Skip to content

Commit

Permalink
feat: #11 google, apple config 및 Public Key API 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
psychology50 committed Dec 27, 2023
1 parent ec351b4 commit 7b2ef3f
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.kcy.fitapet.global.common.security.oauth.OauthOIDCHelper;
import com.kcy.fitapet.global.common.security.oauth.dto.OIDCDecodePayload;
import com.kcy.fitapet.global.common.security.oauth.dto.OIDCPublicKeyResponse;
import com.kcy.fitapet.global.common.security.oauth.kakao.KakaoOauthClient;
import com.kcy.fitapet.global.common.util.sms.SmsProvider;
import com.kcy.fitapet.global.common.util.sms.dto.SensInfo;
import com.kcy.fitapet.global.common.util.sms.dto.SmsRes;
Expand Down Expand Up @@ -141,7 +142,7 @@ private OIDCDecodePayload getPayload(ProviderType provider, String idToken, Stri
OIDCPublicKeyResponse oidcPublicKeyResponse = oauthClient.getOIDCPublicKey();

return oauthOIDCHelper.getPayloadFromIdToken(
idToken, oauthApplicationConfig.getAuthorizationUri(),
idToken, oauthApplicationConfig.getJwksUri(),
oauthApplicationConfig.getClientSecret(), nonce, oidcPublicKeyResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import java.util.List;

public interface OauthApplicationConfig {
String getAuthorizationUri();
String getJwksUri();
String getClientId();
String getClientSecret();
String getClientName();
List<String> getScopes();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public String getKidFromUnsignedTokenHeader(String token, String iss, String aud
@Override
public OIDCDecodePayload getOIDCTokenBody(String token, String modulus, String exponent) {
Claims body = getOIDCTokenJws(token, modulus, exponent).getBody();
log.info("body : {}", body);

return new OIDCDecodePayload(
body.getIssuer(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.kcy.fitapet.global.common.security.oauth.apple;

import com.kcy.fitapet.global.common.security.oauth.OauthApplicationConfig;
import jakarta.validation.constraints.NotEmpty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

@Getter
@Setter
@Validated
@Component
@ConfigurationProperties(prefix = "oauth2.client.provider.apple")
@ConfigurationPropertiesBinding
public class AppleApplicationConfig implements OauthApplicationConfig {
@NotEmpty
private String jwksUri;
@NotEmpty
private String clientId;
@NotEmpty
private String clientSecret;
@NotEmpty
private String clientName;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.kcy.fitapet.global.common.security.oauth.apple;

import com.kcy.fitapet.global.common.security.oauth.OauthClient;
import com.kcy.fitapet.global.common.security.oauth.dto.OIDCPublicKeyResponse;
import com.kcy.fitapet.global.config.feign.AppleOauthConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;

@FeignClient(
name = "AppleOauthClient",
url = "${oauth2.client.provider.apple.jwks-uri}",
configuration = AppleOauthConfig.class
)
public interface AppleOauthClient extends OauthClient {
@Override
@Cacheable(value = "AppleOauth", cacheManager = "oidcCacheManger")
@GetMapping("/auth/keys")
OIDCPublicKeyResponse getOIDCPublicKey();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.kcy.fitapet.global.common.security.oauth.google;

import com.kcy.fitapet.global.common.security.oauth.OauthApplicationConfig;
import jakarta.validation.constraints.NotEmpty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

@Getter
@Setter
@Validated
@Component
@ConfigurationProperties(prefix = "oauth2.client.provider.google")
@ConfigurationPropertiesBinding
public class GoogleApplicationConfig implements OauthApplicationConfig {
@NotEmpty
private String jwksUri;
@NotEmpty
private String clientId;
@NotEmpty
private String clientSecret;
@NotEmpty
private String clientName;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.kcy.fitapet.global.common.security.oauth.google;

import com.kcy.fitapet.global.common.security.oauth.OauthClient;
import com.kcy.fitapet.global.common.security.oauth.dto.OIDCPublicKeyResponse;
import com.kcy.fitapet.global.config.feign.GoogleOauthConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;

@FeignClient(
name = "GoogleOauthClient",
url = "${oauth2.client.provider.google.jwks-uri}",
configuration = GoogleOauthConfig.class
)
public interface GoogleOauthClient extends OauthClient {
@Override
@Cacheable(value = "GoogleOauth", cacheManager = "oidcCacheManger")
@GetMapping("/oauth2/v3/certs")
OIDCPublicKeyResponse getOIDCPublicKey();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.kcy.fitapet.global.common.security.oauth.OauthApplicationConfig;
import jakarta.validation.constraints.NotEmpty;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
Expand All @@ -19,12 +20,11 @@
@ConfigurationPropertiesBinding
public class KakaoApplicationConfig implements OauthApplicationConfig {
@NotEmpty
private String authorizationUri;
private String jwksUri;
@NotEmpty
private String clientId;
@NotEmpty
private String clientSecret;
@NotEmpty
private String clientName;
private List<String> scopes;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@FeignClient(
name = "KakaoOauthClient",
url = "${oauth2.client.provider.kakao.authorization-uri}",
url = "${oauth2.client.provider.kakao.jwks-uri}",
configuration = KakaoOauthConfig.class
)
public interface KakaoOauthClient extends OauthClient {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.kcy.fitapet.global.config.feign;

import feign.codec.Encoder;
import feign.form.FormEncoder;
import org.springframework.context.annotation.Bean;

public class AppleOauthConfig {
@Bean
Encoder formEncoder() {
return new FormEncoder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.kcy.fitapet.global.config.feign;

import feign.codec.Encoder;
import feign.form.FormEncoder;
import org.springframework.context.annotation.Bean;

public class GoogleOauthConfig {
@Bean
Encoder formEncoder() {
return new FormEncoder();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import org.springframework.context.annotation.Bean;

public class KakaoOauthConfig {
// @Bean
// public OkHttpClient client() {
// return new OkHttpClient();
// }
@Bean
public OkHttpClient client() {
return new OkHttpClient();
}

@Bean
Encoder formEncoder() {
Expand Down
50 changes: 33 additions & 17 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,35 @@ spring:
resources:
add-mappings: false

cloud:
openfeign:
okhttp:
enabled: true
client:
config:
default:
connectTimeout: 5000
readTimeout: 10000
loggerLevel: full

oauth2:
client:
provider:
kakao:
authorization-uri: ${KAKAO_AUTH_URI}
jwks-uri: ${KAKAO_JWKS_URI}
client-id: ${KAKAO_CLIENT_ID}
client-secret: ${KAKAO_CLIENT_SECRET}
client-name: Kakao
scope:
- profile_nickname
- profile_image
- account_email

feign:
okhttp:
enabled: true
client:
config:
default:
connectTimeout: 5000
readTimeout: 10000
loggerLevel: full
httpclient:
max-connections: 1000
google:
jwks-uri: ${GOOGLE_JWKS_URI}
client-id: "client-id"
client-secret: "client-secret"
client-name: Google
apple:
jwks-uri: ${APPLE_JWKS_URI}
client-id: "client-id"
client-secret: "client-secret"
client-name: Apple

springdoc:
default-consumes-media-type: application/json;charset=UTF-8
Expand Down Expand Up @@ -137,6 +142,17 @@ spring:
resources:
add-mappings: false

cloud:
openfeign:
okhttp:
enabled: true
client:
config:
default:
connectTimeout: 5000
readTimeout: 10000
loggerLevel: full

springdoc:
default-consumes-media-type: application/json;charset=UTF-8
default-produces-media-type: application/json;charset=UTF-8
Expand Down

0 comments on commit 7b2ef3f

Please sign in to comment.