Skip to content

Commit 02450dd

Browse files
author
Dave Syer
committed
Start documentation content
1 parent 0efb170 commit 02450dd

File tree

11 files changed

+343
-61
lines changed

11 files changed

+343
-61
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@ target
66
.classpath
77
.project
88
.settings/
9-
node
10-
node_modules
11-
etc
9+
Gemfile.lock

Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source "http://rubygems.org"
2+
3+
gem "guard"
4+
gem "guard-shell"
5+
gem "asciidoctor"

Guardfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require 'asciidoctor'
2+
require 'erb'
3+
4+
options = {:mkdirs => true, :safe => :unsafe, :attributes => ['linkcss', 'allow-uri-read']}
5+
6+
guard 'shell' do
7+
watch('.*.adoc') {|m|
8+
Asciidoctor.render_file('README.adoc', options.merge(:to_dir => 'target/generated-docs'))
9+
}
10+
end

README.adoc

Lines changed: 24 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,24 @@
1-
This project is a sample app showing how to do various things with
2-
https://tools.ietf.org/html/rfc6749[OAuth2] and
3-
http://projects.spring.io/spring-boot/[Spring Boot], starting with a
4-
simple, single-provider single-sign on, and working up to a
5-
self-hosted OAuth2 Authorization Server with a choice of social
6-
authentication providers (https://developers.facebook.com[Facebook] or
7-
https://developer.github.com/[Github]). The samples are all
8-
single-page apps using Spring Boot and Spring OAuth on the back
9-
end. They also all use https://angularjs.org/[AngularJS] on the front
10-
end, but the changes needed to convert to a different JavaScript
11-
framework or to use server side rendering would be minimal.
12-
13-
There are several samples building on each other adding new features:
14-
15-
* **simple**: a very basic static app with just a home page and
16-
unconditional login through via Spring Boot's `@EnableOAuth2Sso` (if
17-
you visit the home page you will be automatically redirected to
18-
Facebook).
19-
20-
* **click**: adds an explicit link that the user has to click to
21-
login.
22-
23-
* **logout**: adds a logout link as well for authenticated users.
24-
25-
* **manual**: shows how the `@EnableOAuth2Sso` works by unpicking it
26-
and configuring all its pieces manually.
27-
28-
* **gitub**: adds a second login provider in Github, so the user can
29-
choose on the home page which one to use.
30-
31-
* **auth-server**: turns the app into a fully-fledged OAuth2
32-
Authorization Server, able to issue its own tokens, but still using
33-
the external OAuth2 providers for authentication.
34-
35-
Each of them can be imported into an IDE and there is a main class
36-
`SocialApplication` that you can run there to start the apps. They all
37-
come up with a home page on http://localhost:8080 (and all require
38-
that you have at least a Facebook account if you want to log in and
39-
see the content). You can also run all the apps on the command line
40-
using `mvn spring-boot:run` or by building the jar file and running it
41-
with `mvn package` and `java -jar ...`. There is no need to install
42-
Maven if you use the https://github.com/takari/maven-wrapper[wrapper]
43-
at the top level, e.g.
44-
45-
```
46-
$ cd simple
47-
$ ../mvnw package
48-
$ java -jar target/*.jar
49-
```
50-
51-
NOTE: The apps all work on `localhost:8080` because they use OAuth2
52-
clients registered with Facebook and Github for that address. To run
53-
them on a different host or port, you need to register your own apps
54-
and put the credentials in the config files. There is no danger of
55-
leaking your Facebook or Github credentials beyond localhost if you
56-
use the default values, but be careful what you expose on the
57-
internet, and don't put your own app registrations in public source
58-
control.
1+
---
2+
tags: [security,angular,rest,oauth]
3+
projects: [spring-security,spring-security-oauth,spring-boot]
4+
---
5+
:toc: left
6+
:icons: font
7+
:source-highlighter: prettify
8+
:image-width: 500
9+
:doctype: book
10+
:star: {asterisk}
11+
:all: {asterisk}{asterisk}
12+
13+
= Social Login with Spring Boot and OAuth2
14+
15+
include::overview.adoc[]
16+
17+
include::simple/README.adoc[leveloffset=+1]
18+
include::click/README.adoc[leveloffset=+1]
19+
include::logout/README.adoc[leveloffset=+1]
20+
include::manual/README.adoc[leveloffset=+1]
21+
include::github/README.adoc[leveloffset=+1]
22+
include::auth-server/README.adoc[leveloffset=+1]
23+
24+
include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/footer.adoc[]

