SlideShare a Scribd company logo
1
Spring Security: OAuth2Spring Security: OAuth2
1
2
Topics
• What is OAuth2?
• Why OAuth2?
• Authorization code flow
3
What is OAuth2?What is OAuth2?
4
What is OAuth2?
• A protocol for conveying authorization decisions (via access token)
> It is NOT an authentication protocol
> Typically used with OpenID Connect
• Standard means of obtaining a token – there are four grant types
> Authorization code
> Resource owner password grant
> Implicit
> Client credentials
• Separation of client application from resource owner
> I, resource owner, authorize this app (client app) to perform these
actions on my behalf
5
What is OAuth2 Not?
• It is NOT an authentication protocol
> The user must be authenticated to obtain a token
> How the user is authenticated is outside of the spec*
> How the token is validated is outside of the spec*
> What the token contains is outside of the spec*
• OpenID Connect handles authentication part
6
Why OAuth2?Why OAuth2?
7
Securing Monolithic App
• You only need to authenticate the request once per user
• If there has been no session
> Verify user credentials
> Start a user session
> Provide role-based access control
• Else (session is already created)
> Verify session has not expired
• Method calls are trusted
8
Securing Monolithic App
• Pros
> Limited attack space
• Cons
> Once granted permission, the user has all the credentials for the rest of
the application including database access – once it is hacked, the whole
application is in danger
9
OAuth2 Secures Micro Services
• Single sign on (SSO)
> SSO along the service call chain
• Stateless
> Backend services do not want to maintain user credentials
> Backend services do not want to maintain user sessions
• Delegated access (access some resource on behalf of me)
> A service can access a resource of another service on behalf of resource owner
• User credentials not exposed
> Only Identity server should manage user credentials
• Fine grained and flexible authorization
> Each service has different access control requirements
• Interoperability with non browser clients
> Browser, mobile devices, services
10
Authorization CodeAuthorization Code
FlowFlow
11
Authorization Code Flow - Actors
• Actors
> Resource owner (user)
> Client web app
> Resource server
> Auth. server
• Use case
> Photo-sharing app (client)
wants to access user's friends
data from Facebook (resource
server)
client
web app
auth server
resource
server
12
Authorization Code Flow – step 1
• User (Resource owner)
accesses the client web app for
the first time
client
web app
auth server
resource
server
13
Authorization Code Flow – step 2
• Client redirects the request to
the “./oauth/authorize” endpoint
of the auth-server
• Note 1 – the client web app has
to be configured with endpoint
location of the
“./oauth/authorize” of the auth
server
• Note 2 – the client web app
redirects the request – in other
words, there is no direct
communication between client
and auth server yet
client
web app
auth server
resource
server
14
Authorization Code Flow – step 3
• Auth server redirects the user to
its login page since the user
isn't logged in to the auth server
(this is an authentication)
• User logs in and is redirected
back to the “./oauth/authorize”
endpoint
client
web app
auth server
resource
server
15
Authorization Code Flow – step 4
• User is then presented with “do
you approve for the client app
to perform some actions
specified in the scope?”
• User authorizes (or approve)
them
client
web app
auth server
resource
server
16
Authorization Code Flow – step 5
• Auth server redirects the user
back to the client web app with
“authorization code” (in the
query params of the redirect)
client
web app
auth server
resource
server
17
Authorization Code Flow – step 6
• Client web app accesses
“./oauth/token” endpoint of the
auth server with the
authorization code
• Note 1 – the client web app has
to be configured with endpoint
location of the “./oauth/token” of
the auth server
• Note 2 – this is a direct
communication between client
web app and auth server – it is
secure because client web app
passes client id and client
secret
client
web app
auth server
resource
server
18
Authorization Code Flow – step 7
• Auth server responds with
“access token”
client
web app
auth server
resource
server
19
Authorization Code Flow – step 8
• Client web app accesses the
resource server with access
token
client
web app
auth server
resource
server
20
Authorization Code Flow – step 9
• Resource server verifies the
token with the auth-server
• Note – resource server has to
be configured with “user-info-
uri” in its application.yml
• Auth server sends back user
info back after verification
• If OpenID Connect is used
along with OAuth2, the
resource server should be able
to verify the validity of the
token, which contains JWT
(JSON Web Token)
client
web app
auth server
resource
server
21
Authorization Code Flow – step 10
• Resource server responds back
with protected resource
• Client web app presents the
resource to the user
client
web app
auth server
resource
server
2222

More Related Content

What's hot (20)

PDF
Introduction to OpenID Connect
Nat Sakimura
 
PPTX
OpenID Connect: An Overview
Pat Patterson
 
PPTX
Rest API Security
Stormpath
 
