Skip to content

Commit

Permalink
fix: #106 oauthUseCase에서 forbiddenTokenService 직접 종속성 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
psychology50 committed Feb 11, 2024
1 parent 95decbc commit 1136f2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public boolean isTokenExpired(String token, JwtType type) {
return jwtProviderMap.get(type).isTokenExpired(token);
}

/**
* 토큰을 블랙 리스트에 등록하는 메서드
* @param token : 블랙 리스트에 등록할 토큰
* @param type : 토큰의 타입
*/
public void ban(String token, JwtType type) {
AccessToken forbiddenToken = AccessToken.of(token, getSubInfoFromToken(token, type).id(), getExpiryDate(token, type));
forbiddenTokenService.register(forbiddenToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,11 @@ public class OauthUseCase {
private final OauthClientMapper oauthClientMapper;

private final JwtMapper jwtMapper;

private final ForbiddenTokenService forbiddenTokenService;
private final SmsRedisMapper smsRedisMapper;

private final OIDCTokenService oidcTokenService;
private final SmsProvider smsProvider;

private final SmsRedisMapper smsRedisMapper;

@Transactional
public Optional<Pair<Long, Jwt>> signInByOIDC(String id, String idToken, ProviderType provider, String nonce) {
OIDCDecodePayload payload = getPayload(provider, idToken, nonce);
Expand Down Expand Up @@ -102,10 +99,7 @@ public Pair<Long, Jwt> signUpByOIDC(String id, ProviderType provider, String req
oauthAccount.updateMember(member);
oidcTokenService.deleteOIDCToken(req.idToken());

forbiddenTokenService.register(
AccessToken.of(smsOauthToken, subs.id(), jwtMapper.getExpiryDate(smsOauthToken, JwtType.SMS_OAUTH_TOKEN))
);

jwtMapper.ban(smsOauthToken, JwtType.SMS_OAUTH_TOKEN);
log.info("success oauth signup member id : {} - oauth id : {} [provider: {}]",
member.getId(), oauthAccount.getOauthId(), oauthAccount.getProvider());
return Pair.of(member.getId(), jwtMapper.login(JwtUserInfo.from(member)));
Expand All @@ -117,8 +111,8 @@ public SmsRes sendCode(OauthSmsReq dto, ProviderType provider) {
String key = makeTopic(dto.to(), provider);


smsRedisHelper.saveSmsAuthToken(key, smsInfo.code(), SmsPrefix.OAUTH);
LocalDateTime expireTime = smsRedisHelper.getExpiredTime(key, SmsPrefix.OAUTH);
smsRedisMapper.saveSmsAuthToken(key, smsInfo.code(), SmsPrefix.OAUTH);
LocalDateTime expireTime = smsRedisMapper.getExpiredTime(key, SmsPrefix.OAUTH);
log.info("인증번호 만료 시간: {}", expireTime);
return SmsRes.of(dto.to(), smsInfo.requestTime(), expireTime);
}
Expand All @@ -127,11 +121,11 @@ public SmsRes sendCode(OauthSmsReq dto, ProviderType provider) {
public Pair<Long, Jwt> checkCertificationNumber(OauthSmsReq req, String id, String code, ProviderType provider) {
String key = makeTopic(req.to(), provider);
log.info("key: {}", key);
if (!smsRedisHelper.isCorrectCode(key, code, SmsPrefix.OAUTH)) {
if (!smsRedisMapper.isCorrectCode(key, code, SmsPrefix.OAUTH)) {
log.warn("인증번호 불일치 -> 사용자 입력 인증 번호 : {}", code);
throw new GlobalErrorException(SmsErrorCode.INVALID_AUTH_CODE);
}
smsRedisHelper.removeCode(key, SmsPrefix.OAUTH);
smsRedisMapper.removeCode(key, SmsPrefix.OAUTH);

if (memberSearchService.isExistByPhone(req.to())) {
Member member = memberSearchService.findByPhone(req.to());
Expand Down Expand Up @@ -174,7 +168,7 @@ private String makeTopic(String phoneNumber, ProviderType provider) {
}

private void validateToken(String accessToken, String value, ProviderType provider) {
if (forbiddenTokenService.isForbidden(accessToken))
if (jwtMapper.isForbidden(accessToken))
throw new AuthErrorException(AuthErrorCode.FORBIDDEN_ACCESS_TOKEN, "forbidden access token");

ProviderType tokenProvider = getProviderByTopic(value);
Expand Down

0 comments on commit 1136f2a

Please sign in to comment.