백엔드기술/스프링프레임워크

카카오, Github 소셜 로그인

RevFactory 2021. 1. 19. 00:04

build.gradle

plugins {
	id 'org.springframework.boot' version '2.4.2'
	id 'io.spring.dependency-management' version '1.0.11.RELEASE'
	id 'java'
}

group = 'kr.revfactory'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
	compileOnly {
		extendsFrom annotationProcessor
	}
}

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-actuator'
	implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
	implementation 'org.springframework.boot:spring-boot-starter-validation'
	implementation 'org.springframework.boot:spring-boot-starter-security'
	implementation 'org.springframework.boot:spring-boot-starter-webflux'
	compileOnly 'org.projectlombok:lombok'
	developmentOnly 'org.springframework.boot:spring-boot-devtools'
	annotationProcessor 'org.projectlombok:lombok'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testImplementation 'io.projectreactor:reactor-test'
	testImplementation 'org.springframework.security:spring-security-test'
}

test {
	useJUnitPlatform()
}

 

WebSecurityConfig

package kr.revfactory.demo;

import org.springframework.boot.autoconfigure.security.reactive.PathRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;

@Configuration
public class WebSecurityConfig {
    @Bean
    public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
        return http
                .authorizeExchange()
                .matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
                .anyExchange()
                .authenticated().and()
                .oauth2Login().and()
                // disable the local user login prompt
                // but OAuth2 login is prompted at /login
                .formLogin().disable()
                .build();
    }
}

 

application.yaml

spring:
  security:
    oauth2:
      client:
        registration:
          github:
            client-id: -
            client-secret: -
            redirect-uri-template: '{baseUrl}/login/oauth2/code/{registrationId}'

          kakao:
            client-id: -
            client-secret: -
            redirectUri: '{baseUrl}/login/oauth2/code/{registrationId}'
            authorization-grant-type: authorization_code
            scope: profile,account_email
            client-name: kakao
            clientAuthenticationMethod: post

        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

 

sundries-in-myidea.tistory.com/89?category=798770

 

Spring Boot Security로 카카오 소셜 로그인 만들기

참고 할점.... 이번 포스팅은 스프링 부트와 AWS로 혼자 구현하는 웹 서비스의 소셜로그인 파트를 참조하여 만들었습니다. 즉, 이 책을 기반으로 코드를 추가한 것이기 때문에 자세한 코드는 책을

sundries-in-myidea.tistory.com

medium.com/@kevin_park/springboot-oauth2-0-reative-client-with-spring-security-a30fe3f7e386

 

SpringBoot OAuth2.0 Reative Client With Spring Security

스프링부트 2.2.5 기반으로 작성 된 OAuth2.0 Reactive Client와 WebFlux Security 구현에 관련 된 글입니다.

medium.com

momentjin.tistory.com/144

 

Spring Boot + Kakao Login API 연동 (기초)

토이프로젝트에 Kakao Login API를 연동한 과정을 튜토리얼 형식으로 작성한 글 입니다. 이 글에서 다뤄지는 모든 예제 코드는 Github에서 확인할 수 있습니다. 개요 Spring Boot와 Spring Security를 활용해

momentjin.tistory.com