Skip to content

Commit

Permalink
[Feat/#10] 애플 로그인 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnsugyeong committed Feb 8, 2024
1 parent d0327ef commit 469c347
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/friends/easybud/auth/dto/OauthProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class OauthProperties {

private OAuthSecret kakao;
// private OAuthSecret apple;
private OAuthSecret apple;

@Getter
@Setter
Expand All @@ -27,8 +27,8 @@ public String getBaseUrl(SocialProvider provider) {
switch (provider) {
case KAKAO:
return getOAuthSecret(kakao).getBaseUrl();
// case APPLE:
// return getOAuthSecret(apple).getBaseUrl();
case APPLE:
return getOAuthSecret(apple).getBaseUrl();
default:
throw new GeneralException(ErrorStatus.OAUTH_PROVIDER_NOT_FOUND);
}
Expand All @@ -38,8 +38,8 @@ public String getAppKey(SocialProvider provider) {
switch (provider) {
case KAKAO:
return getOAuthSecret(kakao).getAppKey();
// case APPLE:
// return getOAuthSecret(apple).getAppKey();
case APPLE:
return getOAuthSecret(apple).getAppKey();
default:
throw new GeneralException(ErrorStatus.OAUTH_PROVIDER_NOT_FOUND);
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/friends/easybud/auth/feign/AppleOauthClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.friends.easybud.auth.feign;

import com.friends.easybud.auth.dto.OIDCPublicKeysResponse;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;

@FeignClient(name = "appleOauthClient", url = "https://appleid.apple.com")
public interface AppleOauthClient {

@Cacheable(cacheNames = "AppleOICD", cacheManager = "oidcCacheManager")
@GetMapping("/auth/keys")
OIDCPublicKeysResponse getAppleOIDCOpenKeys();

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.friends.easybud.auth.service;

import static com.friends.easybud.member.domain.SocialProvider.APPLE;
import static com.friends.easybud.member.domain.SocialProvider.KAKAO;

import com.friends.easybud.auth.dto.IdTokenRequest;
import com.friends.easybud.auth.dto.OIDCDecodePayload;
import com.friends.easybud.auth.dto.OIDCPublicKeysResponse;
import com.friends.easybud.auth.dto.OauthProperties;
import com.friends.easybud.auth.dto.SocialLoginResponse;
import com.friends.easybud.auth.dto.SocialLoginType;
import com.friends.easybud.auth.feign.AppleOauthClient;
import com.friends.easybud.auth.feign.KakaoOauthClient;
import com.friends.easybud.global.exception.GeneralException;
import com.friends.easybud.global.response.code.ErrorStatus;
import com.friends.easybud.jwt.JwtDto;
import com.friends.easybud.jwt.JwtProvider;
import com.friends.easybud.member.domain.Member;
Expand All @@ -28,6 +34,7 @@ public class AuthServiceImpl implements AuthService {

private final OauthProperties oauthProperties;
private final KakaoOauthClient kakaoOauthClient;
private final AppleOauthClient appleOauthClient;
private final OauthOIDCService oauthOIDCService;
private final JwtProvider jwtProvider;
private final MemberRepository memberRepository;
Expand Down Expand Up @@ -68,7 +75,16 @@ private Member register(SocialProvider provider, OIDCDecodePayload oidcDecodePay
}

public OIDCDecodePayload getOIDCDecodePayload(SocialProvider provider, String idToken) {
OIDCPublicKeysResponse oidcPublicKeysResponse = kakaoOauthClient.getKakaoOIDCOpenKeys();
OIDCPublicKeysResponse oidcPublicKeysResponse;

if (provider.equals(KAKAO)) {
oidcPublicKeysResponse = kakaoOauthClient.getKakaoOIDCOpenKeys();
} else if (provider.equals(APPLE)) {
oidcPublicKeysResponse = appleOauthClient.getAppleOIDCOpenKeys();
} else {
throw new GeneralException(ErrorStatus.OAUTH_PROVIDER_NOT_FOUND);
}

return oauthOIDCService.getPayloadFromIdToken(
idToken,
oauthProperties.getBaseUrl(provider),
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ oauth:
base-url: ${KAKAO_BASE_URL}
app-key: ${KAKAO_APP_KEY}

# apple:
# base-url: ${APPLE_BASE_URL}
# app-key: ${APPLE_APP_KEY}
apple:
base-url: ${APPLE_BASE_URL}
app-key: ${APPLE_APP_KEY}

jwt:
secret: ${JWT_SECRET}
Expand Down

0 comments on commit 469c347

Please sign in to comment.