Skip to content

Commit

Permalink
feat: 로컬과 배포 환경에 따른 로그인 환경 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
sycuuui committed Nov 13, 2024
1 parent 65dd4b8 commit 2f8b394
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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);

Expand Down

0 comments on commit 2f8b394

Please sign in to comment.