From b550cf181d2d4c21c087b4fc2faa348e3c3c46ea Mon Sep 17 00:00:00 2001 From: ihun-il Date: Sun, 28 Apr 2024 15:00:06 +0900 Subject: [PATCH] =?UTF-8?q?:recycle::=20openFeign=EC=9D=84=20=ED=86=B5?= =?UTF-8?q?=ED=95=B4=20=EC=B9=B4=EC=B9=B4=EC=98=A4,=20=EA=B5=AC=EA=B8=80?= =?UTF-8?q?=20=EC=84=9C=EB=B2=84=EC=97=90=20idToken,=20accessToken=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/api/client/GoogleAuthClient.java | 13 +++++++++++++ .../global/api/client/KakaoOauthClient.java | 12 ++++++++++++ .../global/api/dto/OauthTokenResponse.java | 15 +++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 src/main/java/ohsoontaxi/backend/global/api/dto/OauthTokenResponse.java diff --git a/src/main/java/ohsoontaxi/backend/global/api/client/GoogleAuthClient.java b/src/main/java/ohsoontaxi/backend/global/api/client/GoogleAuthClient.java index 5ba7c1f..479b25c 100644 --- a/src/main/java/ohsoontaxi/backend/global/api/client/GoogleAuthClient.java +++ b/src/main/java/ohsoontaxi/backend/global/api/client/GoogleAuthClient.java @@ -1,9 +1,13 @@ package ohsoontaxi.backend.global.api.client; +import feign.Headers; import ohsoontaxi.backend.global.api.dto.OIDCPublicKeysResponse; +import ohsoontaxi.backend.global.api.dto.OauthTokenResponse; import org.springframework.cache.annotation.Cacheable; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; @FeignClient(name = "GoogleAuthClient", url = "https://www.googleapis.com/oauth2") public interface GoogleAuthClient { @@ -11,5 +15,14 @@ public interface GoogleAuthClient { @Cacheable(cacheNames = "GoogleOICD", cacheManager = "oidcCacheManager") @GetMapping("/v3/certs") OIDCPublicKeysResponse getGoogleOIDCOpenKeys(); + + @Headers("Content-type: application/x-www-form-urlencoded;charset=utf-8") + @PostMapping( + "/v4/token?code={CODE}&client_id={CLIENT_ID}&client_secret={CLIENT_SECRET}&redirect_uri={REDIRECT_URI}&grant_type=authorization_code") + OauthTokenResponse googleAuth( + @PathVariable("CODE") String code, + @PathVariable("CLIENT_ID") String clientId, + @PathVariable("CLIENT_SECRET") String client_secret, + @PathVariable("REDIRECT_URI") String redirectUri); } diff --git a/src/main/java/ohsoontaxi/backend/global/api/client/KakaoOauthClient.java b/src/main/java/ohsoontaxi/backend/global/api/client/KakaoOauthClient.java index 39d6f21..b642b08 100644 --- a/src/main/java/ohsoontaxi/backend/global/api/client/KakaoOauthClient.java +++ b/src/main/java/ohsoontaxi/backend/global/api/client/KakaoOauthClient.java @@ -1,9 +1,13 @@ package ohsoontaxi.backend.global.api.client; +import feign.Headers; import ohsoontaxi.backend.global.api.dto.OIDCPublicKeysResponse; +import ohsoontaxi.backend.global.api.dto.OauthTokenResponse; import org.springframework.cache.annotation.Cacheable; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; @FeignClient(name = "KakaoAuthClient", url = "https://kauth.kakao.com") public interface KakaoOauthClient { @@ -11,4 +15,12 @@ public interface KakaoOauthClient { @Cacheable(cacheNames = "KakaoOICD", cacheManager = "oidcCacheManager") @GetMapping("/.well-known/jwks.json") OIDCPublicKeysResponse getKakaoOIDCOpenKeys(); + + @Headers("Content-type: application/x-www-form-urlencoded;charset=utf-8") + @PostMapping( + "/oauth/token?grant_type=authorization_code&client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&code={CODE}") + OauthTokenResponse kakaoAuth( + @PathVariable("CLIENT_ID") String clientId, + @PathVariable("REDIRECT_URI") String redirectUri, + @PathVariable("CODE") String code); } diff --git a/src/main/java/ohsoontaxi/backend/global/api/dto/OauthTokenResponse.java b/src/main/java/ohsoontaxi/backend/global/api/dto/OauthTokenResponse.java new file mode 100644 index 0000000..3dcdf05 --- /dev/null +++ b/src/main/java/ohsoontaxi/backend/global/api/dto/OauthTokenResponse.java @@ -0,0 +1,15 @@ +package ohsoontaxi.backend.global.api.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class OauthTokenResponse { + @JsonProperty("id_token") + private String idToken; + + @JsonProperty("access_token") + private String accessToken; +} \ No newline at end of file