mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-07 04:41:13 +00:00
Compare commits
11 Commits
8a0a507e5b
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
eccbc94269 | ||
|
77eecaca34 | ||
|
08576cb35a | ||
|
90230c4691 | ||
|
b2f449bf65 | ||
|
5e3a350e15 | ||
|
1c4b818a85 | ||
|
83b5eaf345 | ||
|
a99f3b342a | ||
|
53757476a7 | ||
|
7257100adc |
@@ -223,7 +223,10 @@ class UserHandler(
|
||||
throw RuntimeException("AccessToken or RefreshToken is not valid.")
|
||||
}
|
||||
try {
|
||||
val tokens = Connector.client.refreshAccessToken(user.refreshToken!!)
|
||||
val tokens = user.refreshToken?.let { token -> Connector.client.refreshAccessToken(token) }
|
||||
if(tokens == null) {
|
||||
throw RuntimeException("AccessToken is not valid.")
|
||||
}
|
||||
client = Connector.getClient(tokens.first, tokens.second)
|
||||
UserService.setRefreshToken(user, tokens.first, tokens.second)
|
||||
chatChannelId = getChzzkChannelId(channel.channelId)
|
||||
|
@@ -1,9 +1,12 @@
|
||||
package space.mori.chzzk_bot.chatbot.utils
|
||||
|
||||
import com.google.gson.Gson
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import space.mori.chzzk_bot.chatbot.chzzk.dotenv
|
||||
import space.mori.chzzk_bot.common.utils.client
|
||||
import xyz.r2turntrue.chzzk4j.ChzzkClient
|
||||
import java.io.IOException
|
||||
@@ -29,16 +32,16 @@ data class RefreshTokenResponse(
|
||||
)
|
||||
|
||||
fun ChzzkClient.refreshAccessToken(refreshToken: String): Pair<String, String> {
|
||||
val url = "https://chzzk.naver.com/auth/v1/token"
|
||||
val url = "https://openapi.chzzk.naver.com/auth/v1/token"
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
.header("Content-Type", "application/json")
|
||||
.post(gson.toJson(mapOf(
|
||||
"grantType" to "refresh_token",
|
||||
"refreshToken" to refreshToken,
|
||||
"clientId" to this.apiClientId,
|
||||
"clientSecret" to this.apiSecret
|
||||
)).toRequestBody())
|
||||
"clientId" to dotenv["NAVER_CLIENT_ID"],
|
||||
"clientSecret" to dotenv["NAVER_CLIENT_SECRET"]
|
||||
)).toRequestBody("application/json; charset=utf-8".toMediaType()))
|
||||
.build()
|
||||
|
||||
client.newCall(request).execute().use { response ->
|
||||
|
@@ -181,7 +181,7 @@ val server = embeddedServer(Netty, port = 8080, ) {
|
||||
clientSecret = dotenv["NAVER_CLIENT_SECRET"]
|
||||
)
|
||||
|
||||
val response = applicationHttpClient.post("https://chzzk.naver.com/auth/v1/token") {
|
||||
val response = applicationHttpClient.post("https://openapi.chzzk.naver.com/auth/v1/token") {
|
||||
contentType(ContentType.Application.Json)
|
||||
setBody(tokenRequest)
|
||||
}
|
||||
|
Reference in New Issue
Block a user