diff --git a/adapter/oauth/build.gradle.kts b/adapter/oauth/build.gradle.kts index a05988cf..e88db00f 100644 --- a/adapter/oauth/build.gradle.kts +++ b/adapter/oauth/build.gradle.kts @@ -10,6 +10,7 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter:${Versions.SPRING_BOOT}") implementation("org.springframework.cloud:spring-cloud-starter-openfeign:${Versions.OPEN_FEIGN}") + implementation("com.google.api-client:google-api-client:${Versions.GOOGLE_API_CLIENT}") } tasks { diff --git a/adapter/oauth/src/main/kotlin/com/xorker/draw/oauth/OAuthAdapter.kt b/adapter/oauth/src/main/kotlin/com/xorker/draw/oauth/OAuthAdapter.kt index 4cf8ce0b..2453c7e8 100644 --- a/adapter/oauth/src/main/kotlin/com/xorker/draw/oauth/OAuthAdapter.kt +++ b/adapter/oauth/src/main/kotlin/com/xorker/draw/oauth/OAuthAdapter.kt @@ -3,15 +3,18 @@ package com.xorker.draw.oauth import com.xorker.draw.auth.AuthRepository import com.xorker.draw.auth.AuthType import com.xorker.draw.oauth.apple.AppleAuthService +import com.xorker.draw.oauth.google.GoogleAuthService import org.springframework.stereotype.Component @Component internal class OAuthAdapter( private val appleAuthService: AppleAuthService, + private val googleAuthService: GoogleAuthService, ) : AuthRepository { override fun getPlatformUserId(authType: AuthType, token: String): String { return when (authType) { AuthType.APPLE_ID_TOKEN -> appleAuthService.getPlatformUserId(token) + AuthType.GOOGLE_ID_TOKEN -> googleAuthService.getPlatformUserId(token) } } diff --git a/adapter/oauth/src/main/kotlin/com/xorker/draw/oauth/google/GoogleApiConfiguration.kt b/adapter/oauth/src/main/kotlin/com/xorker/draw/oauth/google/GoogleApiConfiguration.kt new file mode 100644 index 00000000..d3acc8eb --- /dev/null +++ b/adapter/oauth/src/main/kotlin/com/xorker/draw/oauth/google/GoogleApiConfiguration.kt @@ -0,0 +1,8 @@ +package com.xorker.draw.oauth.google + +import org.springframework.boot.context.properties.EnableConfigurationProperties +import org.springframework.context.annotation.Configuration + +@Configuration +@EnableConfigurationProperties(GoogleApiProperties::class) +class GoogleApiConfiguration diff --git a/adapter/oauth/src/main/kotlin/com/xorker/draw/oauth/google/GoogleApiProperties.kt b/adapter/oauth/src/main/kotlin/com/xorker/draw/oauth/google/GoogleApiProperties.kt new file mode 100644 index 00000000..dfdb2f73 --- /dev/null +++ b/adapter/oauth/src/main/kotlin/com/xorker/draw/oauth/google/GoogleApiProperties.kt @@ -0,0 +1,8 @@ +package com.xorker.draw.oauth.google + +import org.springframework.boot.context.properties.ConfigurationProperties + +@ConfigurationProperties("social.google") +data class GoogleApiProperties( + val clientId: String, +) diff --git a/adapter/oauth/src/main/kotlin/com/xorker/draw/oauth/google/GoogleAuthService.kt b/adapter/oauth/src/main/kotlin/com/xorker/draw/oauth/google/GoogleAuthService.kt new file mode 100644 index 00000000..e0e20258 --- /dev/null +++ b/adapter/oauth/src/main/kotlin/com/xorker/draw/oauth/google/GoogleAuthService.kt @@ -0,0 +1,27 @@ +package com.xorker.draw.oauth.google + +import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier +import com.google.api.client.http.javanet.NetHttpTransport +import com.google.api.client.json.gson.GsonFactory +import com.xorker.draw.exception.OAuthFailureException +import java.security.GeneralSecurityException +import org.springframework.stereotype.Component + +@Component +internal class GoogleAuthService( + googleApiProperties: GoogleApiProperties, +) { + private val idTokenVerifier = + GoogleIdTokenVerifier.Builder(NetHttpTransport(), GsonFactory.getDefaultInstance()) + .setAudience(listOf(googleApiProperties.clientId)) + .build() + + fun getPlatformUserId(token: String): String { + try { + val idToken = idTokenVerifier.verify(token) + return idToken?.payload?.subject ?: throw OAuthFailureException + } catch (e: GeneralSecurityException) { + throw OAuthFailureException + } + } +} diff --git a/adapter/oauth/src/main/resources/application-oauth.yml b/adapter/oauth/src/main/resources/application-oauth.yml index 67402ac3..f2ff7970 100644 --- a/adapter/oauth/src/main/resources/application-oauth.yml +++ b/adapter/oauth/src/main/resources/application-oauth.yml @@ -2,3 +2,5 @@ oauth: apple: iss: https://appleid.apple.com client-id: ${APPLE_CLIENT_ID} + google: + client-id: ${GOOGLE_CLIENT_ID} diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 9e78cd14..4df65d27 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -15,4 +15,5 @@ object Versions { const val MICROMETER = "1.12.9" const val SENTRY = "7.0.0" const val FIREBASE = "9.3.0" + const val GOOGLE_API_CLIENT = "1.32.1" } diff --git a/domain/src/main/kotlin/com/xorker/draw/auth/AuthPlatform.kt b/domain/src/main/kotlin/com/xorker/draw/auth/AuthPlatform.kt index a773fac1..211515aa 100644 --- a/domain/src/main/kotlin/com/xorker/draw/auth/AuthPlatform.kt +++ b/domain/src/main/kotlin/com/xorker/draw/auth/AuthPlatform.kt @@ -2,5 +2,7 @@ package com.xorker.draw.auth enum class AuthPlatform(description: String) { APPLE("애플"), + GOOGLE("구글"), + ; } diff --git a/domain/src/main/kotlin/com/xorker/draw/auth/AuthType.kt b/domain/src/main/kotlin/com/xorker/draw/auth/AuthType.kt index 838dfa6e..788f71e9 100644 --- a/domain/src/main/kotlin/com/xorker/draw/auth/AuthType.kt +++ b/domain/src/main/kotlin/com/xorker/draw/auth/AuthType.kt @@ -2,4 +2,5 @@ package com.xorker.draw.auth enum class AuthType(val authPlatform: AuthPlatform) { APPLE_ID_TOKEN(AuthPlatform.APPLE), + GOOGLE_ID_TOKEN(AuthPlatform.GOOGLE), }