Skip to content

Commit

Permalink
♻️: openFeign을 통해 카카오, 구글 서버에 idToken, accessToken 요청
Browse files Browse the repository at this point in the history
  • Loading branch information
Leehunil committed Apr 28, 2024
1 parent 3e4fcc4 commit b550cf1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
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);
}

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);
}
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;
}

0 comments on commit b550cf1

Please sign in to comment.