diff --git a/src/main/java/com/gongjakso/server/domain/member/service/AuthService.java b/src/main/java/com/gongjakso/server/domain/member/service/AuthService.java index 25926c1..2491b9d 100644 --- a/src/main/java/com/gongjakso/server/domain/member/service/AuthService.java +++ b/src/main/java/com/gongjakso/server/domain/member/service/AuthService.java @@ -35,15 +35,15 @@ public LoginRes signIn(String code, String redirectUri, String type) { // Business Logic String loginTypeUpper = type.toUpperCase(); LoginType loginType = LoginType.valueOf(loginTypeUpper); - Member member = null; - if(loginType.equals(LoginType.KAKAO)) { - member = kakaoMember(code, redirectUri); - } + Member member = switch (loginType) { + case KAKAO -> kakaoMember(code, redirectUri); + case GOOGLE -> googleMember(code, redirectUri); - if(loginType.equals(LoginType.GOOGLE)) { - member = googleMember(code, redirectUri); - } + default -> null; + }; + + assert member != null; TokenDto tokenDto = tokenProvider.createToken(member); @@ -55,7 +55,7 @@ public LoginRes signIn(String code, String redirectUri, String type) { return LoginRes.of(member, tokenDto); } - public Member kakaoMember(String code, String redirectUri) { + private Member kakaoMember(String code, String redirectUri) { // 카카오로 액세스 토큰 요청하기 KakaoToken kakaoAccessToken = kakaoClient.getKakaoAccessToken(code, redirectUri); @@ -79,7 +79,7 @@ public Member kakaoMember(String code, String redirectUri) { return member; } - public Member googleMember(String code, String redirectUri) { + private Member googleMember(String code, String redirectUri) { // 구글로 액세스 토큰 요청하기 GoogleToken googleAccessToken = googleClient.getGoogleAccessToken(code, redirectUri); diff --git a/src/main/java/com/gongjakso/server/global/security/google/GoogleClient.java b/src/main/java/com/gongjakso/server/global/security/google/GoogleClient.java index 79c4cfb..d458779 100644 --- a/src/main/java/com/gongjakso/server/global/security/google/GoogleClient.java +++ b/src/main/java/com/gongjakso/server/global/security/google/GoogleClient.java @@ -14,19 +14,31 @@ @Component @RequiredArgsConstructor public class GoogleClient { - @Value("${spring.security.oauth2.client.registration.google.client-id}") - private String googleClientId; + @Value("${spring.security.oauth2.client.registration.google-local.redirect-uri}") + private String localGoogleRedirectUri; - @Value("${spring.security.oauth2.client.registration.google.client-secret}") - private String googleClientSecret; + @Value("${spring.security.oauth2.client.registration.google-local.client-id}") + private String localGoogleClientId; - @Value("${spring.security.oauth2.client.registration.google.authorization-grant-type}") + @Value("${spring.security.oauth2.client.registration.google-local.client-secret}") + private String localGoogleClientSecret; + + @Value("${spring.security.oauth2.client.registration.google-dev.redirect-uri}") + private String devGoogleRedirectUri; + + @Value("${spring.security.oauth2.client.registration.google-dev.client-id}") + private String devGoogleClientId; + + @Value("${spring.security.oauth2.client.registration.google-dev.client-secret}") + private String devGoogleClientSecret; + + @Value("${spring.security.oauth2.client.registration.google-dev.authorization-grant-type}") private String googleGrantType; - @Value("${spring.security.oauth2.client.provider.google.token-uri}") + @Value("${spring.security.oauth2.client.provider.google-dev.token-uri}") private String googleTokenUri; - @Value("${spring.security.oauth2.client.provider.google.user-info-uri}") + @Value("${spring.security.oauth2.client.provider.google-dev.user-info-uri}") private String googleUserInfoUri; /** @@ -35,6 +47,18 @@ public class GoogleClient { * @return - */ public GoogleToken getGoogleAccessToken(String code, String redirectUri) { + String googleClientId = null; + String googleClientSecret = null; + if(redirectUri.equals(devGoogleRedirectUri)){ + googleClientId = devGoogleClientId; + googleClientSecret = devGoogleClientSecret; + } + + if(redirectUri.equals(localGoogleRedirectUri)) { + googleClientId = localGoogleClientId; + googleClientSecret = localGoogleClientSecret; + } + // 요청 보낼 객체 기본 생성 WebClient webClient = WebClient.create(googleTokenUri);