From a3aa238c452b335769b2e8e9c8a4127cabd8aad8 Mon Sep 17 00:00:00 2001 From: kchaeeun Date: Sat, 17 Aug 2024 22:50:37 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20[FEAT]=20API=20=EC=97=B0?= =?UTF-8?q?=EB=8F=99=EC=9D=84=20=EC=9C=84=ED=95=9C=20providerId,=20accessT?= =?UTF-8?q?oken=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/compiler.xml | 2 +- .idea/inspectionProfiles/Project_Default.xml | 2 ++ .../majorLink/global/auth/AuthController.java | 21 ++++--------- .../OAuth2AuthenticationSuccessHandler.java | 8 ++--- .../global/oauth2/OAuthAttributes.java | 30 +++++++++++-------- .../global/oauth2/OAuthLoginService.java | 1 + majorLink/src/main/resources/application.yml | 2 -- 7 files changed, 30 insertions(+), 36 deletions(-) diff --git a/.idea/compiler.xml b/.idea/compiler.xml index c6160d9..c82393e 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -7,7 +7,7 @@ - + diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index 7aee3ff..e0ce15f 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -9,6 +9,8 @@ diff --git a/majorLink/src/main/java/com/example/majorLink/global/auth/AuthController.java b/majorLink/src/main/java/com/example/majorLink/global/auth/AuthController.java index df99641..793b567 100644 --- a/majorLink/src/main/java/com/example/majorLink/global/auth/AuthController.java +++ b/majorLink/src/main/java/com/example/majorLink/global/auth/AuthController.java @@ -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") diff --git a/majorLink/src/main/java/com/example/majorLink/global/oauth2/OAuth2AuthenticationSuccessHandler.java b/majorLink/src/main/java/com/example/majorLink/global/oauth2/OAuth2AuthenticationSuccessHandler.java index 6240bd2..78baa63 100644 --- a/majorLink/src/main/java/com/example/majorLink/global/oauth2/OAuth2AuthenticationSuccessHandler.java +++ b/majorLink/src/main/java/com/example/majorLink/global/oauth2/OAuth2AuthenticationSuccessHandler.java @@ -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); diff --git a/majorLink/src/main/java/com/example/majorLink/global/oauth2/OAuthAttributes.java b/majorLink/src/main/java/com/example/majorLink/global/oauth2/OAuthAttributes.java index 6485509..9374e58 100644 --- a/majorLink/src/main/java/com/example/majorLink/global/oauth2/OAuthAttributes.java +++ b/majorLink/src/main/java/com/example/majorLink/global/oauth2/OAuthAttributes.java @@ -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 attributes) { Map response = (Map) attributes.get(userNameAttribute); @@ -36,18 +41,19 @@ public static OAuthAttributes of(SocialType provider, String userNameAttribute, public static OAuthAttributes ofNaver(Map 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; } diff --git a/majorLink/src/main/java/com/example/majorLink/global/oauth2/OAuthLoginService.java b/majorLink/src/main/java/com/example/majorLink/global/oauth2/OAuthLoginService.java index c128c0d..8a1ffc4 100644 --- a/majorLink/src/main/java/com/example/majorLink/global/oauth2/OAuthLoginService.java +++ b/majorLink/src/main/java/com/example/majorLink/global/oauth2/OAuthLoginService.java @@ -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("***********************"); diff --git a/majorLink/src/main/resources/application.yml b/majorLink/src/main/resources/application.yml index 97089fd..1da8831 100644 --- a/majorLink/src/main/resources/application.yml +++ b/majorLink/src/main/resources/application.yml @@ -45,8 +45,6 @@ spring: host: localhost port: 6379 database: 1 -server: - port: 9000 logging: level: From f8f58bce03411ea67812b948448a739ef61412e7 Mon Sep 17 00:00:00 2001 From: kchaeeun Date: Sat, 17 Aug 2024 22:59:59 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20[BUG]=20=EC=98=A4=EB=9E=9C?= =?UTF-8?q?=20No=20pull=EB=A1=9C=20=EC=83=9D=EA=B8=B4=20=EC=B6=A9=EB=8F=8C?= =?UTF-8?q?=20=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/modules.xml | 2 +- majorLink/src/main/resources/application.yml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.idea/modules.xml b/.idea/modules.xml index 995068b..c74ba53 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + diff --git a/majorLink/src/main/resources/application.yml b/majorLink/src/main/resources/application.yml index 1da8831..a7fcde7 100644 --- a/majorLink/src/main/resources/application.yml +++ b/majorLink/src/main/resources/application.yml @@ -46,6 +46,9 @@ spring: port: 6379 database: 1 +server: + port: 8080 + logging: level: org: