-
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.
Merge pull request #133 from grida-diary/main
prod
- Loading branch information
Showing
13 changed files
with
156 additions
and
30 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
grida-core/core-api/src/main/kotlin/org/grida/auth/AuthProcessor.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 org.grida.auth | ||
|
||
interface AuthProcessor { | ||
fun process(code: String): AuthToken | ||
} |
16 changes: 16 additions & 0 deletions
16
grida-core/core-api/src/main/kotlin/org/grida/auth/AuthProcessorSelector.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,16 @@ | ||
package org.grida.auth | ||
|
||
import org.grida.error.GridaException | ||
import org.grida.error.NotSupportedLoginPlatform | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class AuthProcessorSelector( | ||
private val authProcessors: Map<String, AuthProcessor> | ||
) { | ||
|
||
fun select(platform: String): AuthProcessor { | ||
return authProcessors["${platform}AuthProcessor"] | ||
?: throw GridaException(NotSupportedLoginPlatform) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
grida-core/core-api/src/main/kotlin/org/grida/auth/AuthToken.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,6 @@ | ||
package org.grida.auth | ||
|
||
data class AuthToken( | ||
val accessToken: String, | ||
val refreshToken: String | ||
) |
22 changes: 22 additions & 0 deletions
22
grida-core/core-api/src/main/kotlin/org/grida/auth/AuthTokenProvider.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,22 @@ | ||
package org.grida.auth | ||
|
||
import io.wwan13.wintersecurity.jwt.TokenGenerator | ||
import org.grida.config.TokenPayload | ||
import org.grida.domain.user.User | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class AuthTokenProvider( | ||
private val tokenGenerator: TokenGenerator | ||
) { | ||
|
||
fun provide( | ||
user: User | ||
): AuthToken { | ||
val tokenPayload = TokenPayload(user.id, user.role) | ||
return AuthToken( | ||
accessToken = tokenGenerator.accessToken(tokenPayload), | ||
refreshToken = tokenGenerator.refreshToken(tokenPayload) | ||
) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
grida-core/core-api/src/main/kotlin/org/grida/auth/InternalAuthProcessor.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,36 @@ | ||
package org.grida.auth | ||
|
||
import org.grida.domain.user.LoginOption | ||
import org.grida.domain.user.LoginPlatform | ||
import org.grida.domain.user.UserService | ||
import org.grida.error.GridaException | ||
import org.grida.error.NotSupportedLoginPlatform | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class InternalAuthProcessor( | ||
@Value("\${spring.profiles.active}") | ||
private val activeProfile: String, | ||
private val userService: UserService, | ||
private val authTokenProvider: AuthTokenProvider | ||
) : AuthProcessor { | ||
|
||
override fun process(code: String): AuthToken { | ||
validateActiveProfile() | ||
val loginOption = LoginOption(LoginPlatform.ADMIN, code) | ||
val user = userService.read(loginOption.identifier.toLong()) | ||
|
||
return authTokenProvider.provide(user) | ||
} | ||
|
||
private fun validateActiveProfile() { | ||
if (!enableProfiles.contains(activeProfile)) { | ||
throw throw GridaException(NotSupportedLoginPlatform) | ||
} | ||
} | ||
|
||
companion object { | ||
val enableProfiles = listOf("dev", "stag") | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
grida-core/core-api/src/main/kotlin/org/grida/auth/KakaoAuthProcessor.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,26 @@ | ||
package org.grida.auth | ||
|
||
import org.grida.domain.user.LoginOption | ||
import org.grida.domain.user.LoginPlatform | ||
import org.grida.domain.user.UserService | ||
import org.grida.user.KakaoUserClient | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class KakaoAuthProcessor( | ||
private val kakaoAuthClient: KakaoAuthClient, | ||
private val kakaoUserClient: KakaoUserClient, | ||
private val userService: UserService, | ||
private val authTokenProvider: AuthTokenProvider | ||
) : AuthProcessor { | ||
|
||
override fun process(code: String): AuthToken { | ||
val kakaoToken = kakaoAuthClient.provideAuthToken(code) | ||
val kakaoProfile = kakaoUserClient.readUserProfile(kakaoToken.accessToken) | ||
val loginOption = LoginOption(LoginPlatform.KAKAO, kakaoProfile.id) | ||
|
||
val user = userService.readUserByLoginOption(loginOption) | ||
?: userService.appendAndReturnNormalUser(kakaoProfile.name, loginOption) | ||
return authTokenProvider.provide(user) | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
grida-core/core-api/src/main/kotlin/org/grida/error/CoreApiErrorType.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,12 @@ | ||
package org.grida.error | ||
|
||
import org.grida.http.BAD_REQUEST | ||
|
||
sealed interface CoreApiErrorType : ErrorType | ||
|
||
data object NotSupportedLoginPlatform : CoreApiErrorType { | ||
override val httpStatusCode: Int = BAD_REQUEST | ||
override val errorCode: String = "AUTH_PLATFORM_400_1" | ||
override val message: String = "지원하지 않는 로그인 플랫폼 입니다." | ||
override val logLevel: LogLevel = INFO | ||
} |
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
5 changes: 5 additions & 0 deletions
5
grida-core/core-api/src/main/kotlin/org/grida/presentation/v1/auth/dto/LoginRequest.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 org.grida.presentation.v1.auth.dto | ||
|
||
data class LoginRequest( | ||
val code: String | ||
) |
10 changes: 9 additions & 1 deletion
10
grida-core/core-api/src/main/kotlin/org/grida/presentation/v1/auth/dto/LoginResponse.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 org.grida.presentation.v1.auth.dto | ||
|
||
import org.grida.auth.AuthToken | ||
|
||
data class LoginResponse( | ||
val accessToken: String, | ||
val refreshToken: String, | ||
) | ||
) { | ||
companion object { | ||
fun from(authToken: AuthToken): LoginResponse { | ||
return LoginResponse(authToken.accessToken, authToken.refreshToken) | ||
} | ||
} | ||
} |
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