-
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.
* [refac] make user info dto * [refac] extract external service from transaction * [refac] handle feign exception * [refac] rename variable * [refac] apply facade pattern * [refac] use final keyword * [refac] use final keyword * [refac] delete unnecessary transaction * [refac] delete unnecessary logout logic in validation * [refac] add transactional annotation * [refac] extract external network from transactional * [refac] rename class * [refac] move package * [docs] update README.md * [refac] delete static method * [fix] validate null name * [refac] separate responsibilities by creating dedicated classes * [refac] delete AuthValidator.java * [refac] summarize parameter * [refac] refactor to use string constants * [refac] move location of validation logic * [refac] divide method * [fix] Revoke refresh token renewal on access token reissuance * [fix] change access modifier to public for apply transactional annotation
- Loading branch information
Showing
26 changed files
with
199 additions
and
128 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
7 changes: 4 additions & 3 deletions
7
src/main/java/org/hankki/hankkiserver/api/auth/controller/request/UserLoginRequest.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,12 +1,13 @@ | ||
package org.hankki.hankkiserver.api.auth.controller.request; | ||
|
||
import jakarta.annotation.Nullable; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import org.hankki.hankkiserver.domain.user.model.Platform; | ||
|
||
public record UserLoginRequest( | ||
@Nullable | ||
String name, | ||
@NotBlank | ||
String platform | ||
@NotNull | ||
Platform platform | ||
) { | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/org/hankki/hankkiserver/api/auth/service/AuthFacade.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,50 @@ | ||
package org.hankki.hankkiserver.api.auth.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.hankki.hankkiserver.api.auth.controller.request.UserLoginRequest; | ||
import org.hankki.hankkiserver.api.auth.service.response.UserInfoResponse; | ||
import org.hankki.hankkiserver.api.auth.service.response.UserLoginResponse; | ||
import org.hankki.hankkiserver.api.auth.service.response.UserReissueResponse; | ||
import org.hankki.hankkiserver.api.user.service.UserFinder; | ||
import org.hankki.hankkiserver.api.user.service.UserInfoFinder; | ||
import org.hankki.hankkiserver.auth.jwt.Token; | ||
import org.hankki.hankkiserver.domain.user.model.User; | ||
import org.hankki.hankkiserver.domain.user.model.UserInfo; | ||
import org.hankki.hankkiserver.external.openfeign.oauth.SocialInfoResponse; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class AuthFacade { | ||
|
||
private final UserFinder userFinder; | ||
private final UserInfoFinder userInfoFinder; | ||
private final ExternalService externalService; | ||
private final AuthService authService; | ||
|
||
public UserLoginResponse login(final String token, final UserLoginRequest request) { | ||
SocialInfoResponse response = externalService.getUserInfo(token, request.platform(), request.name()); | ||
UserInfoResponse userInfoResponse = UserInfoResponse.of(request.platform(), response.serialId(), | ||
response.name(), response.email()); | ||
return authService.saveOrGetUser(userInfoResponse); | ||
} | ||
|
||
public void withdraw(final long userId, final String code) { | ||
User user = userFinder.getUser(userId); | ||
externalService.revoke(user.getPlatform(), code, user.getSerialId()); | ||
authService.deleteUser(user); | ||
} | ||
|
||
@Transactional | ||
public void logout(final long userId) { | ||
UserInfo findUserInfo = userInfoFinder.getUserInfo(userId); | ||
findUserInfo.updateRefreshToken(null); | ||
} | ||
|
||
@Transactional | ||
public UserReissueResponse reissue(final String refreshToken) { | ||
Token issuedTokens = authService.generateAccessToken(refreshToken); | ||
return UserReissueResponse.of(issuedTokens); | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/main/java/org/hankki/hankkiserver/api/auth/service/ExternalService.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,23 @@ | ||
package org.hankki.hankkiserver.api.auth.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.hankki.hankkiserver.domain.user.model.Platform; | ||
import org.hankki.hankkiserver.external.openfeign.oauth.SocialInfoResponse; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ExternalService { | ||
|
||
private final OAuthProviderFactory oAuthProviderFactory; | ||
|
||
protected SocialInfoResponse getUserInfo(final String token, final Platform platform, final String name) { | ||
OAuthProvider oAuthProvider = oAuthProviderFactory.findProvider(platform); | ||
return oAuthProvider.getUserInfo(token, name); | ||
} | ||
|
||
protected void revoke(final Platform platform, final String code, final String serialId) { | ||
OAuthProvider oAuthProvider = oAuthProviderFactory.findProvider(platform); | ||
oAuthProvider.requestRevoke(code, serialId); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/org/hankki/hankkiserver/api/auth/service/response/UserInfoResponse.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,14 @@ | ||
package org.hankki.hankkiserver.api.auth.service.response; | ||
|
||
import org.hankki.hankkiserver.domain.user.model.Platform; | ||
|
||
public record UserInfoResponse( | ||
Platform platform, | ||
String serialId, | ||
String name, | ||
String email | ||
) { | ||
public static UserInfoResponse of(final Platform platform, final String serialId, final String name, final String email) { | ||
return new UserInfoResponse(platform, serialId, name, email); | ||
} | ||
} |
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
Oops, something went wrong.