Skip to content

Commit

Permalink
Merge pull request #147 from team-offonoff/auth-joined
Browse files Browse the repository at this point in the history
회원가입이 완료된 소셜 회원은 로그인 요청시에 `access_token` 발급
  • Loading branch information
60jong authored Jan 26, 2024
2 parents a2701a6 + 50594d0 commit 5465a70
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/docs/asciidoc/oauth.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ operation::o-auth-controller-test/oauth_kakao_existing_member_by_id-token[snippe
#### E1. 탈퇴한 회원

operation::o-auth-controller-test/oauth_kakao_deactivated_member_by_id-token[snippets="http-request,http-response"]

#### E2. 정보 미등록 회원

operation::o-auth-controller-test/oauth_kakao_not_completety_joined_member_by_id-token[snippets="http-request,http-response"]
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ private OAuthSignInResponse loginOAuthProfile(OAuthProfile oAuthProfile) {

return new OAuthSignInResponse(false,
response.getMemberId(),
response.getJoinStatus());
response.getJoinStatus(),
response.getAccessToken());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
@Getter
public class OAuthSignInResponse extends OAuthResponse {

public OAuthSignInResponse(Boolean newMember, Long memberId, JoinStatus joinStatus) {
private String accessToken;

public OAuthSignInResponse(Boolean newMember, Long memberId, JoinStatus joinStatus, String accessToken) {
super(newMember, memberId, joinStatus);
this.accessToken = accessToken;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package life.offonoff.ab.web.response.oauth;

import life.offonoff.ab.domain.member.JoinStatus;
import lombok.Getter;

@Getter
public class OAuthSignUpResponse extends OAuthResponse {

public OAuthSignUpResponse(Boolean newMember, Long memberId, JoinStatus joinStatus) {
Expand Down
21 changes: 19 additions & 2 deletions src/test/java/life/offonoff/ab/web/OAuthControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import life.offonoff.ab.application.service.request.oauth.OAuthRequest;
import life.offonoff.ab.config.WebConfig;
import life.offonoff.ab.domain.member.JoinStatus;
import life.offonoff.ab.exception.IllegalJoinStatusException;
import life.offonoff.ab.exception.MemberDeactivatedException;
import life.offonoff.ab.restdocs.RestDocsTest;
import life.offonoff.ab.util.token.JwtProvider;
Expand All @@ -21,6 +22,7 @@
import static life.offonoff.ab.application.service.request.oauth.AuthorizeType.BY_CODE;
import static life.offonoff.ab.application.service.request.oauth.AuthorizeType.BY_IDTOKEN;
import static life.offonoff.ab.domain.member.JoinStatus.AUTH_REGISTERED;
import static life.offonoff.ab.domain.member.JoinStatus.COMPLETE;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.when;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
Expand Down Expand Up @@ -80,7 +82,7 @@ void oauth_kakao_existing_member_by_code() throws Exception {
OAuthRequest request = new OAuthRequest(BY_CODE, "authorize_code", "redirect_uri", null);

when(oAuthService.authorize(any()))
.thenReturn(new OAuthSignInResponse(false, 1L, AUTH_REGISTERED));
.thenReturn(new OAuthSignInResponse(false, 1L, COMPLETE, "access_token"));

mvc.perform(post(OAuthUri.BASE + OAuthUri.KAKAO + OAuthUri.AUTHORIZE)
.contentType(MediaType.APPLICATION_JSON)
Expand Down Expand Up @@ -127,7 +129,7 @@ void oauth_kakao_existing_member_by_idToken() throws Exception {
OAuthRequest request = new OAuthRequest(BY_IDTOKEN, null, null, "id_token");

when(oAuthService.authorize(any()))
.thenReturn(new OAuthSignInResponse(false, 1L, AUTH_REGISTERED));
.thenReturn(new OAuthSignInResponse(false, 1L, COMPLETE, "access_token"));

mvc.perform(post(OAuthUri.BASE + OAuthUri.KAKAO + OAuthUri.AUTHORIZE)
.contentType(MediaType.APPLICATION_JSON)
Expand All @@ -137,6 +139,21 @@ void oauth_kakao_existing_member_by_idToken() throws Exception {
.andDo(print());
}

@Test
void oauth_kakao_not_completety_joined_member_by_idToken() throws Exception {
// given
OAuthRequest request = new OAuthRequest(BY_IDTOKEN, null, null, "id_token");

when(oAuthService.authorize(any()))
.thenThrow(new IllegalJoinStatusException(1L, AUTH_REGISTERED));

mvc.perform(post(OAuthUri.BASE + OAuthUri.KAKAO + OAuthUri.AUTHORIZE)
.contentType(MediaType.APPLICATION_JSON)
.content(new ObjectMapper().writeValueAsString(request)))
.andExpect(status().isBadRequest())
.andDo(print());
}

@Test
void oauth_kakao_deactivated_member_by_idToken() throws Exception {
OAuthRequest request = new OAuthRequest(BY_IDTOKEN, null, null, "id_token");
Expand Down

0 comments on commit 5465a70

Please sign in to comment.