Skip to content

Commit

Permalink
feat: add returning user phonenNumber when login try with kakao
Browse files Browse the repository at this point in the history
  • Loading branch information
JIUNG9 committed Dec 6, 2023
1 parent 4a908a4 commit a0ba195
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.bit.lot.flower.auth.common.dto;

import com.bit.lot.flower.auth.common.valueobject.BaseId;
import com.bit.lot.flower.auth.common.valueobject.Role;
import com.bit.lot.flower.auth.social.valueobject.AuthId;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
public class RenewAccessTokenDto<T extends BaseId> {
T authId;
Role role;

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.bit.lot.flower.auth.common.http.interceptor.filter;

import com.bit.lot.flower.auth.common.dto.RenewAccessTokenDto;
import com.bit.lot.flower.auth.common.util.ExtractAuthorizationTokenUtil;
import com.bit.lot.flower.auth.common.util.JwtUtil;
import com.bit.lot.flower.auth.common.util.RedisBlackListTokenUtil;
import com.bit.lot.flower.auth.common.valueobject.JWTAuthenticationShouldNotFilterAntMatcher;
import com.bit.lot.flower.auth.common.valueobject.KakaoOAuthURLAntURI;
import com.bit.lot.flower.auth.common.valueobject.Role;
import com.bit.lot.flower.auth.common.valueobject.SecurityPolicyStaticValue;
import com.bit.lot.flower.auth.common.valueobject.SwaggerRequestURI;
import com.bit.lot.flower.auth.social.valueobject.AuthId;
import com.nimbusds.openid.connect.sdk.AuthenticationRequest;
import io.jsonwebtoken.ExpiredJwtException;
import java.io.IOException;
import javax.security.sasl.AuthenticationException;
Expand Down Expand Up @@ -56,8 +61,29 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
try {
JwtUtil.isTokenValid(token);
} catch (ExpiredJwtException e) {
<<<<<<< Updated upstream
response.setStatus(403);
}
filterChain.doFilter(request, response);
}
=======
setResponseWhenTokenIsExpiredForCheckingRefreshToken(response, e);
throw new ExpiredJwtException(e.getHeader(), e.getClaims(), "만료된 토큰입니다. Refresh토큰을 확인하세요");
}
filterChain.doFilter(request, response);
}

private void setResponseWhenTokenIsExpiredForCheckingRefreshToken(
HttpServletResponse response, ExpiredJwtException e) throws IOException {
JsonBinderUtil.setResponseWithJson(response, 403, createDtoByToken(e));
}


private RenewAccessTokenDto<AuthId> createDtoByToken(ExpiredJwtException e) {
return RenewAccessTokenDto.<AuthId>builder()
.authId(new AuthId(Long.valueOf(e.getClaims().getSubject())))
.role(Role.valueOf(e.getClaims().get(
SecurityPolicyStaticValue.CLAIMS_ROLE_KEY_NAME, String.class))).build();
}
>>>>>>> Stashed changes
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.bit.lot.flower.auth.common.util;

public class OauthInfoConvertor {

public static String convertInternationalPhoneNumberToDomestic(String phoneNumber) {
String numericPhone = phoneNumber.replaceAll("[^0-9]", "");
numericPhone = "0"+ numericPhone.substring(2) ;
return numericPhone;
}

}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bit.lot.flower.auth.social.security;

import com.bit.lot.flower.auth.common.util.OauthInfoConvertor;
import com.bit.lot.flower.auth.social.dto.command.SocialLoginRequestCommand;
import com.bit.lot.flower.auth.social.exception.SocialAuthException;
import com.bit.lot.flower.auth.social.valueobject.AuthId;
Expand All @@ -26,7 +27,7 @@ public SocialLoginRequestCommand getCommand(DefaultOAuth2User defaultOAuth2User)
private SocialLoginRequestCommand getOauth2LoginDto(DefaultOAuth2User oAuth2User,
AuthenticationProvider provider) {
if (provider == AuthenticationProvider.kakao) {
getKakaoDto(oAuth2User);
return getKakaoDto(oAuth2User);
}
throw new SocialAuthException("아직 존재 하지 않는 인증 제공자입니다.");
}
Expand All @@ -39,7 +40,13 @@ private SocialLoginRequestCommand getKakaoDto(DefaultOAuth2User oAuth2User) {
String email = kakaoAccount.get("email");
String nickname = properties.get("nickname");
return SocialLoginRequestCommand.builder().email(email).nickname(nickname)
<<<<<<< Updated upstream
=======
.phoneNumber(OauthInfoConvertor.convertInternationalPhoneNumberToDomestic(phoneNumber))
>>>>>>> Stashed changes
.socialId(AuthId.builder().value(Long.valueOf(id)).build()).build();
}



}

0 comments on commit a0ba195

Please sign in to comment.