Skip to content

Commit

Permalink
refactor: accessToken으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
hong-sile committed Jul 26, 2024
1 parent 12b81ff commit 6a8f064
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/main/java/play/pluv/login/application/LoginService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public class LoginService {
private final RegisterUpdater registerUpdater;
private final SocialLoginClientComposite socialLoginClientComposite;

public Long createToken(final MusicStreaming serverType, final String authCode) {
public Long createToken(final MusicStreaming serverType, final String accessToken) {
final OAuthMemberInfo memberInfo = socialLoginClientComposite
.fetchMemberInfo(serverType, authCode);
.fetchMemberInfo(serverType, accessToken);

final Member member = registerReader.findByOAuthMemberInfo(memberInfo)
.orElseGet(() -> registerUpdater.registerNewMember(memberInfo));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package play.pluv.login.application.dto;

public record LoginRequest(String authCode) {
public record LoginRequest(String accessToken) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public BaseResponse<LoginResponse> login(
@PathVariable final String oauth, @RequestBody final LoginRequest loginRequest
) {
final var memberId = loginService
.createToken(MusicStreaming.from(oauth), loginRequest.authCode());
.createToken(MusicStreaming.from(oauth), loginRequest.accessToken());
final var loginResponse = new LoginResponse(jwtProvider.createAccessTokenWith(memberId));
return BaseResponse.ok(loginResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public interface SocialLoginClient {

OAuthMemberInfo fetchMember(final String authCode);
OAuthMemberInfo fetchMember(final String accessToken);

MusicStreaming supportedType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public SocialLoginClientComposite(final Set<SocialLoginClient> socialLoginClient
.collect(toMap(SocialLoginClient::supportedType, identity()));
}

public OAuthMemberInfo fetchMemberInfo(final MusicStreaming serverType, final String authCode) {
return getClient(serverType).fetchMember(authCode);
public OAuthMemberInfo fetchMemberInfo(final MusicStreaming serverType, final String accessToken) {
return getClient(serverType).fetchMember(accessToken);
}

private SocialLoginClient getClient(final MusicStreaming serverType) {
Expand Down
7 changes: 3 additions & 4 deletions src/test/java/play/pluv/api/LoginApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public class LoginApiTest extends ApiTest {

@Test
void 소셜_로그인을_한다() throws Exception {
final LoginRequest loginRequest = new LoginRequest("authCode");
final LoginRequest loginRequest = new LoginRequest("accessToken");

final String requestBody = objectMapper.writeValueAsString(loginRequest);

when(loginService.createToken(SPOTIFY, "authCode")).thenReturn(2L);
when(loginService.createToken(SPOTIFY, "accessToken")).thenReturn(2L);

mockMvc.perform(post("/{oauth}/login", "spotify")
.contentType(APPLICATION_JSON_VALUE)
Expand All @@ -37,8 +37,7 @@ public class LoginApiTest extends ApiTest {
parameterWithName("oauth").description("소셜 로그인 제공자(spotify, apple, youtube)")
),
requestFields(
fieldWithPath("authCode").type(STRING)
.description("소셜 로그인 제공자의 authCode/accessToken")
fieldWithPath("accessToken").type(STRING).description("소셜 로그인 제공자의 accessToken")
),
responseFields(
fieldWithPath("code").type(NUMBER).description("상태 코드"),
Expand Down

0 comments on commit 6a8f064

Please sign in to comment.