dnd-side-project / dnd-5th-10-backend

IT 면접 지식 공유 플랫폼 IT'erview Backend-repo
4 stars 0 forks source link

github 로그인 시 정상적으로 토큰 생성 안되는 문제 #17

Closed d36choi closed 3 years ago

d36choi commented 3 years ago
  1. github id -> Integer Type 이라 형변환 에러 image

    String jwtToken = JWT.create()
                .withSubject(principal.getAttribute("sub"))
                .withExpiresAt(new Date(System.currentTimeMillis()+ JwtProperties.EXPIRATION_TIME))
                .withClaim("id", (Long) principal.getAttribute("id"))
                .withClaim("email", (String) principal.getAttribute("email"))
                .sign(Algorithm.HMAC256(JwtProperties.SECRET));
        response.addHeader(JwtProperties.HEADER_STRING, JwtProperties.TOKEN_PREFIX + jwtToken);
  2. 구글 아이디로 가입했는데 깃허브 아이디로 로그인 요청시, CustomOauth2UserService 아래 조건문에서 예외뜨는데 컨트롤러에서 확인 불가능

    if(userOptional.isPresent()) {
            user = userOptional.get();
            if(!user.getProvider().equals(AuthProvider.valueOf(oAuth2UserRequest.getClientRegistration().getRegistrationId()))) {
                OAuth2Error oauth2Error = new OAuth2Error("wrong_account_provider",
                        "login with wrong provider email", null);
                throw new OAuth2AuthenticationException(oauth2Error, oauth2Error.toString());
            }
            user = updateExistingUser(user, oAuth2UserInfo);
        }
d36choi commented 3 years ago
  1. Provider_ID 가 github 최초 로그인시에서는 주입이 되지 않음
RulLu16 commented 3 years ago

https://stackoverflow.com/questions/35373995/github-user-email-is-null-despite-useremail-scope