From 90230c4691e59df2c253f3ebc3766c92accd853d Mon Sep 17 00:00:00 2001 From: dalbodeule <11470513+dalbodeule@users.noreply.github.com> Date: Wed, 4 Jun 2025 16:18:02 +0900 Subject: [PATCH] [hotfix] token claim fixed. --- .../mori/chzzk_bot/chatbot/chzzk/ChzzkHandler.kt | 4 ++-- .../chzzk_bot/chatbot/utils/accessTokenRefresh.kt | 11 +++++++---- .../kotlin/space/mori/chzzk_bot/webserver/Main.kt | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/ChzzkHandler.kt b/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/ChzzkHandler.kt index e6962ca..0883a10 100644 --- a/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/ChzzkHandler.kt +++ b/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/ChzzkHandler.kt @@ -223,8 +223,8 @@ class UserHandler( throw RuntimeException("AccessToken or RefreshToken is not valid.") } try { - val tokens = Connector.client.refreshAccessToken(user.refreshToken!!) - client = Connector.getClient(tokens.first, tokens.second) + val tokens = user.refreshToken?.let { token -> Connector.client.refreshAccessToken(token) } + client = Connector.getClient(tokens!!.first, tokens.second) UserService.setRefreshToken(user, tokens.first, tokens.second) chatChannelId = getChzzkChannelId(channel.channelId) diff --git a/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/utils/accessTokenRefresh.kt b/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/utils/accessTokenRefresh.kt index 4355427..c536348 100644 --- a/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/utils/accessTokenRefresh.kt +++ b/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/utils/accessTokenRefresh.kt @@ -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 { - 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 -> diff --git a/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/Main.kt b/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/Main.kt index aea119d..09eb92e 100644 --- a/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/Main.kt +++ b/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/Main.kt @@ -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) }