-
Notifications
You must be signed in to change notification settings - Fork 1
Book 469 feature/#141 #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1fff654
ae6b5ca
bed59ba
7aa722b
008fa55
71400d5
fc06490
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,32 @@ | ||||||
| package org.yapp.apis.auth.strategy.withdraw | ||||||
|
|
||||||
| import mu.KotlinLogging | ||||||
| import org.springframework.stereotype.Component | ||||||
| import org.yapp.apis.auth.dto.request.WithdrawStrategyRequest | ||||||
| import org.yapp.apis.auth.exception.AuthErrorCode | ||||||
| import org.yapp.apis.auth.exception.AuthException | ||||||
| import org.yapp.apis.auth.manager.GoogleApiManager | ||||||
| import org.yapp.domain.user.ProviderType | ||||||
|
|
||||||
| @Component | ||||||
| class GoogleWithdrawStrategy( | ||||||
| private val googleApiManager: GoogleApiManager | ||||||
| ) : WithdrawStrategy { | ||||||
|
|
||||||
| private val log = KotlinLogging.logger {} | ||||||
|
|
||||||
| override fun getProviderType(): ProviderType = ProviderType.GOOGLE | ||||||
|
|
||||||
| override fun withdraw(request: WithdrawStrategyRequest) { | ||||||
| val googleRefreshToken = request.googleRefreshToken | ||||||
| ?: throw AuthException(AuthErrorCode.GOOGLE_REFRESH_TOKEN_NOT_FOUND, "Google Refresh Token์ด ์กด์ฌํ์ง ์์ต๋๋ค.") | ||||||
|
|
||||||
| try { | ||||||
| googleApiManager.revokeToken(googleRefreshToken as String) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐งน Nitpick | ๐ต Trivial ๋ถํ์ํ ํ์
์บ์คํธ ( Line 21-22์์ โป๏ธ ์ ์- googleApiManager.revokeToken(googleRefreshToken as String)
+ googleApiManager.revokeToken(googleRefreshToken)๐ Committable suggestion
Suggested change
๐ค Prompt for AI Agents |
||||||
| log.info { "Google refresh token revoked successfully for user ${request.userId}" } | ||||||
| } catch (e: Exception) { | ||||||
| log.error("Failed to revoke Google token for user ${request.userId}", e) | ||||||
| throw AuthException(AuthErrorCode.FAILED_TO_REVOKE_TOKEN, e.message) | ||||||
| } | ||||||
|
Comment on lines
+27
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐งฉ Analysis chain๐ Script executed: #!/bin/bash
# Find AuthException class definition
find . -type f -name "*.kt" | xargs grep -l "class AuthException" | head -5Repository: YAPP-Github/Reed-Server Length of output: 135 ๐ Script executed: #!/bin/bash
# Get the AuthException class definition with details
rg "class AuthException" -A 20 --type=ktRepository: YAPP-Github/Reed-Server Length of output: 93 ๐ Script executed: #!/bin/bash
# Look at the GoogleWithdrawStrategy file to understand the context
find . -type f -name "GoogleWithdrawStrategy.kt" -exec cat -n {} \;Repository: YAPP-Github/Reed-Server Length of output: 1536 ๐ Script executed: #!/bin/bash
# Read the AuthException file content
cat -n ./apis/src/main/kotlin/org/yapp/apis/auth/exception/AuthException.ktRepository: YAPP-Github/Reed-Server Length of output: 334 ๐ Script executed: #!/bin/bash
# Find CommonException class
find . -type f -name "*.kt" | xargs grep -l "class CommonException"Repository: YAPP-Github/Reed-Server Length of output: 147 ๐ Script executed: #!/bin/bash
# Read CommonException definition
find . -path "*globalutils/exception/CommonException.kt" -exec cat -n {} \;Repository: YAPP-Github/Reed-Server Length of output: 436 ๐ Script executed: #!/bin/bash
# Find GoogleApiManager
find . -type f -name "*GoogleApiManager*" | head -5Repository: YAPP-Github/Reed-Server Length of output: 136 ๐ Script executed: #!/bin/bash
# Look at GoogleApiManager.revokeToken method
find . -type f -name "*.kt" | xargs grep -l "GoogleApiManager" | head -3Repository: YAPP-Github/Reed-Server Length of output: 222 ๐ Script executed: #!/bin/bash
# Read GoogleApiManager file
cat -n ./apis/src/main/kotlin/org/yapp/apis/auth/manager/GoogleApiManager.ktRepository: YAPP-Github/Reed-Server Length of output: 2074 ๐ Script executed: #!/bin/bash
# Check if ResponseStatusException supports cause parameter
find . -type f -name "*.kt" | xargs grep -l "ResponseStatusException" | head -2Repository: YAPP-Github/Reed-Server Length of output: 147 ๐ Script executed: #!/bin/bash
# Check what GoogleApi.revokeGoogleToken throws
find . -type f -name "GoogleApi.kt" | xargs grep -A 10 "revokeGoogleToken"Repository: YAPP-Github/Reed-Server Length of output: 344 ๐ Script executed: #!/bin/bash
# Check ResponseStatusException to understand what parameters it accepts
# Look for how exceptions are constructed in similar patterns
find . -type f -name "*.kt" | xargs grep -B2 -A2 "throw AuthException" | head -30Repository: YAPP-Github/Reed-Server Length of output: 3445 ๐ Script executed: #!/bin/bash
# Check if there are other exception handling patterns in the codebase with cause
find . -type f -name "*.kt" | xargs grep "Throwable\|cause" | grep -i "exception\|error" | head -10Repository: YAPP-Github/Reed-Server Length of output: 49 ๐ Script executed: #!/bin/bash
# Check Spring ResponseStatusException constructor to understand cause support
python3 << 'EOF'
# ResponseStatusException is from Spring framework
# Let's check how it's typically used in Kotlin/Spring context
# and what the standard exception constructor signature looks like
print("Spring's ResponseStatusException class signature:")
print("public ResponseStatusException(HttpStatus status, `@Nullable` String reason, `@Nullable` Throwable cause)")
print("\nHowever, the current CommonException implementation doesn't pass cause to parent.")
EOFRepository: YAPP-Github/Reed-Server Length of output: 301 ๐ Script executed: #!/bin/bash
# Check if there are any other places catching RestClientException or similar
find . -type f -name "*.kt" | xargs grep -l "RestClientException\|HttpClientErrorException" | head -5Repository: YAPP-Github/Reed-Server Length of output: 205 ๐ Script executed: #!/bin/bash
# Check KakaoApiManager to see similar exception handling patterns
cat -n ./apis/src/main/kotlin/org/yapp/apis/auth/manager/KakaoApiManager.kt | head -60Repository: YAPP-Github/Reed-Server Length of output: 3012 ๊ตฌ์ฒด์ ์ธ ์์ธ ํ์ ์ฒ๋ฆฌ๊ฐ ํ์ํฉ๋๋ค. ํ์ฌ ์ฝ๋์ ๋ ๊ฐ์ง ๋ฌธ์ ๊ฐ ํ์ธ๋์์ต๋๋ค:
๐ ๊ตฌ์ฒด์ ์์ธ ํ์ ์ฒ๋ฆฌ ์ ์- } catch (e: Exception) {
+ } catch (e: org.springframework.web.client.RestClientException) {
log.error("Failed to revoke Google token for user ${request.userId}", e)
throw AuthException(AuthErrorCode.FAILED_TO_REVOKE_TOKEN, e.message)
}๐งฐ Tools๐ช detekt (1.23.8)[warning] 27-27: The caught exception is too generic. Prefer catching specific exceptions to the case that is currently handled. (detekt.exceptions.TooGenericExceptionCaught) [warning] 27-27: The caught exception is swallowed. The original exception could be lost. (detekt.exceptions.SwallowedException) ๐ค Prompt for AI Agents |
||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,22 +1,36 @@ | ||||||
| package org.yapp.infra.external.oauth.google | ||||||
|
|
||||||
| import org.springframework.stereotype.Component | ||||||
| import org.yapp.infra.external.oauth.google.response.GoogleUserInfo | ||||||
| import org.springframework.util.LinkedMultiValueMap | ||||||
| import org.yapp.infra.external.oauth.google.response.GoogleUserInfo // Changed to GoogleUserInfo | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐งน Nitpick | ๐ต Trivial ๋ฆฌํฉํ ๋ง ์์ฌ ์ฃผ์ ์ ๊ฑฐ ํ์.
โป๏ธ ์ ์-import org.yapp.infra.external.oauth.google.response.GoogleUserInfo // Changed to GoogleUserInfo
+import org.yapp.infra.external.oauth.google.response.GoogleUserInfoLine 19๋ ๋์ผํ๊ฒ ์ ์ฉ: - ): Result<GoogleUserInfo> { // Changed to GoogleUserInfo
+ ): Result<GoogleUserInfo> {๐ Committable suggestion
Suggested change
๐ค Prompt for AI Agents |
||||||
|
|
||||||
| @Component | ||||||
| class GoogleApi( | ||||||
| private val googleRestClient: GoogleRestClient | ||||||
| ) { | ||||||
| companion object { | ||||||
| private const val BEARER_PREFIX = "Bearer " | ||||||
| private const val TOKEN = "token" | ||||||
| } | ||||||
|
|
||||||
| fun fetchUserInfo( | ||||||
| accessToken: String, | ||||||
| userInfoUrl: String, | ||||||
| ): Result<GoogleUserInfo> { | ||||||
| ): Result<GoogleUserInfo> { // Changed to GoogleUserInfo | ||||||
| return runCatching { | ||||||
| googleRestClient.getUserInfo(BEARER_PREFIX + accessToken, userInfoUrl) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| fun revokeGoogleToken( | ||||||
| token: String | ||||||
| ): Result<Unit> { | ||||||
| val requestBody = LinkedMultiValueMap<String, String>().apply { | ||||||
| add(TOKEN, token) | ||||||
| } | ||||||
|
|
||||||
| return runCatching { | ||||||
| googleRestClient.revoke(requestBody) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package org.yapp.infra.external.oauth.google | |
|
|
||
| import org.springframework.stereotype.Component | ||
| import org.springframework.web.client.RestClient | ||
| import org.springframework.util.LinkedMultiValueMap | ||
| import org.yapp.infra.external.oauth.google.response.GoogleUserInfo | ||
|
|
||
| @Component | ||
|
|
@@ -21,4 +22,12 @@ class GoogleRestClient( | |
| .body(GoogleUserInfo::class.java) | ||
| ?: throw IllegalStateException("Google API ์๋ต์ด null ์ ๋๋ค.") | ||
| } | ||
|
|
||
| fun revoke(requestBody: LinkedMultiValueMap<String, String>) { | ||
| client.post() | ||
| .uri("https://oauth2.googleapis.com/revoke") | ||
| .body(requestBody) | ||
| .retrieve() | ||
| .body(Unit::class.java) // Google revoke API typically returns an empty body | ||
| } | ||
|
Comment on lines
+26
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐งฉ Analysis chain๐ Web query:
๐ก Result: In Springโs
What to do for Kotlin
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revokeToken์ ์๋ฌ ํธ๋ค๋ง ๋ฐ ๋ก๊น ์ด ๋๋ฝ๋์์ต๋๋ค.getUserInfo(Lines 19-38)๋ ์ฑ๊ณต/์คํจ ์ ๋ก๊น ๊ณผ ์์ธ๋ฅผAuthException์ผ๋ก ๋ํํ๋ ๊ตฌ์กฐํ๋ ์๋ฌ ํธ๋ค๋ง์ด ์์ง๋ง,revokeToken์getOrThrow()๋ง ํธ์ถํ์ฌ ์์ ์์ธ๊ฐ ๊ทธ๋๋ก ์ ํ๋ฉ๋๋ค. ํ ํฐ revoke ์คํจ ์ ๋๋ฒ๊น ์ด ์ด๋ ต๊ณ ,AuthErrorCode.FAILED_TO_REVOKE_TOKEN์ด ์ ์๋์ด ์์์๋ ์ฌ์ฉ๋์ง ์์ต๋๋ค.โป๏ธ getUserInfo์ ๋์ผํ ํจํด์ ์๋ฌ ํธ๋ค๋ง ์ ์ฉ ์ ์
fun revokeToken(token: String) { googleApi.revokeGoogleToken(token) - .getOrThrow() + .onSuccess { + log.info { "Successfully revoked Google token" } + } + .getOrElse { exception -> + log.error(exception) { "Failed to revoke Google token" } + throw AuthException( + AuthErrorCode.FAILED_TO_REVOKE_TOKEN, + "Failed to revoke Google token.", + ) + } }๐ Committable suggestion
๐ค Prompt for AI Agents