-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️: openFeign을 통해 카카오, 구글 서버에 idToken, accessToken 요청
- Loading branch information
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/main/java/ohsoontaxi/backend/global/api/client/GoogleAuthClient.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,15 +1,28 @@ | ||
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 { | ||
|
||
@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); | ||
} | ||
|
12 changes: 12 additions & 0 deletions
12
src/main/java/ohsoontaxi/backend/global/api/client/KakaoOauthClient.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,14 +1,26 @@ | ||
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 { | ||
|
||
@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); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/ohsoontaxi/backend/global/api/dto/OauthTokenResponse.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,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; | ||
} |