-
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
bdf7029
commit bd4f514
Showing
24 changed files
with
238 additions
and
42 deletions.
There are no files selected for viewing
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
23 changes: 20 additions & 3 deletions
23
src/main/kotlin/com/hero/alignlab/client/kakao/KakaoInfoService.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
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
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
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
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
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
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
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
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
45 changes: 30 additions & 15 deletions
45
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,32 +1,47 @@ | ||
package com.hero.alignlab.domain.auth.application | ||
|
||
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 com.hero.alignlab.domain.auth.model.request.OAuthLoginRequest | ||
import com.hero.alignlab.domain.auth.model.response.OAuthCheckSignUpResponse | ||
import com.hero.alignlab.domain.auth.model.response.OAuthLoginResponse | ||
import com.hero.alignlab.domain.user.application.OAuthUserInfoService | ||
import com.hero.alignlab.domain.user.application.UserInfoService | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.springframework.stereotype.Service | ||
import java.time.LocalDateTime | ||
|
||
@Service | ||
class OAuthFacade( | ||
private val kakaoOAuthService: KakaoOAuthService, | ||
private val oAuthService: OAuthService, | ||
private val oAuthUserInfoService: OAuthUserInfoService, | ||
private val userInfoService: UserInfoService, | ||
private val jwtTokenService: JwtTokenService, | ||
) { | ||
companion object { | ||
private val TOKEN_EXPIRED_DATE = LocalDateTime.of(2024, 12, 29, 0, 0, 0) | ||
} | ||
|
||
private val logger = KotlinLogging.logger { } | ||
|
||
suspend fun getOAuthAuthorizeCode(provider: OAuthProvider): OAuthAuthorizeCodeResponse { | ||
when (provider) { | ||
OAuthProvider.kakao -> kakaoOAuthService.getOAuthAuthorizeCode() | ||
} | ||
suspend fun checkSignUp(provider: OAuthProvider, accessToken: String): OAuthCheckSignUpResponse { | ||
val oauthInfo = oAuthService.getOAuthInfo(provider, accessToken) | ||
|
||
val isExists = oAuthUserInfoService.existsByOauthIdAndProvider(oauthInfo.oauthId, provider.toProvider()) | ||
|
||
return OAuthAuthorizeCodeResponse(provider) | ||
return OAuthCheckSignUpResponse(isExists) | ||
} | ||
|
||
suspend fun resolveOAuth(provider: OAuthProvider, request: OAuthAuthorizedRequest) { | ||
val response = when (provider) { | ||
OAuthProvider.kakao -> kakaoOAuthService.generateOAuthToken(request.code) | ||
} | ||
suspend fun signIn(provider: OAuthProvider, request: OAuthLoginRequest): OAuthLoginResponse? { | ||
val oauthInfo = oAuthService.getOAuthInfo(provider, request.accessToken) | ||
|
||
val userInfo = userInfoService.findByOAuthOrThrow(provider.toProvider(), oauthInfo.oauthId) | ||
|
||
val token = jwtTokenService.createToken(userInfo.id, TOKEN_EXPIRED_DATE) | ||
|
||
println("response > " + response.toJson()) | ||
return OAuthLoginResponse( | ||
uid = userInfo.id, | ||
nickname = userInfo.nickname, | ||
accessToken = token | ||
) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/com/hero/alignlab/domain/auth/application/OAuthService.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,17 @@ | ||
package com.hero.alignlab.domain.auth.application | ||
|
||
import com.hero.alignlab.client.kakao.KakaoInfoService | ||
import com.hero.alignlab.domain.auth.model.OAuthProvider | ||
import com.hero.alignlab.domain.auth.model.OAuthUserInfoModel | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class OAuthService( | ||
private val kakaoInfoService: KakaoInfoService, | ||
) { | ||
suspend fun getOAuthInfo(provider: OAuthProvider, accessToken: String): OAuthUserInfoModel { | ||
return when (provider) { | ||
OAuthProvider.kakao -> kakaoInfoService.getOAuthInfo(accessToken) | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/hero/alignlab/domain/auth/model/OAuthProvider.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,6 +1,14 @@ | ||
package com.hero.alignlab.domain.auth.model | ||
|
||
import com.hero.alignlab.domain.user.domain.OAuthProvider | ||
|
||
enum class OAuthProvider { | ||
kakao, | ||
; | ||
|
||
fun toProvider(): OAuthProvider { | ||
return when (this) { | ||
kakao -> OAuthProvider.KAKAO | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/hero/alignlab/domain/auth/model/OAuthUserInfoModel.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,8 @@ | ||
package com.hero.alignlab.domain.auth.model | ||
|
||
data class OAuthUserInfoModel( | ||
val provider: OAuthProvider, | ||
val oauthId: String, | ||
val nickname: String, | ||
val profileImageUrl: String? | ||
) |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/com/hero/alignlab/domain/auth/model/request/OAuthLoginRequest.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 OAuthLoginRequest( | ||
val accessToken: String | ||
) |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/com/hero/alignlab/domain/auth/model/response/OAuthCheckSignUpResponse.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.response | ||
|
||
data class OAuthCheckSignUpResponse( | ||
val isExistsUser: Boolean, | ||
) |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/hero/alignlab/domain/auth/model/response/OAuthLoginResponse.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,8 @@ | ||
package com.hero.alignlab.domain.auth.model.response | ||
|
||
data class OAuthLoginResponse( | ||
val uid: Long, | ||
val nickname: String, | ||
/** hero access token */ | ||
val accessToken: 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
Oops, something went wrong.