-
Notifications
You must be signed in to change notification settings - Fork 1
[Refactor] 내부 자동화를 위한 관리자용 로그인 API 추가 (장기 refresh 토큰 기반) #161
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
Changes from 12 commits
33b16b8
879fe81
91c6b73
d6ca881
b719b48
6415657
848cc4c
243f444
cb8d305
dca8923
ca4909e
ecf97e3
274e51a
284159f
51f4224
53d27a8
7f4d66a
a8f2b1c
40de914
3b12825
64b4e4b
c25b0f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package com.kuit.findyou.domain.auth.dto.response; | ||
|
|
||
| public record AdminLoginResponse(String accessToken, String refreshToken) { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.kuit.findyou.domain.auth.service; | ||
|
|
||
| import com.kuit.findyou.domain.auth.dto.response.AdminLoginResponse; | ||
|
|
||
| public interface AdminLoginService { | ||
| AdminLoginResponse adminLogin(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package com.kuit.findyou.domain.auth.service; | ||
|
|
||
| import com.kuit.findyou.domain.auth.dto.response.AdminLoginResponse; | ||
| import com.kuit.findyou.domain.auth.repository.RedisRefreshTokenRepository; | ||
| import com.kuit.findyou.domain.user.model.User; | ||
| import com.kuit.findyou.domain.user.repository.UserRepository; | ||
| import com.kuit.findyou.global.common.exception.CustomException; | ||
| import com.kuit.findyou.global.jwt.util.JwtUtil; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import static com.kuit.findyou.global.common.response.status.BaseExceptionResponseStatus.USER_NOT_FOUND; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Service | ||
| public class AdminLoginServiceImpl implements AdminLoginService{ | ||
| private final JwtUtil jwtUtil; | ||
| private final UserRepository userRepository; | ||
| private final RedisRefreshTokenRepository redisRefreshTokenRepository; | ||
|
|
||
| @Value("${admin.admin-user-id}") | ||
| private Long adminUserId; | ||
|
|
||
| @Value("${admin.refresh-ttl-ms}") | ||
| private Long adminRefreshTtlMs; | ||
|
|
||
| @Override | ||
| public AdminLoginResponse adminLogin() { | ||
| User user = userRepository.findById(adminUserId) | ||
| .orElseThrow(() -> new CustomException(USER_NOT_FOUND)); | ||
|
|
||
| String accessToken = jwtUtil.createAccessJwt(user.getId(), user.getRole()); | ||
|
||
| String refreshToken = jwtUtil.createRefreshJwt(user.getId(), adminRefreshTtlMs); | ||
|
||
|
|
||
| // 관리자 계정만 TTL 1년으로 저장 | ||
| redisRefreshTokenRepository.save(user.getId(), refreshToken, adminRefreshTtlMs); | ||
|
||
|
|
||
| return new AdminLoginResponse(accessToken, refreshToken); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
서버 간에 인증을 위해서 client credentials라는 방법을 사용하기도 하던데 이렇게 구현하신 이유가 있나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
외부 다수 클라이언트가 붙는 구조가 아니라 내부 자동화 주체 1개만 인증하면 되는 요구사항이라, 인증 인프라를 과도하게 키우기보다는 로그인 단계에서만 API Key를 사용하고, 이후에는 짧은 만료의 access token으로 요청을 처리해 보안 수준은 유지하면서 구현과 운영 복잡도를 낮추는 방식이 적절하다고 생각했습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
보안 관점에서는 아쉽지만 그렇게 생각하신다면 알겠습니다