Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

425 refactor/auth #444

Merged
merged 4 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ dependencies {
implementation(Dependencies.GOOGLE_OAUTH_CLIENT)
implementation(Dependencies.YOUTUBE_ANALYTICS)
implementation(Dependencies.GOOGLE_API_SERVICE)
implementation(Dependencies.GAUTH)

// monitoring
implementation(Dependencies.ACTUATOR)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.dotori.v2.domain.auth.presentation

import com.dotori.v2.domain.auth.util.AuthConverter
import com.dotori.v2.domain.auth.presentation.data.req.SignInGAuthReqDto
import com.dotori.v2.domain.auth.presentation.data.req.SignInEmailAndPasswordReqDto
import com.dotori.v2.domain.auth.presentation.data.req.SignUpReqDto
import com.dotori.v2.domain.auth.presentation.data.res.RefreshResDto
Expand All @@ -17,23 +16,16 @@ import javax.validation.Valid
@RequestMapping("/v2/auth")
class AuthController (
private val signUpService: SignUpService,
private val signInGAuthService: SignInGAuthService,
private val signInEmailAndPasswordService: SignInEmailAndPasswordService,
private val refreshTokenService: RefreshTokenService,
private val changePasswordService: ChangePasswordService,
private val logoutService: LogoutService,
private val authConverter: AuthConverter,
) {
@PostMapping("/signup")
fun signup(@Valid @RequestBody signupReqDto: SignUpReqDto): ResponseEntity<Void> =
signUpService.execute(signupReqDto)
.run { ResponseEntity.ok().build() }

@PostMapping("/gauth")
fun signInGAuth(@Valid @RequestBody signInGAuthReqDto: SignInGAuthReqDto): ResponseEntity<SignInResDto> =
authConverter.toDto(signInGAuthReqDto)
.let { ResponseEntity.ok(signInGAuthService.execute(it)) }

@PostMapping
fun signInEmailAndPassword(@Valid @RequestBody signInEmailAndPasswordReqDto: SignInEmailAndPasswordReqDto): ResponseEntity<SignInResDto> =
authConverter.toDto(signInEmailAndPasswordReqDto)
Expand All @@ -43,11 +35,6 @@ class AuthController (
fun getNewRefreshToken(@RequestHeader("Refresh-Token") refreshToken: String): ResponseEntity<RefreshResDto> =
ResponseEntity.ok().body(refreshTokenService.execute(refreshToken = refreshToken))

@DeleteMapping("/logout")
fun logout(): ResponseEntity<Void> =
logoutService.execute()
.run { ResponseEntity.ok().build() }

@PatchMapping("/password")
fun changePassword(@Valid @RequestBody newPasswordReqDto: NoAuthNewPasswordReqDto): ResponseEntity<Void> =
changePasswordService.execute(newPasswordReqDto)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import org.springframework.stereotype.Service
import java.time.ZonedDateTime

@Service
@Deprecated("GAuth ๋กœ๊ทธ์ธ์œผ๋กœ ๋ณ€ํ™˜")
class SignInEmailAndPasswordServiceImpl(
private val memberRepository: MemberRepository,
private val tokenProvider: TokenProvider,
Expand All @@ -27,32 +26,32 @@ class SignInEmailAndPasswordServiceImpl(
val member = memberRepository.findByEmail(signInEmailAndPasswordDto.email)
?: throw MemberNotFoundException()

if (passwordEncoder.matches(signInEmailAndPasswordDto.password, member.password)) {
val accessToken =
tokenProvider.generateAccessToken(signInEmailAndPasswordDto.email, role = member.roles.first())
val accessExp = tokenProvider.accessExpiredTime
val expiresAt = tokenProvider.accessExpiredTime
val refreshToken =
tokenProvider.generateRefreshToken(signInEmailAndPasswordDto.email, role = member.roles.first())
val refreshExp = tokenProvider.refreshExpiredTime

refreshTokenRepository.save(
RefreshToken(
memberId = member.id,
token = refreshToken
)
)
return toResponse(
accessToken,
refreshToken,
accessExp,
refreshExp,
member.roles,
expiresAt
)
} else {
if (!passwordEncoder.matches(signInEmailAndPasswordDto.password, member.password)) {
throw PasswordMismatchException()
}

val accessToken =
tokenProvider.generateAccessToken(signInEmailAndPasswordDto.email, role = member.roles.first())
val accessExp = tokenProvider.accessExpiredTime
val expiresAt = tokenProvider.accessExpiredTime
val refreshToken =
tokenProvider.generateRefreshToken(signInEmailAndPasswordDto.email, role = member.roles.first())
val refreshExp = tokenProvider.refreshExpiredTime

refreshTokenRepository.save(
RefreshToken(
memberId = member.id,
token = refreshToken
)
)
return toResponse(
accessToken,
refreshToken,
accessExp,
refreshExp,
member.roles,
expiresAt
)
}

private fun toResponse(
Expand Down

This file was deleted.

14 changes: 0 additions & 14 deletions src/main/kotlin/com/dotori/v2/domain/auth/util/AuthConverter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,12 @@ package com.dotori.v2.domain.auth.util
import com.dotori.v2.domain.auth.domain.entity.RefreshToken
import com.dotori.v2.domain.auth.presentation.data.dto.SignInEmailAndPasswordDto
import com.dotori.v2.domain.member.domain.entity.Member
import com.dotori.v2.domain.auth.presentation.data.dto.SignInGAuthDto
import com.dotori.v2.domain.auth.presentation.data.req.SignInEmailAndPasswordReqDto
import com.dotori.v2.domain.auth.presentation.data.req.SignInGAuthReqDto
import com.dotori.v2.domain.member.enums.Role
import gauth.GAuthUserInfo

interface AuthConverter {

fun toDto(signInGAuthReqDto: SignInGAuthReqDto): SignInGAuthDto

fun toDto(signInEmailAndPasswordReqDto: SignInEmailAndPasswordReqDto): SignInEmailAndPasswordDto

fun toEntity(gAuthUserInfo: GAuthUserInfo, role: Role): Member

fun toAdminEntity(gAuthUserInfo: GAuthUserInfo): Member

fun toCouncillorEntity(gAuthUserInfo: GAuthUserInfo): Member

fun toDeveloperEntity(gAuthUserInfo: GAuthUserInfo): Member

fun toEntity(memberInfo: Member, refreshToken: String): RefreshToken

fun toEntity(memberId: Long?, refreshToken: String): RefreshToken
Expand Down
Loading
Loading