-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
74 additions
and
102 deletions.
There are no files selected for viewing
2 changes: 0 additions & 2 deletions
2
dateroad-api/src/main/java/org/dateroad/advertisement/dto/response/AdvGetDetailRes.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
1 change: 1 addition & 0 deletions
1
dateroad-api/src/main/java/org/dateroad/advertisement/service/AdvertisementService.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
12 changes: 0 additions & 12 deletions
12
dateroad-api/src/main/java/org/dateroad/auth/jwt/JwtValidator.java
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
dateroad-api/src/main/java/org/dateroad/auth/jwt/TokenType.java
This file was deleted.
Oops, something went wrong.
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
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
117 changes: 55 additions & 62 deletions
117
dateroad-external/src/main/java/org/dateroad/feign/kakao/KakaoPlatformUserIdProvider.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,62 +1,55 @@ | ||
package org.dateroad.feign.kakao; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import feign.FeignException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.dateroad.code.FailureCode; | ||
import org.dateroad.exception.UnauthorizedException; | ||
import org.dateroad.feign.kakao.dto.response.KakaoErrorRes; | ||
import org.dateroad.feign.kakao.dto.response.KakaoAccessTokenInfoRes; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.IOException; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Component | ||
public class KakaoPlatformUserIdProvider { | ||
private final KakaoFeignApi kakaoFeignApi; | ||
private final ObjectMapper objectMapper; | ||
private static final String TOKEN_TYPE = "Bearer "; | ||
|
||
//AuthService에서 호출 : 카카오에서 주는 userId 받아오기 | ||
public String getKakaoPlatformUserId(final String accessToken) { | ||
String kakaoAccessTokenWithTokenType = getAccessTokenWithTokenType(accessToken); | ||
KakaoAccessTokenInfoRes kakaoAccessTokenInfoRes = getKakaoAccessTokenInfo(kakaoAccessTokenWithTokenType); | ||
return String.valueOf(kakaoAccessTokenInfoRes.id()); | ||
} | ||
|
||
private KakaoAccessTokenInfoRes getKakaoAccessTokenInfo(final String token) { | ||
try { | ||
return kakaoFeignApi.getKakaoPlatformUserId(token); | ||
} catch (FeignException e) { | ||
log.error("Kakao feign exception : ", e); | ||
|
||
//kakaoResponseDTO로 변경 | ||
KakaoErrorRes errorResponse = convertToKakaoErrorResponse(e.contentUTF8()); | ||
|
||
//카카오에서 주는 에러 코드가 -1이면 카카오 내부 에러, 나머지는 카카오 액세스 토큰 에러 | ||
if (errorResponse.code() == -1) { | ||
log.error("Kakao feign exception : ", e); | ||
throw new UnauthorizedException(FailureCode.KAKAO_INTERNER_ERROR); | ||
} else { | ||
log.error("feign exception : ", e); | ||
throw new UnauthorizedException(FailureCode.INVALID_KAKAO_TOKEN); | ||
} | ||
} | ||
} | ||
|
||
private String getAccessTokenWithTokenType(String accessToken) { | ||
return TOKEN_TYPE + accessToken; | ||
} | ||
|
||
private KakaoErrorRes convertToKakaoErrorResponse(String responseBody) { | ||
try { | ||
return objectMapper.readValue(responseBody, KakaoErrorRes.class); | ||
} catch (IOException e) { | ||
log.error("Convert To KakaoErrorResponse Error : ", e); | ||
throw new UnauthorizedException(FailureCode.UNAUTHORIZED); | ||
} | ||
} | ||
} | ||
//package org.dateroad.feign.kakao; | ||
// | ||
//import com.fasterxml.jackson.databind.ObjectMapper; | ||
//import feign.FeignException; | ||
//import lombok.RequiredArgsConstructor; | ||
//import lombok.extern.slf4j.Slf4j; | ||
//import org.dateroad.code.FailureCode; | ||
//import org.dateroad.exception.UnauthorizedException; | ||
//import org.dateroad.feign.kakao.dto.response.KakaoErrorRes; | ||
//import org.dateroad.feign.kakao.dto.response.KakaoAccessTokenInfoRes; | ||
//import org.springframework.stereotype.Component; | ||
// | ||
//import java.io.IOException; | ||
// | ||
//@Slf4j | ||
//@RequiredArgsConstructor | ||
//@Component | ||
//public class KakaoPlatformUserIdProvider { | ||
// private final KakaoFeignApi kakaoFeignApi; | ||
// private final ObjectMapper objectMapper; | ||
// private static final String TOKEN_TYPE = "Bearer "; | ||
// | ||
// private KakaoAccessTokenInfoRes getKakaoAccessTokenInfo(final String token) { | ||
// try { | ||
// return kakaoFeignApi.getKakaoPlatformUserId(token); | ||
// } catch (FeignException e) { | ||
// log.error("Kakao feign exception : ", e); | ||
// | ||
// //kakaoResponseDTO로 변경 | ||
// KakaoErrorRes errorResponse = convertToKakaoErrorResponse(e.contentUTF8()); | ||
// | ||
// //카카오에서 주는 에러 코드가 -1이면 카카오 내부 에러, 나머지는 카카오 액세스 토큰 에러 | ||
// if (errorResponse.code() == -1) { | ||
// log.error("Kakao feign exception : ", e); | ||
// throw new UnauthorizedException(FailureCode.KAKAO_INTERNER_ERROR); | ||
// } else { | ||
// log.error("feign exception : ", e); | ||
// throw new UnauthorizedException(FailureCode.INVALID_KAKAO_TOKEN); | ||
// } | ||
// } | ||
// } | ||
// | ||
// private String getAccessTokenWithTokenType(String accessToken) { | ||
// return TOKEN_TYPE + accessToken; | ||
// } | ||
// | ||
// private KakaoErrorRes convertToKakaoErrorResponse(String responseBody) { | ||
// try { | ||
// return objectMapper.readValue(responseBody, KakaoErrorRes.class); | ||
// } catch (IOException e) { | ||
// log.error("Convert To KakaoErrorResponse Error : ", e); | ||
// throw new UnauthorizedException(FailureCode.UNAUTHORIZED); | ||
// } | ||
// } | ||
//} |