Skip to content

Commit

Permalink
πŸš€ :: Api-v0.0.2-3
Browse files Browse the repository at this point in the history
πŸš€ :: Api-v0.0.2-3
  • Loading branch information
ImNM authored Jan 11, 2023
2 parents f47338f + 5ca479e commit f01ef86
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import band.gosrock.api.auth.model.dto.request.RegisterRequest;
import band.gosrock.api.auth.model.dto.response.AvailableRegisterResponse;
import band.gosrock.api.auth.model.dto.response.OauthLoginLinkResponse;
import band.gosrock.api.auth.model.dto.response.OauthTokenResponse;
import band.gosrock.api.auth.model.dto.response.OauthUserInfoResponse;
import band.gosrock.api.auth.model.dto.response.TokenAndUserResponse;
import band.gosrock.api.auth.service.LoginUseCase;
Expand All @@ -13,7 +14,6 @@
import band.gosrock.api.auth.service.RegisterUseCase;
import band.gosrock.api.auth.service.WithDrawUseCase;
import band.gosrock.common.annotation.DevelopOnlyApi;
import band.gosrock.infrastructure.outer.api.oauth.dto.OauthTokenResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -64,8 +64,10 @@ public OauthLoginLinkResponse getKakaoOauthLink(
@Operation(summary = "code μš”μ²­λ°›λŠ” ν•Έλ“€λŸ¬ ν΄λΌμ΄μ–ΈνŠΈκ°€ λͺ°λΌλ„λ©λ‹ˆλ‹€.", deprecated = true)
@Tag(name = "카카였 oauth")
@GetMapping("/oauth/kakao")
public OauthTokenResponse getCredentialFromKaKao(@RequestParam("code") String code) {
return registerUseCase.getCredentialFromKaKao(code);
public OauthTokenResponse getCredentialFromKaKao(
@RequestParam("code") String code,
@RequestHeader(value = "referer", required = false) String referer) {
return registerUseCase.getCredentialFromKaKao(code, referer);
}

@Operation(summary = "개발용 νšŒμ›κ°€μž…μž…λ‹ˆλ‹€ ν΄λΌμ΄μ–ΈνŠΈκ°€ λͺ°λΌλ„ λ©λ‹ˆλ‹€.", deprecated = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package band.gosrock.api.auth.model.dto.response;


import band.gosrock.infrastructure.outer.api.oauth.dto.KakaoTokenResponse;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class OauthTokenResponse {
private String accessToken;
private String refreshToken;
private String idToken;

public static OauthTokenResponse from(KakaoTokenResponse kakaoTokenResponse) {
return OauthTokenResponse.builder()
.idToken(kakaoTokenResponse.getIdToken())
.refreshToken(kakaoTokenResponse.getRefreshToken())
.accessToken(kakaoTokenResponse.getAccessToken())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import band.gosrock.api.auth.model.dto.request.RegisterRequest;
import band.gosrock.api.auth.model.dto.response.AvailableRegisterResponse;
import band.gosrock.api.auth.model.dto.response.OauthLoginLinkResponse;
import band.gosrock.api.auth.model.dto.response.OauthTokenResponse;
import band.gosrock.api.auth.model.dto.response.TokenAndUserResponse;
import band.gosrock.api.auth.service.helper.KakaoOauthHelper;
import band.gosrock.api.auth.service.helper.TokenGenerateHelper;
Expand All @@ -13,7 +14,6 @@
import band.gosrock.domain.domains.user.domain.Profile;
import band.gosrock.domain.domains.user.domain.User;
import band.gosrock.domain.domains.user.service.UserDomainService;
import band.gosrock.infrastructure.outer.api.oauth.dto.OauthTokenResponse;
import lombok.RequiredArgsConstructor;

@UseCase
Expand All @@ -39,7 +39,7 @@ public OauthLoginLinkResponse getKaKaoOauthLink(String referer) {
* @return
*/
public TokenAndUserResponse upsertKakaoOauthUser(String code) {
String oauthAccessToken = kakaoOauthHelper.getOauthToken(code).getAccessToken();
String oauthAccessToken = kakaoOauthHelper.getOauthTokenTest(code).getAccessToken();
KakaoUserInfoDto oauthUserInfo = kakaoOauthHelper.getUserInfo(oauthAccessToken);

Profile profile = oauthUserInfo.toProfile();
Expand All @@ -62,7 +62,13 @@ public TokenAndUserResponse registerUserByOCIDToken(
return tokenGenerateHelper.execute(user);
}

public OauthTokenResponse getCredentialFromKaKao(String code) {
return kakaoOauthHelper.getOauthToken(code);
public OauthTokenResponse getCredentialFromKaKao(String code, String referer) {

return OauthTokenResponse.from(kakaoOauthHelper.getOauthToken(code, referer));
}

public OauthTokenResponse getCredentialFromKaKaoTest(String code) {

return OauthTokenResponse.from(kakaoOauthHelper.getOauthTokenTest(code));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import band.gosrock.infrastructure.outer.api.oauth.client.KakaoInfoClient;
import band.gosrock.infrastructure.outer.api.oauth.client.KakaoOauthClient;
import band.gosrock.infrastructure.outer.api.oauth.dto.KakaoInformationResponse;
import band.gosrock.infrastructure.outer.api.oauth.dto.KakaoTokenResponse;
import band.gosrock.infrastructure.outer.api.oauth.dto.OIDCPublicKeysResponse;
import band.gosrock.infrastructure.outer.api.oauth.dto.OauthTokenResponse;
import band.gosrock.infrastructure.outer.api.oauth.dto.UnlinkKaKaoTarget;
import lombok.RequiredArgsConstructor;

Expand Down Expand Up @@ -43,7 +43,16 @@ public String getKaKaoOauthLink(String referer) {
referer + "kakao/callback");
}

public OauthTokenResponse getOauthToken(String code) {
public KakaoTokenResponse getOauthToken(String code, String referer) {

return kakaoOauthClient.kakaoAuth(
oauthProperties.getKakaoClientId(),
referer + "kakao/callback",
code,
oauthProperties.getKakaoClientSecret());
}

public KakaoTokenResponse getOauthTokenTest(String code) {

return kakaoOauthClient.kakaoAuth(
oauthProperties.getKakaoClientId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


import band.gosrock.infrastructure.outer.api.oauth.config.FeignOauthConfig;
import band.gosrock.infrastructure.outer.api.oauth.dto.KakaoTokenResponse;
import band.gosrock.infrastructure.outer.api.oauth.dto.OIDCPublicKeysResponse;
import band.gosrock.infrastructure.outer.api.oauth.dto.OauthTokenResponse;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -18,7 +18,7 @@ public interface KakaoOauthClient {

@PostMapping(
"/oauth/token?grant_type=authorization_code&client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&code={CODE}&client_secret={CLIENT_SECRET}")
OauthTokenResponse kakaoAuth(
KakaoTokenResponse kakaoAuth(
@PathVariable("CLIENT_ID") String clientId,
@PathVariable("REDIRECT_URI") String redirectUri,
@PathVariable("CODE") String code,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@Getter
@NoArgsConstructor
@JsonNaming(SnakeCaseStrategy.class)
public class OauthTokenResponse {
public class KakaoTokenResponse {
private String accessToken;
private String refreshToken;
private String idToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ spring:
config:
activate:
on-profile: staging

logging:
level:
band.gosrock.infrastructure.outer.api.* : debug
---
spring:
config:
Expand Down

0 comments on commit f01ef86

Please sign in to comment.