-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from TEAM-SAMSION/PET-300
- Loading branch information
Showing
68 changed files
with
545 additions
and
442 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
...ation/src/main/java/com/pawith/authapplication/handler/UnusedTokenExpireEventHandler.java
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
...-Application/src/main/java/com/pawith/authapplication/service/JWTExtractEmailUseCase.java
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
...cation/src/main/java/com/pawith/authapplication/service/JWTExtractUserDetailsUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.pawith.authapplication.service; | ||
|
||
public interface JWTExtractUserDetailsUseCase<T> { | ||
T extract(final String token); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 0 additions & 57 deletions
57
...th-Application/src/main/java/com/pawith/authapplication/service/command/OAuthInvoker.java
This file was deleted.
Oops, something went wrong.
9 changes: 5 additions & 4 deletions
9
...vice/impl/JWTExtractEmailUseCaseImpl.java → ...mpl/JWTExtractUserDetailsUseCaseImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
package com.pawith.authapplication.service.impl; | ||
|
||
import com.pawith.authapplication.service.JWTExtractEmailUseCase; | ||
import com.pawith.authapplication.service.JWTExtractUserDetailsUseCase; | ||
import com.pawith.authdomain.jwt.JWTProvider; | ||
import com.pawith.authdomain.jwt.TokenType; | ||
import com.pawith.commonmodule.annotation.ApplicationService; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@ApplicationService | ||
@RequiredArgsConstructor | ||
public class JWTExtractEmailUseCaseImpl implements JWTExtractEmailUseCase { | ||
public class JWTExtractUserDetailsUseCaseImpl implements JWTExtractUserDetailsUseCase<Long> { | ||
private final JWTProvider jwtProvider; | ||
|
||
@Override | ||
public String extractEmail(final String token){ | ||
return jwtProvider.extractEmailFromToken(token, TokenType.ACCESS_TOKEN); | ||
public Long extract(final String token) { | ||
return jwtProvider.extractUserClaimsFromToken(token, TokenType.ACCESS_TOKEN) | ||
.getUserId(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../service/command/handler/AuthHandler.java → ...pplication/service/oauth/AuthHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/OAuthInvoker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.pawith.authapplication.service.oauth; | ||
|
||
import com.pawith.authapplication.consts.AuthConsts; | ||
import com.pawith.authapplication.dto.OAuthRequest; | ||
import com.pawith.authapplication.dto.OAuthResponse; | ||
import com.pawith.authapplication.dto.OAuthUserInfo; | ||
import com.pawith.authapplication.exception.AuthException; | ||
import com.pawith.authdomain.exception.AuthError; | ||
import com.pawith.authdomain.jwt.JWTProvider; | ||
import com.pawith.authdomain.jwt.PrivateClaims; | ||
import com.pawith.authdomain.jwt.TokenType; | ||
import com.pawith.authdomain.service.TokenSaveService; | ||
import com.pawith.userdomain.service.UserQueryService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.support.TransactionTemplate; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class OAuthInvoker { | ||
private final List<AuthHandler> authHandlerList; | ||
private final JWTProvider jwtProvider; | ||
private final TokenSaveService tokenSaveService; | ||
private final ApplicationEventPublisher publisher; | ||
// private final OAuthModifyingService oAuthModifyingService; | ||
// private final OAuthQueryService oAuthQueryService; | ||
// private final OAuthSaveService oAuthSaveService; | ||
private final UserQueryService userQueryService; | ||
private final TransactionTemplate transactionTemplate; | ||
|
||
public OAuthResponse execute(OAuthRequest request){ | ||
// oauth 정보가 없으면 생성 | ||
// 생성하고 조회, email이 없어도 될지, user에서 email, provider는 제거 | ||
// oauth에는 userId를 넣는다? | ||
// 있으면 그대로 진행 | ||
final OAuthUserInfo oAuthUserInfo = attemptLogin(request); | ||
saveOAuthAndPublishEvent(request, oAuthUserInfo); | ||
return generateServerAuthenticationTokens(PrivateClaims.UserClaims.of(userQueryService.findByEmail(oAuthUserInfo.getEmail()).getId())); | ||
} | ||
|
||
private void saveOAuthAndPublishEvent(OAuthRequest request, OAuthUserInfo oAuthUserInfo) { | ||
transactionTemplate.execute(status -> { | ||
/** | ||
* OAuth 정보가 이미 존재하면, OAuth 정보를 조회하고 이메일 정보가 변경되면 UserEmailUpdateEvent를 발행한다. | ||
* OAuth 존재하지 않으면 새로운 OAuth 정보를 생성한다. 이후에 UserSignUpEvent를 발행하여 사용자의 가입을 알린다. | ||
*/ | ||
// if(oAuthQueryService.isOAuthExist(oAuthUserInfo.getSub())){ | ||
// final OAuth oAuth = oAuthQueryService.findBySub(oAuthUserInfo.getSub()); | ||
// oAuthModifyingService. | ||
// } else{ | ||
// publisher.publishEvent(UserSignUpEvent.of(oAuthUserInfo.getUsername(), oAuthUserInfo.getEmail(), request.getProvider())); | ||
// oAuthSaveService.saveOAuthUser( | ||
// OAuth.of( | ||
// request.getProvider(), | ||
// request.getRefreshToken(), | ||
// oAuthUserInfo.getEmail(), | ||
// oAuthUserInfo.getSub(), | ||
// userQueryService.findByEmail(oAuthUserInfo.getEmail()).getId() | ||
// ) | ||
// ); | ||
// } | ||
// return null; | ||
return null; | ||
}); | ||
} | ||
|
||
private OAuthUserInfo attemptLogin(OAuthRequest request) { | ||
for (AuthHandler authHandler : authHandlerList) { | ||
if (authHandler.isAccessible(request)) { | ||
return authHandler.handle(request); | ||
} | ||
} | ||
throw new AuthException(AuthError.OAUTH_FAIL); | ||
} | ||
|
||
private OAuthResponse generateServerAuthenticationTokens(PrivateClaims.UserClaims userClaims) { | ||
final JWTProvider.Token token = jwtProvider.generateToken(userClaims); | ||
tokenSaveService.saveToken(token.refreshToken(), TokenType.REFRESH_TOKEN, userClaims.getUserId()); | ||
final String accessToken = AuthConsts.AUTHENTICATION_TYPE_PREFIX + token.accessToken(); | ||
final String refreshToken = AuthConsts.AUTHENTICATION_TYPE_PREFIX + token.refreshToken(); | ||
return OAuthResponse.builder() | ||
.accessToken(accessToken) | ||
.refreshToken(refreshToken) | ||
.build(); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...rvice/command/feign/AppleFeignClient.java → ...service/oauth/feign/AppleFeignClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...command/feign/GoogleOAuthFeignClient.java → ...e/oauth/feign/GoogleOAuthFeignClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
.../command/feign/KakaoOAuthFeignClient.java → ...ce/oauth/feign/KakaoOAuthFeignClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.../command/feign/NaverOAuthFeignClient.java → ...ce/oauth/feign/NaverOAuthFeignClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ommand/feign/response/GoogleUserInfo.java → .../oauth/feign/response/GoogleUserInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...command/feign/response/KakaoUserInfo.java → ...e/oauth/feign/response/KakaoUserInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.