Skip to content

Commit f6adb79

Browse files
authored
Merge pull request #89 from noeyeyh/fix/google
#88 Fix: 구글 로그인 redirect uri 설정
2 parents 3e9b0e3 + e8e08ec commit f6adb79

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/main/java/com/memesphere/domain/user/controller/UserController.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff 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

src/main/java/com/memesphere/domain/user/service/GoogleService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.memesphere.domain.user.dto.response.TokenResponse;
66

77
public 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
}

src/main/java/com/memesphere/domain/user/service/GoogleServiceImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)