저는 이 곳에서 학습을 위한 목적으로 우선 구현을 사용자 인증 정보를 세션에 저장하는 방식을 사용하고 있습니다. 이 방식은 서버에서 클라이언트의 상태를 유지해야 하므로, 서버의 부하 증가 등 여러 문제를 야기할 수 있기 때문에 추후 토큰 기반의 인증 방식을 사용할 것을 권장드립니다!


spring.security.oauth2.client.registration.naver.client-id={클라이언트-id}
spring.security.oauth2.client.registration.naver.client-secret={클라이언트-비밀번호}
spring.security.oauth2.client.registration.naver.redirect-uri=http://로컬주소/본인 설정 Callback URL
spring.security.oauth2.client.registration.naver.scope=name,profile,email
spring.security.oauth2.client.registration.naver.authorization-grant-type=authorization_code
spring.security.oauth2.client.provider.naver.authorization-uri=https://nid.naver.com/oauth2.0/authorize
spring.security.oauth2.client.provider.naver.token-uri:https://nid.naver.com/oauth2.0/token
spring.security.oauth2.client.provider.naver.user-info-uri:https://openapi.naver.com/v1/nid/me
spring.security.oauth2.client.provider.naver.user-name-attribute: response
public static OAuthAttributes of(String registrationId, String userNameAttributeName, Map<String, Object> attributes) {
if ("naver".equals(registrationId)) {
return ofNaver(registrationId, userNameAttributeName, attributes);
}
return ofGoogle(registrationId, userNameAttributeName, attributes);
}
private static OAuthAttributes ofNaver(String registrationId, String userNameAttributeName, Map<String, Object> attributes) {
Map<String, Object> response = (Map<String, Object>) attributes.get("response");
return OAuthAttributes.builder()
.name((String) response.get("name"))
.email((String) response.get("email"))
.picture((String) response.get("profile_image"))
.attributes(attributes)
.provider(registrationId)
.providerId((String) response.get("id"))
.nameAttributeKey(userNameAttributeName)
.build();
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<a href="/oauth2/authorization/google">google login</a><br>
<a href="/oauth2/authorization/naver">naver login</a>
</body>
</html>



출처 : https://developers.kakao.com/docs/latest/ko/kakaologin/rest-api




활성화 설정을 활성화해주고 Redirect URI를 설정해줍니다!

비즈 앱 전환 신청

카카오 비즈니스 통합 서비스 약관 동의하기 후 비즈앱 전환

제품 설정 -> 동의 항목 -> 동의 항목 설정

Client-Secret 생성

spring.security.oauth2.client.registration.kakao.client-id={클라이언트 ID(REST API 키)}
spring.security.oauth2.client.registration.kakao.client-secret={클라이언트 비밀번호}
spring.security.oauth2.client.registration.kakao.scope= account_email, profile_nickname
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
spring.security.oauth2.client.registration.kakao.client-name=Kakao
spring.security.oauth2.client.registration.kakao.client-authentication-method=none
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
public static OAuthAttributes of(String registrationId, String userNameAttributeName, Map<String, Object> attributes) {
if ("naver".equals(registrationId)) {
return ofNaver(registrationId, userNameAttributeName, attributes);
} else if ("kakao".equals(registrationId)) {
return ofKakao(registrationId, userNameAttributeName, attributes);
}
return ofGoogle(registrationId, userNameAttributeName, attributes);
}
private static OAuthAttributes ofKakao(String registrationId, String userNameAttributeName, Map<String, Object> attributes) {
Map<String, Object> kakaoAccount = (Map<String, Object>) attributes.get("kakao_account");
Map<String, Object> profile = (Map<String, Object>) kakaoAccount.get("profile");
return OAuthAttributes.builder()
.name((String) profile.get("nickname"))
.email((String) kakaoAccount.get("email"))
.picture((String) profile.get("profile_image_url"))
.attributes(attributes)
.provider(registrationId)
.providerId(String.valueOf(attributes.get("id")))
.nameAttributeKey(userNameAttributeName)
.build();
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<a href="/oauth2/authorization/google">google login</a><br>
<a href="/oauth2/authorization/naver">naver login</a><br>
<a href="/oauth2/authorization/kakao">kakao login</a>
</body>
</html>

