내 애플리케이션 으로 이동
애플리케이션 추가하기 버튼 클릭하여 어플리케이션 추가
Rest API 키 를 알아두자client_id 로 쓰임!
카카오 로그인 페이지에 들어가서 설정ON 으로 변경
Redirect URL 설정Local 환경에서 테스트 해볼것이기 때문에 아래와 같이 설정http://localhost:8080/login/oauth2/code/kakao
→ 나중에는 domain 이름으로 바꿔주기

카카오 로그인 → 보안Client Secret 코드 생성 버튼 클릭client_secret 으로 사용된다!
카카오 비즈니스 신청을 통해 이메일을 받아올 수 있음
oauth2-client 의존성 추가하기build.gradle
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
application.yaml 작성하기application.yaml 파일에 인증을 위한 값 작성하기spring:
security:
oauth2:
client:
registration:
kakao:
client-id: cliend-id 작성
client-secret: client-secret 작성
client-authentication-method: client_secret_post
redirect-uri: "{baseUrl}/login/oauth2/code/kakao"
authorization-grant-type: authorization_code
client-name: kakao
scope:
- profile_nickname
- profile_image
- account_email
provider:
kakao:
authorization-uri: https://kauth.kakao.com/oauth/authorize
token-uri: https://kauth.kakao.com/oauth/token
user-info-uri: https://kapi.kakao.com/v2/user/me
user-name-attribute: id
SecurityConfig.java 작성하기@Configuration
@RequiredArgsConstructor
public class SecurityConfig {
private final KakaoAuthenticationSuccessHandler successHandler;
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests((requests) -> requests
// "/admin/**" 경로에 대해서만 인증 필요 [추후 변경]
.requestMatchers("/admin/**").authenticated()
// 그 외의 경로는 인증 없이 접근 가능
.anyRequest().permitAll()
)
.oauth2Login((oauth2) -> oauth2
.successHandler(successHandler) // 성공 핸들러 등록
);
return http.build();
}
}