Skip to content

Commit

Permalink
Merge pull request TeamMajorLink#45 from kchaeeun/feat#26
Browse files Browse the repository at this point in the history
✨[FEAT] 로그인 API 연동을 위한 providerId, accessToken 반환
  • Loading branch information
kchaeeun authored Aug 17, 2024
2 parents 76b1e80 + f8f58bc commit 231a858
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,13 @@ public void returnLoginResult(HttpServletResponse response,
}

@GetMapping("/result/new-user")
public void returnLoginResult(HttpServletResponse response,
@RequestParam(value = "username") String username,
@RequestParam(value = "email") String email,
@RequestParam(value = "profileImg") String profileImg,
@RequestParam(value = "phone") String phone,
@RequestParam(value = "gender", required = false) String gender) throws IOException {
FirstLoginResponse firstLogInResponse = FirstLoginResponse.builder()
.username(username)
.email(email)
.phone(phone)
.profileImg(profileImg)
.gender(gender)
.build();
public void returnFirstLoginResult(HttpServletResponse response,
@RequestParam(name = "providerId") String providerId,
@RequestParam(name = "accessToken") String accessToken)
throws IOException {

// response.setHeader("temp-token", tempToken);
response.getWriter().write(objectMapper.writeValueAsString(firstLogInResponse));
response.setHeader("providerId", providerId);
response.setHeader("accessToken", accessToken);
}

// @PostMapping("/reissue-token")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,8 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo

OAuthAttributes attributes = oAuth2User.getOAuthAttributes();
String uri = UriComponentsBuilder.fromUriString(redirectUrl + "/new-user")
// .queryParam("temp-token", String.valueOf(socialInfo.getTemporalToken()))
.queryParam("username", attributes.getUsername())
.queryParam("email", attributes.getEmail())
.queryParam("profileImg", attributes.getProfileImg())
.queryParam("phone", attributes.getPhone())
.queryParam("gender", attributes.getGender())
.queryParam("providerId", attributes.getId())
.queryParam("accessToken", attributes.getAccessToken())
.toUriString();

response.sendRedirect(uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public class OAuthAttributes {
private String profileImg;
private Gender gender;
private String phone;
private String accessToken;

public void updateAccessToken(String accessToken) {
this.accessToken = accessToken;
}

public static OAuthAttributes of(SocialType provider, String userNameAttribute, Map<String, Object> attributes) {
Map<String, Object> response = (Map<String, Object>) attributes.get(userNameAttribute);
Expand All @@ -36,18 +41,19 @@ public static OAuthAttributes of(SocialType provider, String userNameAttribute,

public static OAuthAttributes ofNaver(Map<String, Object> response) {
OAuthAttributes oAuthAttributes = new OAuthAttributes();
oAuthAttributes.id = (String) response.get("id");
oAuthAttributes.email = (String) response.get("email");
oAuthAttributes.username = (String) response.get("name");
oAuthAttributes.phone = (String) response.get("phone");
oAuthAttributes.profileImg = (String) response.get("profile_image");
String gender = (String) response.get("gender");

if ("F".equals(gender)) {
oAuthAttributes.gender = Gender.FEMALE;
} else if ("M".equals(gender)) {
oAuthAttributes.gender = Gender.MALE;
}
// oAuthAttributes.id = (String) response.get("id");
// oAuthAttributes.email = (String) response.get("email");
// oAuthAttributes.username = (String) response.get("name");
// oAuthAttributes.phone = (String) response.get("phone");
// oAuthAttributes.profileImg = (String) response.get("profile_image");
oAuthAttributes.accessToken = (String) response.get("accessToken");
// String gender = (String) response.get("gender");
//
// if ("F".equals(gender)) {
// oAuthAttributes.gender = Gender.FEMALE;
// } else if ("M".equals(gender)) {
// oAuthAttributes.gender = Gender.MALE;
// }

return oAuthAttributes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic
.getUserNameAttributeName();

OAuthAttributes oAuthAttributes = OAuthAttributes.of(provider, userNameAttribute, oAuth2User.getAttributes());
oAuthAttributes.updateAccessToken(userRequest.getAccessToken().getTokenValue());

log.info(oAuthAttributes.getId());
log.info("***********************");
Expand Down
1 change: 1 addition & 0 deletions majorLink/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ spring:
host: localhost
port: 6379
database: 1

server:
port: 8080

Expand Down

0 comments on commit 231a858

Please sign in to comment.