스프링 OAuth2 클라이언트 세션 11 : 커스텀 로그인 페이지
·
Spring Security/OAuth2
기본 OAuth2 로그인 페이지GET : /login커스텀 로그인 페이지 설정login.mustachelogin pagenaver logingoogle login controller > LoginController@Controllerpublic class LoginController { @GetMapping("/login") public String loginPage() { return "login"; }}SecurityConfig OAuth2 커스텀 로그인 페이지 등록config > SecurityConfighttp .oauth2Login((oauth2) -> oauth2 .loginPage("/login") .userInfoEndpoint..
스프링 OAuth2 클라이언트 세션 : 로그인 및 DB 저장 테스트
·
Spring Security/OAuth2
테스트# JPA 및 Hibernate 설정spring.jpa.hibernate.ddl-auto=createspring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImplddl-auto 설정을 create로 바꾼 후 프로젝트 실행UserEntity 테이블이 만들어짐.로그인 페이지로 이동.네이버로 로그인 구글 로그인해당 두 서비스로 로그인이 잘 됐고, UserEntity에 데이터가 잘 들어왔다.
스프링 OAuth2 클라이언트 세션 10 : 유저 정보 DB 저장
·
Spring Security/OAuth2
DB 관련 의존성 주석 해제build.gradledependencies { //implementation 'org.springframework.boot:spring-boot-starter-data-jpa' //runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'}DB 연결 변수 작성application.properties# DB 설정spring.datasource.driver-class-name=org.mariadb.jdbc.Driverspring.datasource.url=jdbc:mariadb://localhost:3306/oauth2spring.datasource.username=rootspring.datasource.password=!123456sp..
스프링 OAuth2 클라이언트 세션 9 : 응답 데이터로 로그인 완료
·
Spring Security/OAuth2
CustomOAuth2UserService 이어서 작성@Servicepublic class CustomOAuth2UserService extends DefaultOAuth2UserService { //DefaultOAuth2UserService OAuth2UserService의 구현체 @Override public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException { OAuth2User oAuth2User = super.loadUser(userRequest); System.out.println(oAuth2User.getAttributes()); ..
스프링 OAuth2 클라이언트 세션 8 : OAuth2UserService 응답 받기
·
Spring Security/OAuth2
OAuth2UserServiceCustomOAuth2UserService@Servicepublic class CustomOAuth2UserService extends DefaultOAuth2UserService { //DefaultOAuth2UserService OAuth2UserService의 구현체 @Override public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException { OAuth2User oAuth2User = super.loadUser(userRequest); System.out.println(oAuth2User.getAttributes()..
스프링 OAuth2 클라이언트 세션 7 : 구글 소셜 로그인 신청
·
Spring Security/OAuth2
구글 GCP(aws와 같이 구글에서 제공하는 클라우드 서비스)https://cloud.google.com/free/?utm_source=google&utm_medium=cpc&utm_campaign=japac-KR-all-en-dr-BKWS-all-core-trial-EXA-dr-1605216&utm_content=text-ad-none-none-DEV_c-CRE_668690472449-ADGP_Hybrid+ https://cloud.google.com/free/?utm_campaign=japac-KR-all-en-dr-BKWS-all-core-trial-EXA-dr-1605216&utm_content=text-ad-none-none-DEV_c-CRE_668690472449-ADGP_Hybrid+&utm..
스프링 OAuth2 클라이언트 세션 6 : 네이버 소셜 로그인 신청
·
Spring Security/OAuth2
네이버 로그인 API 공식 문서https://developers.naver.com/products/login/api/api.md 네이버 로그인 - INTRO환영합니다 네이버 로그인의 올바른 적용방법을 알아볼까요? 네이버 로그인을 통해 신규 회원을 늘리고, 기존 회원은 간편하게 로그인하게 하려면 제대로 적용하는 것이 중요합니다! 이에 올바developers.naver.com네이버 로그인 API 신청네이버 개발자센터 -> 네이버 로그인 APIClientID와 Client Secret를 스프링 부트 application.properties OAuth2 변수에 설정하면 된다.변수 설정application.perperties#registrationspring.security.oauth2.client.registr..
스프링 OAuth2 클라이언트 세션 5 : SecurityConfig 등록
·
Spring Security/OAuth2
SecurityConfigconfig > SecurityConfig@Configuration@EnableWebSecuritypublic class SecurityConfig { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http .csrf((csrf) -> csrf.disable()); http .formLogin((login) -> login.disable()); http .httpBasic((basic) -> basic.disable()); http ..
스프링 OAuth2 클라이언트 세션 4 : OAuth2 변수 역할
·
Spring Security/OAuth2
OAuth2 소셜 로그인을 위한 변수 설정위의 각각의 로직이 동작을 하기 위해서는 서비스별로 특정 값이 필요하기 때문에 변수 설정이 필요하다. application.properties#registrationspring.security.oauth2.client.registration.서비스명.client-name=서비스명spring.security.oauth2.client.registration.서비스명.client-id=서비스에서 발급 받은 아이디spring.security.oauth2.client.registration.서비스명.client-secret=서비스에서 발급 받은 비밀번호spring.security.oauth2.client.registration.서비스명.redirect-uri=서비스에 등록..
스프링 OAuth2 클라이언트 세션 3 : 동작 원리
·
Spring Security/OAuth2
동작 모식도 : OAuth2 코드 방식각각의 필터가 동작하는 주소 (관습)OAuth2AuthorizationRequestRedirectFilter/oauth2/authorization/서비스명/oauth2/authorization/naver/oauth2/authorization/google OAuth2LoginAuthenticationFilter : 외부 인증 서버에 설정할 redirect_uri/login/oauth2/code/서비스명/login/oauth2/code/naver/login/oauth2/code/googleOAuth2 인증 및 동작을 위한 변수들변수 설정만 진행하면 OAuth2AuthorizationRequestRedirectFilter -> OAuth2LoginAuthentication..