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
@EnableOAuth2Ssoworks 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.
-
custom-error: adds an error message for unauthenticated users, and a custom authentication based on Github API.
|
Note
|
The changes needed to migrate from one app to the next one in the feature ladder can be tracked in the source (the source code is in Github). The first 6 changes in the repository are transforming a single app so you can easily see the differences. Any further differences you might see between the app in those early commits and the final state you see in the guide are cosmetic. |
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 target/*.jar (per the
Spring
Boot docs and other
available
documentation). 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.
|