Skip to content

silverlight86/tut-spring-boot-oauth2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project is a sample app showing how to do various things with OAuth2 and Spring Boot, starting with a simple, single-provider single-sign on, and working up to a self-hosted OAuth2 Authorization Server with a choice of social authentication providers (Facebook or Github). The samples are all single-page apps using Spring Boot and Spring OAuth on the back end. They also all use AngularJS on the front end, but the changes needed to convert to a different JavaScript framework or to use server side rendering would be minimal.

There are several samples building on each other adding new features:

  • simple: a very basic static app with just a home page and unconditional login through via Spring Boot’s @EnableOAuth2Sso (if you visit the home page you will be automatically redirected to Facebook).

  • click: adds an explicit link that the user has to click to login.

  • logout: adds a logout link as well for authenticated users.

  • manual: shows how the @EnableOAuth2Sso works by unpicking it and configuring all its pieces manually.

  • gitub: adds a second login provider in Github, so the user can choose on the home page which one to use.

  • auth-server: turns the app into a fully-fledged OAuth2 Authorization Server, able to issue its own tokens, but still using the external OAuth2 providers for authentication.

Each of them can be imported into an IDE and there is a main class SocialApplication that you can run there to start the apps. They all come up with a home page on http://localhost:8080 (and all require that you have at least a Facebook account if you want to log in and see the content). You can also run all the apps on the command line using mvn spring-boot:run or by building the jar file and running it with mvn package and java -jar …​. There is no need to install Maven if you use the wrapper at the top level, e.g.

$ cd simple $ ../mvnw package $ java -jar target/*.jar
Note
The apps all work on localhost:8080 because they use OAuth2 clients registered with Facebook and Github for that address. To run them on a different host or port, you need to register your own apps and put the credentials in the config files. There is no danger of leaking your Facebook or Github credentials beyond localhost if you use the default values, but be careful what you expose on the internet, and don’t put your own app registrations in public source control.

About

Spring Boot and OAuth2:: A tutorial on "social" login and single sign on with Facebook and Github

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 68.2%
  • HTML 30.5%
  • Ruby 1.3%