
#OAuth2
spring.security.oauth2.client.registration.kakao.client-id=[ํด๋ผ์ด์ธํธID]
spring.security.oauth2.client.registration.kakao.client-secret=[ํด๋ผ์ด์ธํธ Secret]
spring.security.oauth2.client.registration.kakao.scope=profile_nickname, account_email
spring.security.oauth2.client.registration.kakao.client-name=Kakao
spring.security.oauth2.client.registration.kakao.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.kakao.redirect-uri=http://localhost:8080/login/oauth2/code/kakao
# provider
spring.security.oauth2.client.registration.kakao.client-authentication-method=client_secret_post
spring.security.oauth2.client.provider.kakao.authorization-uri=https://kauth.kakao.com/oauth/authorize
spring.security.oauth2.client.provider.kakao.token-uri=https://kauth.kakao.com/oauth/token
spring.security.oauth2.client.provider.kakao.user-info-uri=https://kapi.kakao.com/v2/user/me
spring.security.oauth2.client.provider.kakao.user-name-attribute=id
1. KakaoMemberInfo ํด๋์ค (OAuth2MemberInfo ๊ตฌํ)
public class KakaoMemberInfo implements OAuth2MemberInfo {
private Map<String, Object> attributes;
private final Map<String, Object> profileAttributes;
public KakaoMemberInfo(Map<String, Object> attributes) {
this.attributes = (Map<String, Object>) attributes.get("kakao_account");
this.profileAttributes = (Map<String, Object>) this.attributes.get("profile");
}
@Override
public String getEmail() {
return (String) attributes.get("email");
}
@Override
public String getProvider() {
return "kakao";
}
@Override
public String getProviderId() {
return (String) attributes.get("id");
}
@Override
public String getNickName() {
return (String) profileAttributes.get("nickname");
}
}
OAuth2MemberInfo ์ธํฐํ์ด์ค๋ฅผ ๊ตฌํํ์ฌ ์นด์นด์ค๋ก๋ถํฐ ๋ฐ์ ์ฌ์ฉ์ ์ ๋ณด๋ฅผ ๊ฐ์ง๊ณ ์ถ์ถํฉ๋๋ค.KakaoMemberInfo ์์ฑ์์์๋ attributes ๋งต์์ kakao_account ํค๋ฅผ ์ฌ์ฉํ์ฌ Kakao ๊ณ์ ์ ์์ฑ์ ์ ๊ทผํฉ๋๋ค. ๊ทธ๋ฐ ๋ค์ profileAttributes ๋งต์์ profile ํค๋ฅผ ์ฌ์ฉํ์ฌ ํ๋กํ ์ ๋ณด์ ์ ๊ทผํฉ๋๋ค.
getXXXX() : ๋ค์ด๋ฒ๋ก๋ถํฐ ๋ฐ์ ์ฌ์ฉ์ ์ ๋ณด์์ ํค์ ํด๋นํ๋ ๊ฐ์ ์ถ์ถํฉ๋๋ค.getProvider() : ์ ๋ณด๋ฅผ ์ ๊ณตํ๋ ์ ๊ณต์๋ฅผ ๋ฐํํฉ๋๋ค. ์ ๊ณต์๋ naver์
๋๋ค.2. Oauth2MemberService ํด๋์ค(DefaultOAuth2UserService)
else if (platform.equals("kakao")) {
System.out.println("์นด์นด์ค ๋ก๊ทธ์ธ ์์ฒญ");
response = new KakaoMemberInfo((Map) oAuth2User.getAttributes());//์นด์นด์ค์ ์๋ ์ฌ์ฉ์ ์ ๋ณด ์ถ์ถ
}