PPTX
An Introduction to OAuth 2
Aaron Parecki
 
PDF
Spring Boot Actuator
Rowell Belen
 
PDF
Spring Security
Knoldus Inc.
 
PDF
What is REST API? REST API Concepts and Examples | Edureka
Edureka!
 
PPTX
OAuth2 + API Security
Amila Paranawithana
 
PDF
OAuth 2.0
Uwe Friedrichsen
 
ODP
OAuth2 - Introduction
Knoldus Inc.
 
PDF
Angular 16 – the rise of Signals
Coding Academy
 
PDF
A Hacker's perspective on AEM applications security
Mikhail Egorov
 
PDF
스프링 시큐리티 구조 이해
beom kyun choi
 
PPTX
Introduction to Spring Boot
Purbarun Chakrabarti
 
ODP
Introduction to Swagger
Knoldus Inc.
 
PDF
Hunting for security bugs in AEM webapps
Mikhail Egorov
 
PDF
REST APIs with Spring
Joshua Long
 
PDF
ORM Injection
Simone Onofri
 
PDF
Spring Framework - AOP
Dzmitry Naskou
 
PPTX
Spring boot Introduction
Jeevesh Pandey
 
Introduction to OpenID Connect
Nat Sakimura
 
OpenID Connect: An Overview
Pat Patterson
 
Rest API Security
Stormpath
 
An Introduction to OAuth 2
Aaron Parecki
 
Spring Boot Actuator
Rowell Belen
 
Spring Security
Knoldus Inc.
 
What is REST API? REST API Concepts and Examples | Edureka
Edureka!
 
OAuth2 + API Security
Amila Paranawithana
 
OAuth 2.0
Uwe Friedrichsen
 
OAuth2 - Introduction
Knoldus Inc.
 
Angular 16 – the rise of Signals
Coding Academy
 
A Hacker's perspective on AEM applications security
Mikhail Egorov
 
스프링 시큐리티 구조 이해
beom kyun choi
 
Introduction to Spring Boot
Purbarun Chakrabarti
 
Introduction to Swagger
Knoldus Inc.
 
Hunting for security bugs in AEM webapps
Mikhail Egorov
 
REST APIs with Spring
Joshua Long
 
ORM Injection
Simone Onofri
 
Spring Framework - AOP
Dzmitry Naskou
 
Spring boot Introduction
Jeevesh Pandey
 

Similar to Spring security oauth2 (20)

PDF
Spring4 security oauth2
axykim00
 
PDF
Spring4 security oauth2
Sang Shin
 
PDF
Stateless Auth using OAUTH2 & JWT
Mobiliya
 
PDF
Stateless Auth using OAuth2 & JWT
Gaurav Roy
 
PDF
Securing APIs with OAuth 2.0
Kai Hofstetter
 
PPTX
OAuth
Numaan Mohammad
 
PPTX
OAuth
Vijay Naik
 
PDF
Mobile Authentication - Onboarding, best practices & anti-patterns
Pieter Ennes
 
PDF
Intro to API Security with Oauth 2.0
Functional Imperative
 
PDF
O auth2.0 guide
Dilip Mohapatra
 
PDF
oauth-for-credentials-security-in-rest-api-access
idsecconf
 
PPTX
Creating a Sign On with Open id connect
Derek Binkley
 
PPTX
Oauth2 and OWSM OAuth2 support
Gaurav Sharma
 
PPTX
OAuth [noddyCha]
noddycha
 
PPTX
OAuth2 and OpenID with Spring Boot
Geert Pante
 
PPTX
Microservice security with spring security 5.1,Oauth 2.0 and open id connect
Nilanjan Roy
 
PPTX
(1) OAuth 2.0 Overview
anikristo
 
PDF
Learn with WSO2 - API Security
WSO2
 
PDF
Deep Dive into OAuth for Connected Apps
Salesforce Developers
 
PPT
OAuth 2.0 and OpenId Connect
Saran Doraiswamy
 
Spring4 security oauth2
axykim00
 
Spring4 security oauth2
Sang Shin
 
Stateless Auth using OAUTH2 & JWT
Mobiliya
 
Stateless Auth using OAuth2 & JWT
Gaurav Roy
 
Securing APIs with OAuth 2.0
Kai Hofstetter
 
OAuth
Vijay Naik
 
Mobile Authentication - Onboarding, best practices & anti-patterns
Pieter Ennes
 
Intro to API Security with Oauth 2.0
Functional Imperative
 
O auth2.0 guide
Dilip Mohapatra
 
oauth-for-credentials-security-in-rest-api-access
idsecconf
 
Creating a Sign On with Open id connect
Derek Binkley
 
Oauth2 and OWSM OAuth2 support
Gaurav Sharma
 
