Skip to content

Commit

Permalink
Merge pull request #46 from onetime-with-members/feature/#38/social-e…
Browse files Browse the repository at this point in the history
…mail

[feat] : 소셜 로그인 시 유저 이메일을 가져올 수 있다
  • Loading branch information
bbbang105 authored Sep 29, 2024
2 parents 9c916ff + 02a2650 commit d954a24
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/main/java/side/onetime/auth/dto/GoogleUserInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ public String getProvider() {
public String getName() {
return (String) attributes.get("name");
}

@Override
public String getEmail() {
return (String) attributes.get("email");
}
}
7 changes: 5 additions & 2 deletions src/main/java/side/onetime/auth/dto/KakaoUserInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class KakaoUserInfo implements OAuth2UserInfo {

@Override
public String getProviderId() {
// Long 타입이기 때문에 toString으로 변환
return attributes.get("id").toString();
}

Expand All @@ -23,7 +22,11 @@ public String getProvider() {

@Override
public String getName() {
// kakao_account라는 Map에서 추출
return (String) ((Map) attributes.get("properties")).get("nickname");
}

@Override
public String getEmail() {
return (String) ((Map) attributes.get("kakao_account")).get("email");
}
}
5 changes: 5 additions & 0 deletions src/main/java/side/onetime/auth/dto/NaverUserInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ public String getProvider() {
public String getName() {
return (String) attributes.get("name");
}

@Override
public String getEmail() {
return (String) attributes.get("email");
}
}
1 change: 1 addition & 0 deletions src/main/java/side/onetime/auth/dto/OAuth2UserInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public interface OAuth2UserInfo {
String getProviderId();
String getProvider();
String getName();
String getEmail();
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private OAuth2UserInfo extractOAuth2UserInfo(OAuth2AuthenticationToken token, St
private void handleAuthentication(HttpServletRequest request, HttpServletResponse response, OAuth2UserInfo oAuth2UserInfo, String provider) throws IOException {
String providerId = oAuth2UserInfo.getProviderId();
String name = oAuth2UserInfo.getName();
String email = oAuth2UserInfo.getEmail();

User existUser = userRepository.findByProviderId(providerId);

Expand All @@ -86,9 +87,10 @@ private void handleAuthentication(HttpServletRequest request, HttpServletRespons
handleExistingUser(request, response, existUser);
}

log.info("유저 이름 : {}", name);
log.info("NAME : {}", name);
log.info("PROVIDER : {}", provider);
log.info("PROVIDER_ID : {}", providerId);
log.info("EMAIL : {}", email);
}

// 신규 유저 처리
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ spring:
client-secret: ${OAUTH_KAKAO_CLIENT_SECRET}
scope:
- profile_nickname
- account_email
authorization-grant-type: authorization_code
redirect-uri: ${OAUTH_KAKAO_REDIRECT_URI}
client-name: Kakao
Expand Down

0 comments on commit d954a24

Please sign in to comment.