auth-server/README.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[[_social_login_authserver]]
2+
= Hosting an Authorization Server
3+
4+
In this section we modify the <<_social_login_github,github>> app we built by making the app into a fully-fledged OAuth2 Authorization Server, still using Facebook and Github for authentication, but able to create its own access tokens. These tokens could then be used to secure back end resources, or to do SSO with other applications that we happen to need to secure the same way.

click/README.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[[_social_login_click]]
2+
= Add a Welcome Page
3+
4+
In this section we modify the <<_social_login_simple,simple>> app we
5+
just built, by adding an explicit link to login with Facebook. Instead
6+
of being redirected immediately, the new link will be visible on the
7+
home page, and the user can choose to login or to stay
8+
unauthenticated. Only when the user has clicked on the link will he be
9+
shown the secure content.

github/README.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[[_social_login_github]]
2+
= Login with Github
3+
4+
In this section we modify the <<_social_login_manual,manual>> app we built by adding a link so the user can choose to authenticate with Github, in addition to the original Facebook link.

logout/README.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[[_social_login_logout]]
2+
= Add a Logout Button
3+
4+
In this section we modify the <<_social_login_click,click>> app we built by adding a logout button.

manual/README.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[[_social_login_manual]]
2+
= Manual Configuration of OAuth2 Client
3+
4+
In this section we modify the <<_social_login_logout,logout>> app we built by picking apart the "magic" in the `@EnableOAuth2Sso` annotation, manually configuring everything in there to make it explicit.

overview.adoc

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
This guide shows you how to build a sample app doing various things
2+
with "social login" using https://tools.ietf.org/html/rfc6749[OAuth2]
3+
and http://projects.spring.io/spring-boot/[Spring Boot]. It starts
4+
with a simple, single-provider single-sign on, and works up to a
5+
self-hosted OAuth2 Authorization Server with a choice of
6+
authentication providers (https://developers.facebook.com[Facebook] or
7+
https://developer.github.com/[Github]). The samples are all
8+
single-page apps using Spring Boot and Spring OAuth on the back
9+
end. They also all use https://angularjs.org/[AngularJS] on the front
10+
end, but the changes needed to convert to a different JavaScript
11+
framework or to use server side rendering would be minimal.
12+
13+
There are several samples building on each other adding new features:
14+
15+
* <<_social_login_simple,**simple**>>: a very basic static app with just a home page and
16+
unconditional login through via Spring Boot's `@EnableOAuth2Sso` (if
17+
you visit the home page you will be automatically redirected to
18+
Facebook).
19+
20+
* <<_social_login_click,**click**>>: adds an explicit link that the user has to click to
21+
login.
22+
23+
* <<_social_login_logout,**logout**>>: adds a logout link as well for authenticated users.
24+
25+
* <<_social_login_manual,**manual**>>: shows how the `@EnableOAuth2Sso` works by unpicking it
26+
and configuring all its pieces manually.
27+
28+
* <<_social_login_github,**gitub**>>: adds a second login provider in Github, so the user can
29+
choose on the home page which one to use.
30+
31+
* <<_social_login_authserver,**auth-server**>>: turns the app into a fully-fledged OAuth2
32+
Authorization Server, able to issue its own tokens, but still using
33+
the external OAuth2 providers for authentication.
34+
35+
Each of them can be imported into an IDE and there is a main class
36+
`SocialApplication` that you can run there to start the apps. They all
37+
come up with a home page on http://localhost:8080 (and all require
38+
that you have at least a Facebook account if you want to log in and
39+
see the content). You can also run all the apps on the command line
40+
using `mvn spring-boot:run` or by building the jar file and running it
41+
with `mvn package` and `java -jar target/*.jar` (per the
42+
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#getting-started-first-application-run[Spring
43+
Boot docs] and other
44+
https://spring.io/guides/gs/spring-boot/[available
45+
documentation]). There is no need to install Maven if you use the
46+
https://github.com/takari/maven-wrapper[wrapper] at the top level,
47+
e.g.
48+
49+
```
50+
$ cd simple
51+
$ ../mvnw package
52+
$ java -jar target/*.jar
53+
```
54+
55+
NOTE: The apps all work on `localhost:8080` because they use OAuth2
56+
clients registered with Facebook and Github for that address. To run
57+
them on a different host or port, you need to register your own apps
58+
and put the credentials in the config files. There is no danger of
59+
leaking your Facebook or Github credentials beyond localhost if you
60+
use the default values, but be careful what you expose on the
61+
internet, and don't put your own app registrations in public source
62+
control.

0 commit comments

Comments
 (0)