-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7510ea3
commit c9eb3c0
Showing
11 changed files
with
177 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
moodoodle-domain/src/main/java/zzangdol/user/domain/AuthProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package zzangdol.user.domain; | ||
|
||
public enum AuthProvider { | ||
KAKAO, NAVER, APPLE, DEFAULT | ||
KAKAO, GOOGLE, NAVER, APPLE, DEFAULT | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
moodoodle-infrastructure/src/main/java/zzangdol/oauth/client/google/GoogleLoginClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package zzangdol.oauth.client.google; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import zzangdol.oauth.client.SocialLoginClient; | ||
import zzangdol.oauth.dto.GoogleTokenResponse; | ||
import zzangdol.oauth.dto.GoogleUserInfoResponse; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class GoogleLoginClient implements SocialLoginClient<GoogleUserInfoResponse> { | ||
|
||
private final GoogleLoginTokenClient googleLoginTokenClient; | ||
private final GoogleLoginUserClient googleLoginUserClient; | ||
|
||
@Override | ||
public GoogleUserInfoResponse getUserInfo(String authorizationCode) { | ||
GoogleTokenResponse tokenInfo = googleLoginTokenClient.getTokenInfo(authorizationCode); | ||
return googleLoginUserClient.getUserInfo(tokenInfo.getAccessToken()); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...dle-infrastructure/src/main/java/zzangdol/oauth/client/google/GoogleLoginTokenClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package zzangdol.oauth.client.google; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.reactive.function.BodyInserters; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.core.publisher.Mono; | ||
import zzangdol.oauth.dto.GoogleTokenResponse; | ||
|
||
@Slf4j | ||
@Component | ||
public class GoogleLoginTokenClient { | ||
|
||
private WebClient webClient; | ||
|
||
@Value("${google.token.uri}") | ||
private String TOKEN_URI; | ||
|
||
@Value("${google.redirect.uri}") | ||
private String REDIRECT_URI; | ||
|
||
@Value("${google.grant.type}") | ||
private String GRANT_TYPE; | ||
|
||
@Value("${google.client.id}") | ||
private String CLIENT_ID; | ||
|
||
@Value("${google.client.secret}") | ||
private String CLIENT_SECRET; | ||
|
||
@Value("${google.scope}") | ||
private String SCOPE; | ||
|
||
@Value("${google.response_type}") | ||
private String RESPONSE_TYPE; | ||
|
||
@PostConstruct | ||
private void init() { | ||
this.webClient = WebClient.builder() | ||
.baseUrl(TOKEN_URI) | ||
.build(); | ||
} | ||
|
||
public GoogleTokenResponse getTokenInfo(final String code) { | ||
log.info("Requesting token with code: {}", code); | ||
|
||
return webClient.post() | ||
.uri("") | ||
.contentType(MediaType.APPLICATION_FORM_URLENCODED) | ||
.body(BodyInserters.fromFormData("grant_type", GRANT_TYPE) | ||
.with("client_id", CLIENT_ID) | ||
.with("redirect_uri", REDIRECT_URI) | ||
.with("code", code) | ||
.with("client_secret", CLIENT_SECRET)) | ||
.retrieve() | ||
.onStatus(status -> status.is4xxClientError() || status.is5xxServerError(), clientResponse -> clientResponse.bodyToMono(String.class) | ||
.flatMap(response -> { | ||
log.error("Error Response: {}", response); | ||
return Mono.error(new RuntimeException("Error Response: " + response)); | ||
})) | ||
.bodyToMono(GoogleTokenResponse.class) | ||
.block(); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...odle-infrastructure/src/main/java/zzangdol/oauth/client/google/GoogleLoginUserClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package zzangdol.oauth.client.google; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import zzangdol.oauth.dto.GoogleUserInfoResponse; | ||
|
||
@Slf4j | ||
@Component | ||
public class GoogleLoginUserClient { | ||
|
||
private final WebClient webClient; | ||
|
||
private static final String USER_INFO_URI = "https://www.googleapis.com/oauth2/v3/userinfo"; | ||
|
||
public GoogleLoginUserClient() { | ||
this.webClient = WebClient.builder() | ||
.baseUrl(USER_INFO_URI) | ||
.build(); | ||
} | ||
|
||
public GoogleUserInfoResponse getUserInfo(final String token) { | ||
return webClient.get() | ||
.uri("") | ||
.header("Authorization", "Bearer " + token) | ||
.retrieve() | ||
.bodyToMono(GoogleUserInfoResponse.class) | ||
.block(); | ||
} | ||
|
||
} |
3 changes: 2 additions & 1 deletion
3
...angdol/oauth/client/KakaoLoginClient.java → .../oauth/client/kakao/KakaoLoginClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...l/oauth/client/KakaoLoginTokenClient.java → ...h/client/kakao/KakaoLoginTokenClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ol/oauth/client/KakaoLoginUserClient.java → ...th/client/kakao/KakaoLoginUserClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
moodoodle-infrastructure/src/main/java/zzangdol/oauth/dto/GoogleTokenResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package zzangdol.oauth.dto; | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
public class GoogleTokenResponse { | ||
|
||
private String accessToken; | ||
private int expiresIn; | ||
private String refreshToken; | ||
private String scope; | ||
private String tokenType; | ||
private String idToken; | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
moodoodle-infrastructure/src/main/java/zzangdol/oauth/dto/GoogleUserInfoResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package zzangdol.oauth.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
|
||
@AllArgsConstructor | ||
public class GoogleUserInfoResponse implements SocialUserInfoResponse { | ||
|
||
private String email; | ||
private String name; | ||
|
||
@Override | ||
public String getEmail() { | ||
return this.email; | ||
} | ||
|
||
@Override | ||
public String getNickname() { | ||
return this.name; | ||
} | ||
} |