-
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
Showing
90 changed files
with
1,985 additions
and
206 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
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 |
---|---|---|
|
@@ -39,4 +39,9 @@ out/ | |
### Kotlin ### | ||
.kotlin | ||
|
||
mysqldata/ | ||
mysqldata/ | ||
|
||
.env | ||
.env.dev | ||
|
||
docker-compose.prod.yml |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
-- scheme | ||
CREATE DATABASE balancemania CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; | ||
CREATE | ||
DATABASE balancemania CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; | ||
|
||
-- 유저 정보 | ||
CREATE TABLE `user` | ||
( | ||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT 'user id', | ||
`name` varchar(256) NOT NULL COMMENT 'user 이름', | ||
`created_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '생성일', | ||
`modified_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '수정일', | ||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT 'user id', | ||
`oauth_provider` int NOT NULL COMMENT 'oauth 제공자, KAKAO: 0', | ||
`oauth_id` varchar(256) NOT NULL COMMENT 'oauth id', | ||
`name` varchar(256) NOT NULL COMMENT 'user 이름', | ||
`gender` int DEFAULT NULL COMMENT 'user 성별, 남성: 0, 여성: 1', | ||
`birth` date DEFAULT NULL COMMENT 'user 출생년도', | ||
`status_type` int NOT NULL COMMENT '상태 정보 타입 정보 / 활동 : 1, 탈퇴 : 2, 일시 정지 7일 : 3, 영구 정지 : 4', | ||
`created_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '생성일', | ||
`modified_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '수정일', | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB AUTO_INCREMENT=200000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='유저 정보'; |
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
92 changes: 92 additions & 0 deletions
92
src/main/kotlin/com/balancemania/api/auth/application/AuthFacade.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,92 @@ | ||
package com.balancemania.api.auth.application | ||
|
||
import arrow.fx.coroutines.parZip | ||
import com.balancemania.api.auth.application.domain.RefreshToken | ||
import com.balancemania.api.auth.model.AuthUser | ||
import com.balancemania.api.auth.model.AuthUserImpl | ||
import com.balancemania.api.auth.model.AuthUserToken | ||
import com.balancemania.api.auth.model.TokenDto | ||
import com.balancemania.api.auth.model.response.TokenRefreshRequest | ||
import com.balancemania.api.config.database.TransactionTemplates | ||
import com.balancemania.api.exception.ErrorCode | ||
import com.balancemania.api.exception.InvalidTokenException | ||
import com.balancemania.api.exception.NoAuthorityException | ||
import com.balancemania.api.extension.coExecuteOrNull | ||
import com.balancemania.api.user.application.UserService | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.awaitAll | ||
import kotlinx.coroutines.coroutineScope | ||
import org.springframework.context.ApplicationEventPublisher | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
class AuthFacade( | ||
private val userService: UserService, | ||
private val jwtTokenService: JwtTokenService, | ||
private val refreshTokenService: RefreshTokenService, | ||
private val oAuthService: OAuthService, | ||
private val eventPublisher: ApplicationEventPublisher, | ||
private val txTemplates: TransactionTemplates, | ||
) { | ||
fun resolveAuthUser(token: AuthUserToken): Any { | ||
return jwtTokenService.verifyToken(token) | ||
.let { payload -> | ||
if (payload.type != "accessToken") { | ||
throw InvalidTokenException(ErrorCode.INVALID_ACCESS_TOKEN) | ||
} | ||
|
||
val user = userService.findByIdOrThrowSync(payload.id) | ||
|
||
AuthUserImpl(uid = user.id) | ||
} | ||
} | ||
|
||
@Transactional | ||
suspend fun logout(user: AuthUser) { | ||
refreshTokenService.deleteByKey(user.uid.toString()) | ||
} | ||
|
||
@Transactional | ||
suspend fun refreshToken(request: TokenRefreshRequest): TokenDto { | ||
val accessPayload = jwtTokenService.verifyTokenWithExtendedExpiredAt(request.accessToken) | ||
val refreshPayload = jwtTokenService.verifyRefreshToken(request.refreshToken) | ||
|
||
if (accessPayload.id != refreshPayload.id) { | ||
throw NoAuthorityException(ErrorCode.INVALID_TOKEN) | ||
} | ||
|
||
return parZip( | ||
{ refreshTokenService.deleteByKey(refreshPayload.id.toString()) }, | ||
{ jwtTokenService.generateAccessAndRefreshToken(refreshPayload.id) } | ||
) { _, tokenDto -> | ||
RefreshToken( | ||
uid = refreshPayload.id, | ||
refreshToken = tokenDto.refreshToken | ||
).run { refreshTokenService.save(this) } | ||
|
||
tokenDto | ||
} | ||
} | ||
|
||
@Transactional | ||
suspend fun withdraw(authUser: AuthUser) { | ||
val user = userService.findByIdOrThrow(authUser.uid) | ||
|
||
coroutineScope { | ||
val txDeferred = async { | ||
txTemplates.writer.coExecuteOrNull { | ||
user.apply { | ||
this.oauthInfo = oauthInfo.withdrawOAuthInfo() | ||
}.run { userService.saveSync(this) } | ||
} | ||
} | ||
|
||
val oAuthDeferred = async { | ||
oAuthService.withdraw(user.oauthInfo) | ||
} | ||
|
||
awaitAll(txDeferred, oAuthDeferred) | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/com/balancemania/api/auth/application/DevOAuthService.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,29 @@ | ||
package com.balancemania.api.auth.application | ||
|
||
import com.balancemania.api.auth.application.oauth.KakaoOAuthService | ||
import com.balancemania.api.auth.model.response.OAuthLoginLinkResponse | ||
import com.balancemania.api.auth.model.response.OAuthTokenResponse | ||
import com.balancemania.api.user.domain.vo.OAuthProvider | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class DevOAuthService( | ||
private val kakaoOAuthService: KakaoOAuthService, | ||
) { | ||
private val logger = KotlinLogging.logger { } | ||
|
||
/** oauth login link 가져오기 */ | ||
suspend fun getOAuthLoginLinkDev(provider: OAuthProvider): OAuthLoginLinkResponse { | ||
return when (provider) { | ||
OAuthProvider.KAKAO -> kakaoOAuthService.getOAuthLoginLinkDev() | ||
} | ||
} | ||
|
||
/** oauth token 가져오기 */ | ||
suspend fun getOAuthTokenDev(provider: OAuthProvider, code: String): OAuthTokenResponse { | ||
return when (provider) { | ||
OAuthProvider.KAKAO -> kakaoOAuthService.getOAuthTokenDev(code) | ||
} | ||
} | ||
} |
Oops, something went wrong.