File tree Expand file tree Collapse file tree 3 files changed +14
-7
lines changed
src/main/java/com/memesphere/domain/user Expand file tree Collapse file tree 3 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -49,8 +49,18 @@ public ApiResponse<LoginResponse> kakaoLogin(@RequestParam("code") String code)
4949
5050 @ PostMapping ("/login/oauth2/google" )
5151 @ Operation (summary = "구글 로그인/회원가입 API" )
52- public ApiResponse <LoginResponse > googleLogin (@ RequestParam ("code" ) String code ) throws IOException {
53- TokenResponse googleTokenResponse = googleServiceImpl .getAccessTokenFromGoogle (code );
52+ public ApiResponse <LoginResponse > googleLogin (HttpServletRequest request , @ RequestParam ("code" ) String code ) throws IOException {
53+ TokenResponse googleTokenResponse = null ;
54+ String origin = request .getHeader ("Origin" );
55+
56+ if (origin .equals ("http://localhost:3000" )) {
57+ googleTokenResponse = googleServiceImpl .getAccessTokenFromGoogle (code , "http://localhost:3000/user/login/oauth2/google" );
58+ } else if (origin .equals ("http://localhost:8080" )) {
59+ googleTokenResponse = googleServiceImpl .getAccessTokenFromGoogle (code , "http://localhost:8080/user/login/oauth2/google" );
60+ } else if (origin .equals ("https://15.164.103.195.nip.io" )) {
61+ googleTokenResponse = googleServiceImpl .getAccessTokenFromGoogle (code , "https://15.164.103.195.nip.io/user/login/oauth2/google" );
62+ }
63+
5464 GoogleUserInfoResponse googleUserInfoResponse = googleServiceImpl .getUserInfo (googleTokenResponse .getAccessToken ());
5565 LoginResponse loginResponse = googleServiceImpl .handleUserLogin (googleUserInfoResponse );
5666
Original file line number Diff line number Diff line change 55import com .memesphere .domain .user .dto .response .TokenResponse ;
66
77public interface GoogleService {
8- TokenResponse getAccessTokenFromGoogle (String code );
8+ TokenResponse getAccessTokenFromGoogle (String code , String redirectUri );
99 GoogleUserInfoResponse getUserInfo (String accessToken );
1010 LoginResponse handleUserLogin (GoogleUserInfoResponse userInfo );
1111}
Original file line number Diff line number Diff line change @@ -33,9 +33,6 @@ public class GoogleServiceImpl implements GoogleService{
3333 @ Value ("${security.oauth2.client.registration.google.client-secret}" )
3434 private String clientSecret ;
3535
36- @ Value ("${security.oauth2.client.registration.google.redirect-uri}" )
37- private String redirectUri ;
38-
3936 @ Value ("${security.oauth2.client.registration.google.authorization-grant-type}" )
4037 private String authorizationCode ;
4138
@@ -46,7 +43,7 @@ public class GoogleServiceImpl implements GoogleService{
4643 private String userInfoUri ;
4744
4845
49- public TokenResponse getAccessTokenFromGoogle (String code ) {
46+ public TokenResponse getAccessTokenFromGoogle (String code , String redirectUri ) {
5047 try {
5148 String decodedCode = URLDecoder .decode (code , StandardCharsets .UTF_8 );
5249
You can’t perform that action at this time.
0 commit comments