Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kakao 사용자 정보 받아오는 response 변경 #772

Merged
merged 5 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import static hanglog.global.exception.ExceptionCode.INVALID_AUTHORIZATION_CODE;
import static hanglog.global.exception.ExceptionCode.NOT_SUPPORTED_OAUTH_SERVICE;
import static java.lang.Boolean.TRUE;

import hanglog.global.exception.AuthException;
import hanglog.login.domain.OauthAccessToken;
import hanglog.login.domain.OauthProvider;
import hanglog.login.domain.OauthUserInfo;
import hanglog.login.infrastructure.oauthuserinfo.KakaoUserInfo;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
Expand All @@ -24,6 +27,7 @@ public class KakaoOauthProvider implements OauthProvider {

private static final String PROPERTIES_PATH = "${oauth2.provider.kakao.";
private static final String PROVIDER_NAME = "kakao";
private static final String SECURE_RESOURCE = "secure_resource";

protected final String clientId;
protected final String clientSecret;
Expand Down Expand Up @@ -57,11 +61,15 @@ public OauthUserInfo getUserInfo(final String code) {
headers.setBearerAuth(accessToken);
final HttpEntity<MultiValueMap<String, String>> userInfoRequestEntity = new HttpEntity<>(headers);

final Map<String, Boolean> queryParam = new HashMap<>();
queryParam.put(SECURE_RESOURCE, TRUE);

final ResponseEntity<KakaoUserInfo> response = restTemplate.exchange(
userUri,
HttpMethod.GET,
userInfoRequestEntity,
KakaoUserInfo.class
KakaoUserInfo.class,
queryParam
);

if (response.getStatusCode().is2xxSuccessful()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class KakaoUserInfo implements OauthUserInfo {

@JsonProperty("id")
private String socialLoginId;
@JsonProperty("properties")
private Properties properties;
@JsonProperty("kakao_account")
private KakaoAccount kakaoAccount;

@Override
public String getSocialLoginId() {
Expand All @@ -23,20 +23,28 @@ public String getSocialLoginId() {

@Override
public String getNickname() {
return properties.name;
return kakaoAccount.kakaoProfile.nickname;
}

@Override
public String getImageUrl() {
return properties.image;
return kakaoAccount.kakaoProfile.image;
}

@NoArgsConstructor(access = PRIVATE)
private static class Properties {
private static class KakaoAccount {

@JsonProperty("profile")
private KakaoProfile kakaoProfile;
}

@NoArgsConstructor(access = PRIVATE)
private static class KakaoProfile {

@JsonProperty("nickname")
private String name;
@JsonProperty("profile_image")
private String nickname;

@JsonProperty("profile_image_url")
private String image;
}
}