OAuth [noddyCha]
noddycha
 
OAuth2 and OpenID with Spring Boot
Geert Pante
 
Microservice security with spring security 5.1,Oauth 2.0 and open id connect
Nilanjan Roy
 
(1) OAuth 2.0 Overview
anikristo
 
Learn with WSO2 - API Security
WSO2
 
Deep Dive into OAuth for Connected Apps
Salesforce Developers
 
OAuth 2.0 and OpenId Connect
Saran Doraiswamy
 
Ad

Recently uploaded (20)

PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
Ad

Spring security oauth2

  • 1. 1 Spring Security: OAuth2Spring Security: OAuth2 1
  • 2. 2 Topics • What is OAuth2? • Why OAuth2? • Authorization code flow
  • 4. 4 What is OAuth2? • A protocol for conveying authorization decisions (via access token) > It is NOT an authentication protocol > Typically used with OpenID Connect • Standard means of obtaining a token – there are four grant types > Authorization code > Resource owner password grant > Implicit > Client credentials • Separation of client application from resource owner > I, resource owner, authorize this app (client app) to perform these actions on my behalf
  • 5. 5 What is OAuth2 Not? • It is NOT an authentication protocol > The user must be authenticated to obtain a token > How the user is authenticated is outside of the spec* > How the token is validated is outside of the spec* > What the token contains is outside of the spec* • OpenID Connect handles authentication part
  • 7. 7 Securing Monolithic App • You only need to authenticate the request once per user • If there has been no session > Verify user credentials > Start a user session > Provide role-based access control • Else (session is already created) > Verify session has not expired • Method calls are trusted
  • 8. 8 Securing Monolithic App • Pros > Limited attack space • Cons > Once granted permission, the user has all the credentials for the rest of the application including database access – once it is hacked, the whole application is in danger
  • 9. 9 OAuth2 Secures Micro Services • Single sign on (SSO) > SSO along the service call chain • Stateless > Backend services do not want to maintain user credentials > Backend services do not want to maintain user sessions • Delegated access (access some resource on behalf of me) > A service can access a resource of another service on behalf of resource owner • User credentials not exposed > Only Identity server should manage user credentials • Fine grained and flexible authorization > Each service has different access control requirements • Interoperability with non browser clients > Browser, mobile devices, services
  • 11. 11 Authorization Code Flow - Actors • Actors > Resource owner (user) > Client web app > Resource server > Auth. server • Use case > Photo-sharing app (client) wants to access user's friends data from Facebook (resource server) client web app auth server resource server
  • 12. 12 Authorization Code Flow – step 1 • User (Resource owner) accesses the client web app for the first time client web app auth server resource server
  • 13. 13 Authorization Code Flow – step 2 • Client redirects the request to the “./oauth/authorize” endpoint of the auth-server • Note 1 – the client web app has to be configured with endpoint location of the “./oauth/authorize” of the auth server • Note 2 – the client web app redirects the request – in other words, there is no direct communication between client and auth server yet client web app auth server resource server
  • 14. 14 Authorization Code Flow – step 3 • Auth server redirects the user to its login page since the user isn't logged in to the auth server (this is an authentication) • User logs in and is redirected back to the “./oauth/authorize” endpoint client web app auth server resource server
  • 15. 15 Authorization Code Flow – step 4 • User is then presented with “do you approve for the client app to perform some actions specified in the scope?” • User authorizes (or approve) them client web app auth server resource server
  • 16. 16 Authorization Code Flow – step 5 • Auth server redirects the user back to the client web app with “authorization code” (in the query params of the redirect) client web app auth server resource server
  • 17. 17 Authorization Code Flow – step 6 • Client web app accesses “./oauth/token” endpoint of the auth server with the authorization code • Note 1 – the client web app has to be configured with endpoint location of the “./oauth/token” of the auth server • Note 2 – this is a direct communication between client web app and auth server – it is secure because client web app passes client id and client secret client web app auth server resource server
  • 18. 18 Authorization Code Flow – step 7 • Auth server responds with “access token” client web app auth server resource server
  • 19. 19 Authorization Code Flow – step 8 • Client web app accesses the resource server with access token client web app auth server resource server
  • 20. 20 Authorization Code Flow – step 9 • Resource server verifies the token with the auth-server • Note – resource server has to be configured with “user-info- uri” in its application.yml • Auth server sends back user info back after verification • If OpenID Connect is used along with OAuth2, the resource server should be able to verify the validity of the token, which contains JWT (JSON Web Token) client web app auth server resource server
  • 21. 21 Authorization Code Flow – step 10 • Resource server responds back with protected resource • Client web app presents the resource to the user client web app auth server resource server
  • 22. 2222