Skip to content

Commit

Permalink
feat: add native login
Browse files Browse the repository at this point in the history
  • Loading branch information
CChuYong committed Feb 2, 2025
1 parent c129670 commit 19b7afb
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 3 deletions.
16 changes: 16 additions & 0 deletions user-service/src/main/java/kr/mafoo/user/api/AuthApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import kr.mafoo.user.controller.dto.request.AppleLoginRequest;
import kr.mafoo.user.controller.dto.request.AppleNativeLoginRequest;
import kr.mafoo.user.controller.dto.request.KakaoLoginRequest;
import kr.mafoo.user.controller.dto.request.KakaoNativeLoginRequest;
import kr.mafoo.user.controller.dto.request.TokenRefreshRequest;
import kr.mafoo.user.controller.dto.response.LoginResponse;
import org.springframework.validation.annotation.Validated;
Expand Down Expand Up @@ -32,6 +34,20 @@ Mono<LoginResponse> loginWithApple(
ServerWebExchange exchange
);

@Operation(summary = "카카오 네티이브 로그인", description = "카카오 인가 코드로 로그인(토큰 발행)합니다.")
@PostMapping("/login/kakao-native")
Mono<LoginResponse> loginWithKakaoNative(
@RequestBody KakaoNativeLoginRequest request,
ServerWebExchange exchange
);

@Operation(summary = "애플 네이티브 로그인" , description = "애플 인가 코드로 로그인(토큰 발행)합니다.")
@PostMapping("/login/apple-native")
Mono<LoginResponse> loginWithAppleNative(
@RequestBody AppleNativeLoginRequest request,
ServerWebExchange exchange
);

@Operation(summary = "토큰 갱신", description = "리프레시 토큰으로 기존 토큰을 갱신합니다.")
@PostMapping("/refresh")
Mono<LoginResponse> loginWithRefreshToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@ConfigurationProperties(prefix = "app.oauth.apple")
@ConfigurationPropertiesBinding
public record AppleOAuthProperties(
String clientId
String clientId,
String nativeClientId
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import kr.mafoo.user.api.AuthApi;
import kr.mafoo.user.controller.dto.request.AppleLoginRequest;
import kr.mafoo.user.controller.dto.request.AppleNativeLoginRequest;
import kr.mafoo.user.controller.dto.request.KakaoLoginRequest;
import kr.mafoo.user.controller.dto.request.KakaoNativeLoginRequest;
import kr.mafoo.user.controller.dto.request.TokenRefreshRequest;
import kr.mafoo.user.controller.dto.response.LoginResponse;
import kr.mafoo.user.domain.AuthToken;
Expand Down Expand Up @@ -33,6 +35,19 @@ public Mono<LoginResponse> loginWithApple(AppleLoginRequest request, ServerWebEx
.map(this::toLoginResponse);
}

@Override
public Mono<LoginResponse> loginWithKakaoNative(KakaoNativeLoginRequest request, ServerWebExchange exchange) {
return null;
}

@Override
public Mono<LoginResponse> loginWithAppleNative(AppleNativeLoginRequest request, ServerWebExchange exchange) {
String userAgent = getUserAgent(exchange);
return authService
.loginWithApple(request.identityToken(), userAgent)
.map(this::toLoginResponse);
}

@Override
public Mono<LoginResponse> loginWithRefreshToken(TokenRefreshRequest request) {
return authService
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package kr.mafoo.user.controller.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "애플 로그인 요청")
public record AppleNativeLoginRequest(
@Schema(description = "엑세스 코드", example = "test")
String identityToken
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package kr.mafoo.user.controller.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "카카오 로그인 요청")
public record KakaoNativeLoginRequest(
@Schema(description = "카카오 엑세스 토큰", example = "test")
String accessToken
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ private Mono<AppleLoginInfo> getUserInfoWithAppleAccessToken(AppleKeyResponse[]
.parseSignedClaims(identityToken);

Set<String> audienceList = claims.getPayload().get("aud", Set.class);
if (audienceList == null || !audienceList.contains(appleOAuthProperties.clientId())) {
throw new RuntimeException();
if (audienceList == null || (!audienceList.contains(appleOAuthProperties.clientId()) && !audienceList.contains(appleOAuthProperties.nativeClientId()))) {
throw new RuntimeException("Invalid audience: " + audienceList);
}

return new AppleLoginInfo(claims.getPayload().get("sub", String.class));
Expand Down
1 change: 1 addition & 0 deletions user-service/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ app:
redirect-uri: ${KAKAO_REDIRECT_URL}
apple:
client-id: ${APPLE_CLIENT_ID}
native-client-id: ${APPLE_NATIVE_CLIENT_ID}
jwt:
verify-key: ${JWT_VERIFY_KEY}
expiration:
Expand Down

0 comments on commit 19b7afb

Please sign in to comment.