Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] apple login bug #151

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading