Skip to main content

Spring Boot and Spring Security OAuth2 tutorial for Authorization through Facebook, Google, LinkedIn and Twitter

Spring Boot oauth2 tutorial for accessing Facebook, Google, LinkedIn and Twitter

In this tutorial we will extend the Spring Boot OAuth2 tutorial, to provide support for Google, Twitter and LinkedIn along with Facebook. The above tutorial implements a Single sign-on with facebook. If you have not gone through the above tutorial, please have a look before proceeding as this tutorial extends the above tutorial for Google, LinkedIn and Twitter

Maven dependencies

Add the following dependencies in your pom.xml

 

Add the right annotations and extend the WebSecurityConfigurerAdapter

 

Override the configure method to allow

  • Filters needed for single sign-on
  • The request to be authenticated for selected URLs like /connect/.
  • Defining the logout URL
  • Defining the CsrfTokenRepository

 

  • Add the request mapping to get Principal(The User logged In)

  • Add the filters needed for each provider

 

  • Define the Beans needs for each provider

 

Updating the Properties file with ClientId and Secret Key

Update the HTML to add Links for LinkedIn, Twitter and Google

 

The Complete Java class will look like this

Run the application on localhost:3000, if you have not changed the server.port properties in the file

Above code can be cloned from here: Github Spring OAUTH2 facebook google authorization

 

Please note that by the time of writing this blog, the twitter and LinkedIn providers were having some issues after authorization. I will fix them as soon as I get some time

Also, I have written a step by step tutorial for authorising user using Spring-social and Spring-security, see link below.

Related Posts

4 thoughts on “Spring Boot and Spring Security OAuth2 tutorial for Authorization through Facebook, Google, LinkedIn and Twitter

Leave a Reply

Your email address will not be published. Required fields are marked *

Bitnami