Skip to content

Commit

Permalink
fix: Claims sub 항목으로 사용하게 수정 (#269)
Browse files Browse the repository at this point in the history
* feat: 외부 API 호출 툴 Feign 설정

* feat: Apple 로그인 구현 + 회원가입 Reqeust Provider 추가

* fix: Claims sub 항목 빼서 쓰게 수정

* fix: AuthorizationCode Request 제거
  • Loading branch information
sejineer authored Feb 21, 2024
1 parent 75dfd83 commit bc45f7a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.shallwe.domain.auth.dto.*;
import com.shallwe.domain.auth.exception.AlreadyExistEmailException;
import com.shallwe.domain.auth.exception.InvalidPasswordException;
import com.shallwe.domain.auth.exception.InvalidProviderIdException;
import com.shallwe.domain.auth.exception.UnRegisteredUserException;
import com.shallwe.domain.common.Status;
import com.shallwe.domain.shopowner.domain.ShopOwner;
Expand Down Expand Up @@ -264,9 +265,9 @@ private boolean valid(final String refreshToken) {
@Transactional
public AuthRes appleSignIn(AppleSignInReq appleSignInReq) {
Claims claims = appleJwtUtils.getClaimsBy(appleSignInReq.getIdentityToken());
Long userId = Long.parseLong(claims.getId());
String providerId = claims.get("sub").toString();

User user = userRepository.findById(userId).orElseThrow(InvalidUserException::new);
User user = userRepository.findByProviderId(providerId).orElseThrow(InvalidProviderIdException::new);
if(user.getName() == null || user.getPhoneNumber() == null || user.getAge() == null || user.getGender() == null) {
throw new UnRegisteredUserException();
}
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/shallwe/domain/auth/dto/AppleSignInReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
@Data
public class AppleSignInReq {

@Schema(type = "string", description = "애플 로그인을 위한 AuthorizationCode")
private String authorizationCode;

@Schema(type = "string", description = "애플 로그인을 위한 IdentityToken")
private String identityToken;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shallwe/domain/auth/dto/SignUpReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class SignUpReq {
@Schema( type = "string", example = "123123", description="카카오/애플 고유 유저 ID 입니다.")
private String providerId;

@Schema( type = "string", example = "KAKAO / APPLE", description="카카오/애플/구글 로그인 제공자 입니다.")
@Schema( type = "string", example = "KAKAO / APPLE / GOOGLE ", description="카카오/애플/구글 로그인 제공자 입니다.")
private Provider provider;

@Schema( type = "string", example = "string", description="카카오톡 닉네임 입니다.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.shallwe.domain.auth.exception;

public class InvalidProviderIdException extends RuntimeException {

public InvalidProviderIdException() {
super("존재하지 않는 provider id 입니다.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public ResponseCustom<AuthRes> signIn(

@Operation(summary = "애플 로그인", description = "애플 로그인을 수행합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "애플 로그인 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = AppleSignInRes.class) ) } ),
@ApiResponse(responseCode = "200", description = "애플 로그인 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = AuthRes.class) ) } ),
@ApiResponse(responseCode = "400", description = "애플 로그인 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ),
})
@PostMapping(value="/sign-in/apple")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ public interface UserRepository extends JpaRepository<User, Long> {

Optional<User> findByEmailAndStatus(String email, Status status);

Optional<User> findByProviderId(String providerId);

}

0 comments on commit bc45f7a

Please sign in to comment.