Skip to content

Commit

Permalink
Merge pull request #151 from Team-Motivoo/fix/#150-apple_login_bug
Browse files Browse the repository at this point in the history
[FIX] apple login bug
  • Loading branch information
jun02160 authored Mar 25, 2024
2 parents 8c7bb0d + de3e264 commit c5a4ebb
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 29 deletions.
3 changes: 0 additions & 3 deletions motivoo-api/src/test/java/controller/OauthControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
import sopt.org.motivoo.api.controller.auth.dto.response.LoginResponse;
import sopt.org.motivoo.api.controller.auth.dto.response.OauthTokenResponse;
import sopt.org.motivoo.common.response.ApiResponse;
import sopt.org.motivoo.domain.auth.dto.request.OauthTokenCommand;
import sopt.org.motivoo.domain.auth.dto.response.LoginResult;
import sopt.org.motivoo.domain.auth.dto.response.OauthTokenResult;
import sopt.org.motivoo.domain.user.repository.UserRepository;

@Slf4j
Expand Down
3 changes: 1 addition & 2 deletions motivoo-api/src/test/java/fixture/UserFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static User createUserV3(){
.nickname(USER_NICKNAME3)
.socialId(SOCIAL_ID)
.socialPlatform(USER_SOCIAL_PLATFORM3)
.socialAccessToken(SOCIAL_ACCESS_TOKEN)
// .socialAccessToken(SOCIAL_ACCESS_TOKEN)
.refreshToken(REFRESH_TOKEN)
.type(USER_TYPE3)
.deleted(DELETED)
Expand All @@ -87,7 +87,6 @@ public static LoginResponse createLoginResponse() {
return LoginResponse.builder()
.id(user.getSocialId())
.nickname(user.getNickname())
.accessToken(user.getSocialAccessToken())
.refreshToken(user.getRefreshToken())
.tokenType("Bearer").build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,17 @@ public LoginResult login(OauthTokenCommand tokenRequest) {
List<User> userEntity = userRetriever.getUsersBySocialId(applePlatformMember.platformId());
//처음 로그인 하거나 탈퇴한 경우 -> 회원가입
if (userEntity == null || isWithdrawn(userEntity)) {
saveUser(null, applePlatformMember.platformId(), socialPlatform, tokenRequest, refreshToken);
}
User user = saveUser(null, applePlatformMember.platformId(), socialPlatform, tokenRequest, refreshToken);

//로그인
User user = userEntity.get(0);
updateRefreshToken(user, refreshToken);
String accessToken = jwtTokenProvider.createAccessToken(new UserAuthentication(user.getId(),null,null));
//로그인
updateRefreshToken(user, refreshToken);
String accessToken = jwtTokenProvider.createAccessToken(new UserAuthentication(user.getId(),null,null));

boolean isFinishedOnboarding = healthRetriever.existsHealthByUser(user);
boolean isMatched = user.getParentchild() != null && user.getParentchild().isMatched();
boolean isFinishedOnboarding = healthRetriever.existsHealthByUser(user);
boolean isMatched = user.getParentchild() != null && user.getParentchild().isMatched();

return LoginResult.of(userEntity.get(0), accessToken, refreshToken, isFinishedOnboarding, isMatched);
return LoginResult.of(user, accessToken, refreshToken, isFinishedOnboarding, isMatched);
}
}
throw new UserException(INVALID_SOCIAL_PLATFORM);
}
Expand Down Expand Up @@ -163,7 +162,7 @@ public User saveUser(String nickName, String providerId, SocialPlatform socialPl
.nickname(nickName)
.socialId(providerId)
.socialPlatform(socialPlatform)
.socialAccessToken(tokenRequest.accessToken())
// .socialAccessToken(tokenRequest.accessToken())
.refreshToken(refreshToken)
.type(UserType.NONE)
.deleted(Boolean.FALSE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class User extends BaseTimeEntity {

private String nickname;

private String socialAccessToken;
// private String socialAccessToken;

private String refreshToken;

Expand All @@ -83,12 +83,11 @@ public class User extends BaseTimeEntity {
private final List<UserMissionChoices> userMissionChoice = new ArrayList<>();

@Builder
private User(String nickname, String socialId, SocialPlatform socialPlatform, String socialAccessToken,
private User(String nickname, String socialId, SocialPlatform socialPlatform,
String refreshToken, UserType type, boolean deleted) {
this.nickname = nickname;
this.socialId = socialId;
this.socialPlatform = socialPlatform;
this.socialAccessToken = socialAccessToken;
this.refreshToken = refreshToken;
this.type = type;
this.deleted = deleted;
Expand Down Expand Up @@ -131,7 +130,6 @@ public void updateOnboardingInfo(UserType type, Integer age) {

public void deleteSocialInfo() {
this.socialPlatform = SocialPlatform.WITHDRAW;
this.socialAccessToken = null;
}

public void updateParentchild(Parentchild parentchild) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ public interface UserRepository extends JpaRepository<User, Long> {
@Query("select u.refreshToken from User u where u.id=?1")
String findRefreshTokenById(Long id);

@Query("select u.socialAccessToken from User u where u.id=?1")
String findSocialAccessTokenById(Long id);

@Query("select count(u.id) from User u where u.parentchild=?1")
int countByParentchild(Parentchild parentchild);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ public String getRefreshTokenById(Long userId) {
return userRepository.findRefreshTokenById(userId);
}

public String getAccessTokenById(Long userId) {
return userRepository.findSocialAccessTokenById(userId);
}

public void saveUser(User newUser) {
userRepository.save(newUser);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package sopt.org.motivoo.external.client.auth;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import feign.Logger;
import sopt.org.motivoo.external.MotivooExternalRoot;

@Configuration
@EnableFeignClients(basePackageClasses = MotivooExternalRoot.class)
public class FeignClientConfig {

@Bean
Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class AppleLoginService {
public OAuthPlatformMemberResult getApplePlatformMember(String identityToken) {
Map<String, String> headers = appleJwtParser.parseHeaders(identityToken);
ApplePublicKeys applePublicKeys = appleClient.getApplePublicKeys();

PublicKey publicKey = publicKeyGenerator.generatePublicKey(headers, applePublicKeys);

Claims claims = appleJwtParser.parsePublicKeyAndGetClaims(identityToken, publicKey);
Expand All @@ -42,5 +41,4 @@ private void validateClaims(Claims claims) {
throw new BusinessException(INVALID_APPLE_CLAIMS);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static sopt.org.motivoo.common.advice.CommonExceptionType.*;

import org.springframework.stereotype.Component;

import sopt.org.motivoo.common.advice.BusinessException;
import sopt.org.motivoo.external.client.auth.apple.ApplePublicKey;
import sopt.org.motivoo.external.client.auth.apple.ApplePublicKeys;
Expand Down Expand Up @@ -32,8 +33,8 @@ public PublicKey generatePublicKey(Map<String, String> headers, ApplePublicKeys
}

private PublicKey generatePublicKeyWithApplePublicKey(ApplePublicKey publicKey) {
byte[] nBytes = Base64.getDecoder().decode(publicKey.getN());
byte[] eBytes = Base64.getDecoder().decode(publicKey.getE());
byte[] nBytes = Base64.getUrlDecoder().decode(publicKey.getN());
byte[] eBytes = Base64.getUrlDecoder().decode(publicKey.getE());

BigInteger n = new BigInteger(POSITIVE_SIGN_NUMBER, nBytes);
BigInteger e = new BigInteger(POSITIVE_SIGN_NUMBER, eBytes);
Expand Down

0 comments on commit c5a4ebb

Please sign in to comment.