반응형
1. 다음 종속성을 pom.xml 파일에 추가합니다
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-facebook</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-social-facebook</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
2. application.properties 파일에 Facebook App ID 및 App Secret을 추가합니다
spring.social.facebook.app-id=YOUR_APP_ID
spring.social.facebook.app-secret=YOUR_APP_SECRET
3. Facebook Connect 컨트롤러 구현
import org.springframework.social.connect.ConnectionFactoryLocator;
import org.springframework.social.connect.ConnectionRepository;
import org.springframework.social.connect.web.ConnectController;
import org.springframework.stereotype.Controller;
@Controller
public class FacebookConnectController extends ConnectController {
public FacebookConnectController(ConnectionFactoryLocator connectionFactoryLocator,
ConnectionRepository connectionRepository) {
super(connectionFactoryLocator, connectionRepository);
}
}
4. Facebook 로그인 만들기
<a href="<c:url value='/connect/facebook' />">Login with Facebook</a>
5. 콜백 엔드포인트 구현
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.web.ProviderSignInUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
@Controller
public class FacebookCallbackController {
private final ProviderSignInUtils providerSignInUtils;
public FacebookCallbackController(ProviderSignInUtils providerSignInUtils) {
this.providerSignInUtils = providerSignInUtils;
}
@RequestMapping(value = "/facebook")
public String facebook(HttpServletRequest request) {
Connection<?> connection = providerSignInUtils.getConnectionFromSession(request);
// store the user's data in your database
// redirect the user to the appropriate page
return "redirect:/";
}
}
반응형
'Spring Boot' 카테고리의 다른 글
[Springboot] Instagram 사진 올리기 연동 구현(인스타그램 + java) (0) | 2023.02.08 |
---|---|
[Springboot] Instagram 로그인 연동 구현(인스타그램 + java) (0) | 2023.02.08 |
[Springboot] smtp email 보내기 구현 (0) | 2023.02.08 |
[Google API + Springboot] 유튜브 영상올리기 (Google youtube) 구현 소스 (0) | 2023.02.08 |
[Google API + Springboot] 유튜브 영상정보취득 (Google youtube) 구현 소스 (0) | 2023.02.08 |