[스프링부트-jpa-sns] 페이스북 로그인
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
application.yml
oauth2:
client:
registration:
facebook:
client-id: 102492681
client-secret: 4fc170c2437
scope:
- public_profile
- email
OAuth2DetailsService 클래스
@Service
public class OAuth2DetailsService extends DefaultOAuth2UserService{
}
SecurityConfig에 추가
private final OAuth2DetailsService oAuth2DetailsService;
.oauth2Login() //form로그인도 하는데, oauth2Login도 할거임
.userInfoEndpoint() //최종응답을 회원정보로 받는다.
.userService(oAuth2DetailsService);
signin.jsp
<button onclick="javascript:location.href='/oauth2/authorization/facebook'">
https://spring.io/guides/tutorials/spring-boot-oauth2/
- open auth: 인증오픈
- 앱리스트 확인
- 페이스북이 인증코드 돌려줌
- access token으로 유저의 정보에 접근할 수 있다.
- scope는 public_profile, email
- 회원가입-> 로그인
- OAuth2 라이브러리가 해줌 따라서 회원정보 받아서 회원가입-> 로그인시키면 됨
https://easyupclass.e-itwill.com/course/course_view.jsp?id=27&cid=28