Skip to content

Commit

Permalink
Merge pull request #149 from BOOK-TALK/revert-148-#145-refactor-oidc
Browse files Browse the repository at this point in the history
Revert "#145 [refactor] OIDC 생성자 할당 로직 리팩토링"
  • Loading branch information
chanwoo7 authored Sep 13, 2024
2 parents b32362c + b58f2fc commit e3a2a2b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,38 @@
import com.book.backend.exception.CustomException;
import com.book.backend.exception.ErrorCode;
import com.book.backend.domain.oidc.kakao.KakaoAuthProvider;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.EnumMap;
import java.util.Map;

@Component
@RequiredArgsConstructor
public class OidcProviderFactory {

private final Map<Provider, OidcProvider> authProviderMap = new EnumMap<>(Provider.class); // OIDC 구현체별로 적절한 구현체를 저장
private final Map<Provider, OidcProvider> authProviderMap; // OIDC 구현체별로 적절한 구현체를 저장
private final KakaoAuthProvider kakaoAuthProvider;
private final AppleAuthProvider appleAuthProvider;

@PostConstruct
private void initialize() {
authProviderMap.put(Provider.KAKAO, kakaoAuthProvider);
authProviderMap.put(Provider.APPLE, appleAuthProvider);
public OidcProviderFactory(
AppleAuthProvider appleAuthProvider,
KakaoAuthProvider kakaoAuthProvider
) {
this.authProviderMap = new EnumMap<>(Provider.class);
this.kakaoAuthProvider = kakaoAuthProvider;
this.appleAuthProvider = appleAuthProvider;
initialize();
}

// 주어진 Provider와 idToken을 사용하여 해당 제공자의 ID를 반환
public String getProviderId(Provider provider, String idToken) {
return getProvider(provider).getProviderId(idToken);
}

private void initialize() {
authProviderMap.put(Provider.KAKAO, kakaoAuthProvider);
authProviderMap.put(Provider.APPLE, appleAuthProvider);
}

// 주어진 Provider에 대응하는 OidcProvider를 가져옴
private OidcProvider getProvider(final Provider provider) {
final OidcProvider oidcProvider = authProviderMap.get(provider);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package com.book.backend.domain.oidc.apple;

import com.book.backend.domain.oidc.record.OidcPublicKeyList;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;

@Component
@RequiredArgsConstructor
public class AppleAuthClient {

private final RestClient restClient;
@Value("${apple.publicKeyUri}")

private final String publicKeyUri;

public AppleAuthClient(
RestClient restClient,
@Value("${apple.publicKeyUri}") String publicKeyUri
) {
this.restClient = restClient;
this.publicKeyUri = publicKeyUri;
}

// 공개키 목록 반환
public OidcPublicKeyList getPublicKeys() {
return restClient.get()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package com.book.backend.domain.oidc.kakao;

import com.book.backend.domain.oidc.record.OidcPublicKeyList;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;

@Component
@RequiredArgsConstructor
public class KakaoAuthClient {

private final RestClient restClient;
@Value("${kakao.publicKeyUri}")
private final String publicKeyUri;

public KakaoAuthClient(
RestClient restClient,
@Value("${kakao.publicKeyUri}") String publicKeyUri
) {
this.restClient = restClient;
this.publicKeyUri = publicKeyUri;
}

// 공개키 목록 반환
public OidcPublicKeyList getPublicKeys() {
return restClient.get()
Expand Down

0 comments on commit e3a2a2b

Please sign in to comment.