This repository was archived by the owner on Jul 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOAuthInfoRetrieveAdapter.kt
More file actions
45 lines (41 loc) · 1.87 KB
/
OAuthInfoRetrieveAdapter.kt
File metadata and controls
45 lines (41 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.asap.client.oauth
import com.asap.application.user.exception.UserException
import com.asap.application.user.port.out.AuthInfoRetrievePort
import com.asap.application.user.vo.AuthInfo
import com.asap.client.oauth.exception.OAuthException
import com.asap.domain.user.enums.SocialLoginProvider
import org.springframework.stereotype.Component
@Component
class OAuthInfoRetrieveAdapter(
private val oAuthRetrieveHandlers: Map<SocialLoginProvider, OAuthRetrieveHandler>,
) : AuthInfoRetrievePort {
override fun getAuthInfo(
provider: SocialLoginProvider,
accessToken: String,
): AuthInfo {
try {
val oAuthResponse =
oAuthRetrieveHandlers[provider]?.getOAuthInfo(OAuthRetrieveHandler.OAuthRequest(accessToken))
?: throw OAuthException.OAuthRetrieveFailedException("OAuth 정보를 가져오는 핸들러가 존재하지 않습니다.")
return AuthInfo(
socialLoginProvider = provider,
socialId = oAuthResponse.socialId,
username = oAuthResponse.username,
profileImage = oAuthResponse.profileImage,
email = oAuthResponse.email,
)
} catch (e: OAuthException) {
throw UserException.UserAuthNotFoundException("OAuth 정보를 가져오는데 실패했습니다. 에러 메시지: ${e.message}")
}
}
override fun getAccessToken(
provider: SocialLoginProvider,
code: String,
state: String,
): String {
val accessTokenResponse =
oAuthRetrieveHandlers[provider]?.getAccessToken(OAuthRetrieveHandler.OAuthGetAccessTokenRequest(code, state))
?: throw OAuthException.OAuthRetrieveFailedException("OAuth Access Token을 가져오는 핸들러가 존재하지 않습니다.")
return accessTokenResponse.accessToken
}
}