Skip to content

Commit

Permalink
Merge branch 'feature/DRAW-390' into sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
comforest committed Oct 18, 2024
2 parents 6725de1 + 0bde910 commit 1d6a626
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions adapter/oauth/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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,
)
Original file line number Diff line number Diff line change
@@ -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
}
}
}
2 changes: 2 additions & 0 deletions adapter/oauth/src/main/resources/application-oauth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ oauth:
apple:
iss: https://appleid.apple.com
client-id: ${APPLE_CLIENT_ID}
google:
client-id: ${GOOGLE_CLIENT_ID}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ object Versions {
const val FIREBASE = "9.3.0"
const val KOTEST = "6.0.0.M1"
const val MOCKK = "1.13.12"
const val GOOGLE_API_CLINET = "1.32.1"
const val GOOGLE_API_CLIENT = "1.32.1"
}
2 changes: 2 additions & 0 deletions domain/src/main/kotlin/com/xorker/draw/auth/AuthPlatform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ package com.xorker.draw.auth

enum class AuthPlatform(description: String) {
APPLE("애플"),
GOOGLE("구글"),

;
}
1 change: 1 addition & 0 deletions domain/src/main/kotlin/com/xorker/draw/auth/AuthType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

0 comments on commit 1d6a626

Please sign in to comment.