-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3aeac01
commit 135447b
Showing
10 changed files
with
140 additions
and
18 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/kotlin/com/hero/alignlab/client/kakao/KakaoOAuthService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.hero.alignlab.client.kakao | ||
|
||
import com.hero.alignlab.client.kakao.client.KaKaoOAuthClient | ||
import com.hero.alignlab.client.kakao.config.KakaoOAuthClientConfig | ||
import com.hero.alignlab.client.kakao.model.request.GenerateKakaoOAuthTokenRequest | ||
import com.hero.alignlab.client.kakao.model.response.GenerateKakaoOAuthTokenResponse | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class KakaoOAuthService( | ||
private val kaKaoOAuthClient: KaKaoOAuthClient, | ||
private val config: KakaoOAuthClientConfig.Config | ||
) { | ||
suspend fun getOAuthAuthorizeCode(redirectUrl: String? = null) { | ||
withContext(Dispatchers.IO) { | ||
kaKaoOAuthClient.getOAuthAuthorizeCode() | ||
} | ||
} | ||
|
||
suspend fun generateOAuthToken(code: String, redirectUri: String? = null): GenerateKakaoOAuthTokenResponse { | ||
val request = GenerateKakaoOAuthTokenRequest( | ||
clientId = config.clientSecretCode, | ||
redirectUri = redirectUri ?: config.redirectUrl, | ||
code = code, | ||
) | ||
|
||
return generateOAuthToken(request) | ||
} | ||
|
||
suspend fun generateOAuthToken(request: GenerateKakaoOAuthTokenRequest): GenerateKakaoOAuthTokenResponse { | ||
return withContext(Dispatchers.IO) { | ||
kaKaoOAuthClient.generateOAuthToken(request) | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/com/hero/alignlab/client/kakao/client/KaKaoOAuthClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
package com.hero.alignlab.client.kakao.client | ||
|
||
import com.hero.alignlab.client.kakao.model.request.GenerateKakaoOAuthTokenRequest | ||
import com.hero.alignlab.client.kakao.model.response.GenerateKakaoOAuthTokenResponse | ||
|
||
interface KaKaoOAuthClient { | ||
suspend fun getOAuthAuthorizeCode(redirectUrl: String? = null) | ||
|
||
suspend fun generateOAuthToken(request: GenerateKakaoOAuthTokenRequest): GenerateKakaoOAuthTokenResponse | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...ain/kotlin/com/hero/alignlab/client/kakao/model/request/GenerateKakaoOAuthTokenRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.hero.alignlab.client.kakao.model.request | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming | ||
|
||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy::class) | ||
data class GenerateKakaoOAuthTokenRequest( | ||
val grantType: String = "authorization_code", | ||
val clientId: String, | ||
val redirectUri: String, | ||
val code: String, | ||
val clientSecret: String? = null | ||
) |
15 changes: 15 additions & 0 deletions
15
...n/kotlin/com/hero/alignlab/client/kakao/model/response/GenerateKakaoOAuthTokenResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.hero.alignlab.client.kakao.model.response | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming | ||
|
||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy::class) | ||
data class GenerateKakaoOAuthTokenResponse( | ||
val tokenType: String, | ||
val accessToken: String, | ||
val idToken: String?, | ||
val expiresIn: Int, | ||
val refreshToken: String, | ||
val refreshTokenExpiresIn: Int, | ||
val scope: String? | ||
) |
16 changes: 13 additions & 3 deletions
16
src/main/kotlin/com/hero/alignlab/domain/auth/application/OAuthFacade.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,32 @@ | ||
package com.hero.alignlab.domain.auth.application | ||
|
||
import com.hero.alignlab.client.kakao.client.KaKaoOAuthClient | ||
import com.hero.alignlab.client.kakao.KakaoOAuthService | ||
import com.hero.alignlab.common.extension.toJson | ||
import com.hero.alignlab.domain.auth.model.OAuthProvider | ||
import com.hero.alignlab.domain.auth.model.request.OAuthAuthorizedRequest | ||
import com.hero.alignlab.domain.auth.model.response.OAuthAuthorizeCodeResponse | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class OAuthFacade( | ||
private val kaKaoOAuthClient: KaKaoOAuthClient, | ||
private val kakaoOAuthService: KakaoOAuthService, | ||
) { | ||
private val logger = KotlinLogging.logger { } | ||
|
||
suspend fun getOAuthAuthorizeCode(provider: OAuthProvider): OAuthAuthorizeCodeResponse { | ||
when (provider) { | ||
OAuthProvider.kakao -> kaKaoOAuthClient.getOAuthAuthorizeCode() | ||
OAuthProvider.kakao -> kakaoOAuthService.getOAuthAuthorizeCode() | ||
} | ||
|
||
return OAuthAuthorizeCodeResponse(provider) | ||
} | ||
|
||
suspend fun resolveOAuth(provider: OAuthProvider, request: OAuthAuthorizedRequest) { | ||
val response = when (provider) { | ||
OAuthProvider.kakao -> kakaoOAuthService.generateOAuthToken(request.code) | ||
} | ||
|
||
println("response > " + response.toJson()) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/com/hero/alignlab/domain/auth/model/request/OAuthAuthorizedRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.hero.alignlab.domain.auth.model.request | ||
|
||
data class OAuthAuthorizedRequest( | ||
val code: String, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 15 additions & 2 deletions
17
src/main/kotlin/com/hero/alignlab/domain/dev/application/DevOAuthService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,37 @@ | ||
package com.hero.alignlab.domain.dev.application | ||
|
||
import com.hero.alignlab.client.kakao.KakaoOAuthService | ||
import com.hero.alignlab.client.kakao.client.KaKaoOAuthClient | ||
import com.hero.alignlab.client.kakao.config.KakaoOAuthClientConfig | ||
import com.hero.alignlab.client.kakao.model.response.GenerateKakaoOAuthTokenResponse | ||
import com.hero.alignlab.common.extension.toJson | ||
import com.hero.alignlab.domain.auth.model.OAuthProvider | ||
import com.hero.alignlab.domain.auth.model.request.OAuthAuthorizedRequest | ||
import com.hero.alignlab.domain.dev.model.response.DevOAuthCodeResponse | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class DevOAuthService( | ||
private val kaKaoOAuthClient: KaKaoOAuthClient, | ||
private val kakaoOAuthService: KakaoOAuthService, | ||
private val config: KakaoOAuthClientConfig.Config, | ||
) { | ||
private val logger = KotlinLogging.logger { } | ||
|
||
suspend fun getOAuthAuthorizeCode(provider: OAuthProvider): DevOAuthCodeResponse { | ||
when (provider) { | ||
OAuthProvider.kakao -> kaKaoOAuthClient.getOAuthAuthorizeCode(config.devRedirectUrl) | ||
OAuthProvider.kakao -> kakaoOAuthService.getOAuthAuthorizeCode(config.devRedirectUrl) | ||
} | ||
|
||
return DevOAuthCodeResponse(provider) | ||
} | ||
|
||
suspend fun resolveOAuth( | ||
provider: OAuthProvider, | ||
request: OAuthAuthorizedRequest | ||
): GenerateKakaoOAuthTokenResponse { | ||
return when (provider) { | ||
OAuthProvider.kakao -> kakaoOAuthService.generateOAuthToken(request.code) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters