SlideShare a Scribd company logo
JavaCommunity
OAuth2 and Spring
Security
OREST IVASIV
8/14/2015 @halyph
JavaCommunity
OAuth2 Overview
Use Cases
◦ Service-to-service
◦ Client-to-Service
◦ Client-to-client (SSO)
Spring Security OAuth2 Samples
8/14/2015 @halyph2
Agenda
JavaCommunity
Dark Age
Pre OAuth 1.0
◦ Flickr: “FlickrAuth”
◦ Google: “AuthSub”
◦ Facebook: request signed with MD5 hashes
◦ Yahoo: BBAuth (“Browser-Based Auth”)
OAuth 1.0
◦ Uses signature (HMAC hash)
Oauth 2.0
◦ Relies on SSL/HTTPS
8/14/2015 @halyph3
OAuth2 History
JavaCommunity
Authentication
Authorization
Federated Authentication
Delegated Authorization
8/14/2015 @halyph4
Terminology
JavaCommunity
Resource Owner - User
Resource Server – API
Client Application – 3d party application
Authorization Server – Auth API (may be in scope of Resource Server)
8/14/2015 @halyph5
OAuth2 Roles
JavaCommunity
◦ Register with Authorization Server (get a client_id and maybe a client_secret)
◦ Do not collect user credentials
◦ Obtain a token (opaque) from Authorization Server
◦ On its own behalf - client_credentials
◦ On behalf of a user
◦ Use it to access Resource Server
8/14/2015 @halyph6
Role of Client Application
JavaCommunity
1. Extract token from request and decode it
2. Make access control decision
◦ Scope
◦ Audience
◦ User account information (id, roles etc.)
◦ Client information (id, roles etc.)
3. Send 403 (FORBIDDEN) if token not sufficient
8/14/2015 @halyph7
Role of Resource Server
JavaCommunity
1. Compute token content and grant tokens
2. Interface for users to confirm that they authorize the Client to act on their behalf
3. Authenticate users (/authorize)
4. Authenticate clients (/token)
#1 and #4 are covered thoroughly by the spec; #2 and #3 not (for good reasons).
8/14/2015 @halyph8
Role of the Authorization Server
JavaCommunity
Authorization code grant flow
◦ Web-server apps – authorization_code
Implicit grant flow
◦ Browser-based apps – implicit
◦ Mobile apps – implicit
Resource owner password credentials grant flow
◦ Username/password access – password
Client credentials grant flow
◦ Application access – client_credentials
8/14/2015 @halyph9
OAuth 2.0 Grant Flows
JavaCommunity
8/14/2015 @halyph10
Authorization code grant flow
JavaCommunity
8/14/2015 @halyph11
Authorization code grant flow
JavaCommunity
◦ Create a “Log In” link
◦ Link to:
https://facebook.com/dialog/oauth?response_type=code&client_id=YOU
R_CLIENT_ID&redirect_uri=REDIRECT_URI&scope=email
8/14/2015 @halyph12
Authorization code grant flow (Cont)
JavaCommunity
◦ User visits the authorization page
https://facebook.com/dialog/oauth?response_type=code&client_id=28
653682475872&redirect_uri=everydaycity.com&scope=email
◦ On success, user is redirected back to your site with auth code
https://example.com/auth?code=AUTH_CODE_HERE
◦ On error, user is redirected back to your site with error code
https://example.com/auth?error=access_denied
8/14/2015 @halyph13
Authorization code grant flow (Cont)
JavaCommunity
◦ Server exchanges auth code for an access token
POST https://graph.facebook.com/oauth/access_token
Post Body:
grant_type=authorization_code
&code=CODE_FROM_QUERY_STRING
&redirect_uri=REDIRECT_URI &client_id=YOUR_CLIENT_ID
&client_secret=YOUR_CLIENT_SECRET
◦ Your server gets a response like the following
{
"access_token":"RsT5OjbzRn430zqMLgV3Ia",
"token_type":"bearer",
"expires_in":3600,
"refresh_token":"e1qoXg7Ik2RRua48lXIV"
}
or if there was an error
{
"error":"invalid_request"
}
8/14/2015 @halyph14
Authorization code grant flow (Cont)
JavaCommunity
8/14/2015 @halyph15
Implicit grant flow
JavaCommunity
8/14/2015 @halyph16
Implicit grant flow
JavaCommunity
◦ Create a “Log In” link
◦ Link to:
https://facebook.com/dialog/oauth?response_type=token&client_id=CL
IENT_ID
&redirect_uri=REDIRECT_URI&scope=email
8/14/2015 @halyph17
Implicit grant flow (Cont)
JavaCommunity
◦ User visits the authorization page
https://facebook.com/dialog/oauth?response_type=token&client_id=2
865368247587&redirect_uri=everydaycity.com&scope=email
◦ On success, user is redirected back to your site with the access token in the fragment
https://example.com/auth#token=ACCESS_TOKEN
◦ On error, user is redirected back to your site with error code
https://example.com/auth#error=access_denied
8/14/2015 @halyph18
Implicit grant flow (Cont)
JavaCommunity
8/14/2015 @halyph19
Resource owner password credentials grant flow
JavaCommunity
8/14/2015 @halyph20
Resource owner password credentials grant flow
JavaCommunity
POST https://api.example.com/oauth/token
Post Body:
grant_type=password
&username=USERNAME
&password=PASSWORD
&client_id=YOUR_CLIENT_ID
&client_secret=YOUR_CLIENT_SECRET
Response:
{
"access_token":"RsT5OjbzRn430zqMLgV3Ia",
"token_type":"bearer",
"expires_in":3600,
"refresh_token":"e1qoXg7Ik2RRua48lXIV"
}
8/14/2015 @halyph21
Resource owner password credentials grant flow (Cont)
JavaCommunity
8/14/2015 @halyph22
Client credentials grant flow
JavaCommunity
8/14/2015 @halyph23
Client credentials grant flow
JavaCommunity
POST https://api.example.com/1/oauth/token
Post Body:
grant_type=client_credentials
&client_id=YOUR_CLIENT_ID
&client_secret=YOUR_CLIENT_SECRET
Response:
{
"access_token":"RsT5OjbzRn430zqMLgV3Ia",
"token_type":"bearer",
"expires_in":3600,
"refresh_token":"e1qoXg7Ik2RRua48lXIV"
}
8/14/2015 @halyph24
Client credentials grant flow (Cont)
JavaCommunity
authorization_code:
◦ Authorization code grant flow (Web-server apps)
◦ response_type=code
implicit:
◦ Implicit grant flow (Mobile and browser-based apps)
◦ response_type=token
password:
◦ Resource owner password credentials grant flow (Username/password access)
client_credentials:
◦ Client credentials grant flow (Application access)
8/14/2015 @halyph25
Grant Types
JavaCommunity
GET https://api.example.com/me
Authorization: Bearer RsT5OjbzRn430zqMLgV3Ia
Access token can be in an HTTP header or a query string parameter
https://api.example.com/me?access_token=RsT5OjbzRn430zqMLgV3Ia
8/14/2015 @halyph26
Accessing Resources
JavaCommunity
POST https://api.example.com/oauth/token
grant_type=refresh_token
&reresh_token=e1qoXg7Ik2RRua48lXIV
&client_id=YOUR_CLIENT_ID
&client_secret=YOUR_CLIENT_SECRET
Your server gets a similar response as the original call to oauth/token with new tokens.
{
"access_token":"RsT5OjbzRn430zqMLgV3Ia",
"expires_in":3600,
"refresh_token":"e1qoXg7Ik2RRua48lXIV"
8/14/2015 @halyph27
New access token via refresh token
JavaCommunity
POST https://api.example.com/oauth/token
grant_type=refresh_token
&reresh_token=e1qoXg7Ik2RRua48lXIV
&client_id=YOUR_CLIENT_ID
&client_secret=YOUR_CLIENT_SECRET
Your server gets a similar response as the original call to oauth/token with new tokens.
{
"access_token":"RsT5OjbzRn430zqMLgV3Ia",
"expires_in":3600,
"refresh_token":"e1qoXg7Ik2RRua48lXIV"
8/14/2015 @halyph28
New access token via refresh token
JavaCommunity
1. Sample OAuth2 with password grant
2. Web App Client
8/14/2015 @halyph29
Sample Apps
JavaCommunity
OAuth
◦ The OAuth 2.0 Authorization Framwork
◦ http://oauth.net/2/
◦ OAuth Bible by @Nijikokun
◦ An Introduction to OAuth 2 by Aaron Parecki
◦ Single-Page-Application & REST security by Igor Bossenko
Videos
◦ O'Reilly Webcast: An Introduction to OAuth 2 by Aaron Parecki
◦ David Syer (lead of Spring Security OAuth)
◦ Security for Microservices with Spring and OAuth2
◦ Webinar Replay: A Single-Page Application with Spring Security and Angular JS
◦ Data Modelling and Identity Management with OAuth2
◦ Les Hazlewood (Stormpath founder and CTO, Apache Shiro)
◦ Token Authentication for Java Applications
Sample Apps
◦ https://github.com/spring-projects/spring-security-oauth/tree/master/tests/
◦ https://github.com/spring-projects/spring-security-oauth/tree/master/samples/oauth2
◦ https://github.com/dsyer/spring-security-angular/
OAuth and Spring
◦ https://speakerdeck.com/dsyer/security-for-microservices-with-spring
8/14/2015 @halyph30
References
JavaCommunity
Q&A
8/14/2015 @halyph31

More Related Content

PDF
Spring Security
PDF
PUC SE Day 2019 - SpringBoot
PDF
Real Life Clean Architecture
PPTX
Schema directeur et urbanisation du si
PPTX
Getting Started With WebAuthn
PDF
BigData_Chp4: NOSQL
PDF
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
PDF
Microservices avec Spring Cloud
Spring Security
PUC SE Day 2019 - SpringBoot
Real Life Clean Architecture
Schema directeur et urbanisation du si
Getting Started With WebAuthn
BigData_Chp4: NOSQL
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Microservices avec Spring Cloud

What's hot (20)

ODP
OAuth2 - Introduction
PPTX
Spring security
PDF
Spring Boot
PPTX
Spring Security 5
PPTX
Introduction to spring boot
PDF
Microservices with Java, Spring Boot and Spring Cloud
PDF
Hacking Adobe Experience Manager sites
PDF
What is REST API? REST API Concepts and Examples | Edureka
PDF
OAuth 2.0
PPTX
Springboot Microservices
PPTX
An Introduction to OAuth2
PPTX
RESTful API - Best Practices
PPTX
Spring boot
PPTX
An introduction to OAuth 2
PPTX
Soap vs rest
PPTX
OAuth2 + API Security
PDF
Spring boot introduction
PDF
Spring MVC Framework
PDF
Spring Security
PPTX
Spring Framework
OAuth2 - Introduction
Spring security
Spring Boot
Spring Security 5
Introduction to spring boot
Microservices with Java, Spring Boot and Spring Cloud
Hacking Adobe Experience Manager sites
What is REST API? REST API Concepts and Examples | Edureka
OAuth 2.0
Springboot Microservices
An Introduction to OAuth2
RESTful API - Best Practices
Spring boot
An introduction to OAuth 2
Soap vs rest
OAuth2 + API Security
Spring boot introduction
Spring MVC Framework
Spring Security
Spring Framework
Ad

Similar to OAuth2 and Spring Security (20)

PDF
Keeping Pace with OAuth’s Evolving Security Practices.pdf
PDF
I Love APIs 2015: Advanced Crash Course in Apigee Edge Workshop
PPT
UserCentric Identity based Service Invocation
PPTX
How to Use Stormpath in angular js
PPT
O auth 2
PPTX
Securing RESTful APIs using OAuth 2 and OpenID Connect
PPTX
Using ArcGIS with OAuth 2.0 - Esri DevSummit Dubai 2013
PPTX
Securing RESTful APIs using OAuth 2 and OpenID Connect
PPTX
OAuth - Don’t Throw the Baby Out with the Bathwater
PPTX
Devteach 2017 OAuth and Open id connect demystified
PPT
Oauth2.0
PPTX
How to build Simple yet powerful API.pptx
PPTX
Oauth2 and OWSM OAuth2 support
PDF
Accessing APIs using OAuth on the federated (WordPress) web
PPTX
OAuth in the Wild
PDF
What the Heck is OAuth and OIDC - UberConf 2018
PDF
Access Management for Cloud and Mobile
PDF
What the Heck is OAuth and OIDC - Denver Developer Identity Workshop 2020
PDF
Understanding Identity in the World of Web APIs – Ronnie Mitra, API Architec...
PPTX
Adding Identity Management and Access Control to your Application
Keeping Pace with OAuth’s Evolving Security Practices.pdf
I Love APIs 2015: Advanced Crash Course in Apigee Edge Workshop
UserCentric Identity based Service Invocation
How to Use Stormpath in angular js
O auth 2
Securing RESTful APIs using OAuth 2 and OpenID Connect
Using ArcGIS with OAuth 2.0 - Esri DevSummit Dubai 2013
Securing RESTful APIs using OAuth 2 and OpenID Connect
OAuth - Don’t Throw the Baby Out with the Bathwater
Devteach 2017 OAuth and Open id connect demystified
Oauth2.0
How to build Simple yet powerful API.pptx
Oauth2 and OWSM OAuth2 support
Accessing APIs using OAuth on the federated (WordPress) web
OAuth in the Wild
What the Heck is OAuth and OIDC - UberConf 2018
Access Management for Cloud and Mobile
What the Heck is OAuth and OIDC - Denver Developer Identity Workshop 2020
Understanding Identity in the World of Web APIs – Ronnie Mitra, API Architec...
Adding Identity Management and Access Control to your Application
Ad

More from Orest Ivasiv (8)

PDF
Why don't you Groovy?
PDF
Vagrant or docker for java dev environment
PDF
Dockerizing development workflow
PPTX
When Camel Smiles
PPTX
Adventures of java developer in ruby world
PDF
Math synonyms
PPTX
Java Code Quality Tools
PPTX
Time Management: the Hidden Power of Pomodoro
Why don't you Groovy?
Vagrant or docker for java dev environment
Dockerizing development workflow
When Camel Smiles
Adventures of java developer in ruby world
Math synonyms
Java Code Quality Tools
Time Management: the Hidden Power of Pomodoro

Recently uploaded (20)

PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
KodekX | Application Modernization Development
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation theory and applications.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPT
Teaching material agriculture food technology
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Electronic commerce courselecture one. Pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
cuic standard and advanced reporting.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
KodekX | Application Modernization Development
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation theory and applications.pdf
Spectral efficient network and resource selection model in 5G networks
Teaching material agriculture food technology
The AUB Centre for AI in Media Proposal.docx
Electronic commerce courselecture one. Pdf
Big Data Technologies - Introduction.pptx
Unlocking AI with Model Context Protocol (MCP)
Chapter 3 Spatial Domain Image Processing.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
cuic standard and advanced reporting.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Empathic Computing: Creating Shared Understanding
The Rise and Fall of 3GPP – Time for a Sabbatical?
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Dropbox Q2 2025 Financial Results & Investor Presentation

OAuth2 and Spring Security