SlideShare a Scribd company logo
1 of 32
Oauth2 and OpenID
Goals
・ Understand Oauth
・Grab the concept of OpenID Connect
・Integrate with OAuth2 Provider
・Implement spring security with OAuth2
OAuth2 Use Cases
• Login: OpenID connect
• Access REST API for Users
• Access REST API server-to-server
Build Your Own Authentication?
A Lot of Requirements
・Store user credentials safely
・Support LDAP//SSO integration?
・Develop a password reset process
・Develop MFA by your own
・User feel annoyed to each application
with a unique password.
OpenID Connect / OAuth2
・Delegate storing user credentials
・Manages user registration easily
・Manage password reset process
・Delegate MFA implementation
・User can login with multiple applications
with a single set of credentials
What is the Concept of OAuth2 ?
・Authentication vs. Authorization
・Tokens
・Scopes
・Client Credentials
・Authorization Code
Authentication vs. Authorization
Authorization
Authentication
・Identify who you are
・Must Prove your identity
・What are you allowed to do
・What API resources can you access
Authorization Examples
If you are in AWS environment,
the access distribution would be...
Administrator Developer Biz
・Have all access
(Include billing access)
・Have access to create,
delete, edit resources
・Only have access to read
resources.
Tokens
Access Token Refresh Token
・To refresh the condition
・Bearer Tokens
・JWT Token
・Opaque Token
Tokens' Metaphor
Access Token Refresh Token
Possession Used to buy more ticket
Scopes vs Authorities
Scopes in OAuth2 tells the application what user data it can
access.
• Personal data from the provider, like email
• Application specific scope names?
Can be (ab)used as Spring Security Authorities
Authorities in Spring Security
Roles
・Like, manager, chef, server, dish wash etc..
・A permitted authority or action
Permissions
・Permitted actions on specific data
・Like a manager for a specific division
・Or owner of a specific configuration
What is OpenID Connect ?
OpenID Connect is…..
Features
・Confidential, secure & browser based
・Not access a resource directly so that we get id
token instead of an access token.
・Hybrid flow with id tokens instead of access tokens.
OpenID's Metaphor
Theme Park (Resource)
Ticket
(Access
Token)
You (Client)
Wrist Band
(ID Token) You with wrist Band
(Client with ID token )
You are allowed
to enter !
Ticket gate
(Open ID)
OpenID Connect Flows
Client Credentials flow: for server-to-server calls
• Sends client id + client secret to OAuth2 Provider
• Receives access token directly
Authorization Code flow: for stateful applications
• Redirects users to OAuth2 Provider
• Receives authorization code
• Exchange for access token via backend-to-backend call
• Sends Session Cookie to frontend for subsequent calls
Authorization Code with PKCE: for single-page-application or mobile
• Application opens a separate browser for OAuth2 Provider login
• Receives authorization code from the browser in the Application
• Exchange for access token directly from the Application to the OAuth2 Provider
• Application sends access token to the Backend in every REST call
2 Initialize the flow with the STS by redirecting the browser
4
5
3
I am Philippe with password FluffyDog17!
Request to the STS to initialize the flow
6
Who are you? Please authenticate to me!
Good. Now follow this redirect back to the application,
so it can extract the authorization code from the URL
7
1
Follow redirect to the application's callback endpoint
I want to authenticate (click the login button)
8
A server-to-server request to exchange
the authorization code from step 7
9 The identity token representing
the authenticated user
10 Use the identity token
to authenticate the user
THE AUTHORIZATION CODE FLOW FOR OIDC
The authorization request (a redirect to the STS)
1 https://sts.restograde.com/authorize
2 ?response_type=code
3 &scope=openid profile email
4 &client_id=FN983CEYgx4mdUg3NKNKHjwfNAL5Fb42
5 &redirect_uri=https://restograde.com/callback
Indicates the authorization code flow
We want an ID token with email/profile info
The client requesting authentication
Where the STS should send the code
2 3
The redirect back to the client application
1 https://restograde.com/callback
2 ?code=ySVyktqNkEKJyyIjOKCVwCurNlGoRDcaLYEbW2j5WxZY The temporary authorization code
6 7
The request to exchange the authorization code
1 POST /oauth/token
2
3 grant_type=authorization_code
4 &client_id=FN983CEYgx4mdUg3NKNKHjwfNAL5Fb42
5 &client_secret=6ODRv0g…OVOSWI
7 &redirect_uri=https://restograde.com/callback
8 &code=ySVyktqNkEKJyyIjOKCVwCurNlGoRDcaLYEbW2j5WxZY
8
Indicates the code exchange request
The client exchanging the code
The client needs to authenticate to the STS
The redirect URI used before
The code received in step 7
pdr.online
The response from the Security Token Service
1 {
2 "id_token": "eyJhbGciO...du6TY9w",
3 }
9
The identity token representing the authenticated user
The identity token contains a sub claim with the
user's unique identifier. The application can use
this claim to lookup the user in its database and
establish and authenticated session
pdr.online
Handle tokens according
to the use case at hand
4
3 Request to the STS to initialize the flow
I know you! Follow this redirect back to the application!
7
1
Follow redirect to the application's callback endpoint
Request that triggers the initialization of the flow
8
A server-to-server request to exchange
the authorization co
de from step 7
9 Relevant tokens for this
particular use case
10
Session Cookies
The STS uses cookies to keep track of the authenticated
user. Every subsequent request from the browser to the
STS will carry this cookie, enabling session re-use and SSO.
2 Initialize the flow with the STS by redirecting the browser
The backend can also use a
cookie to store session id’s
for authorized users.
1 Initialize the flow with the STS
2 Initialize the flow
3 Redirect with authorization code
4 Follow redirect with authorization code
7
A server-to-server request to
exchange the authorization code
8 Relevant tokens associated
with the victim user
10 Associate tokens with
the attacker's account
AN AUTHORIZATION CODE INJECTION ATTACK
5 Steal the authorization code
6
Send request to
the callback with
the stolen code
4 Initialize the flow and include the code challenge
6
7
5
I am Philippe with password FluffyDog17!
Request to the STS to initialize the flow
9
Who are you? Please authenticate to me!
Good. Now follow this redirect back to the application,
so it can extract the authorization code from the URL
10
1
Follow redirect to the application's callback endpoint
Request that triggers the initialization of the flow
11
Exchange the authorization code from step 10
and include the code verifier
13 Relevant tokens for this
particular use case
14 Handle tokens according
to the use case at hand
THE AUTHORIZATION CODE FLOW WITH PKCE
2
Generate a random value (code verifier) and
associate it with the user's session (e.g., keep in a cookie)
8
Store the code challenge
along with the
authorization code
Calculate the SHA256
hash of the code verifier
and compare to the
stored code challenge
3
Calculate the SHA256 hash
of the code verifier
(code challenge)
12
JWT Token
• In Authorization code flow, JWT Tokens are received by the backend
• JWT Tokens can also be used directly for REST API’s
• “Authorization: Bearer “+ jwtToken
Spring Security and
OpenID Connect
Configure a Client application in an OIDC
Provider
Multiple OpenID Connect Providers
• Azure AD, AWS Cognito, Google Account, GitHub
• Okta, Auth0, OneLogin
• For development: JBoss KeyCloak
Need to register a client application
• Allows access to user information
• Client ID + Client Secret
• Authorized callback URL’s
• For spring: …/login/oauth2/code/{provider}
Register an OAuth2 Client
Github:
• Set up Homepage URL
• Authorization callback URL
Keycloak:
• Create Realm
• Create Client
• Configure callback URL
• Add users
Configure a Spring application for OIDC Login
• spring-boot-starter-oauth2-client will autoconfigure OIDC logins.
• spring-boot-starter-oauth2-resource-server will add support for REST API
• issuer-uri has a /.well-known/openid-configuration path.
Configure WebSecurity
Authentication
Default Authorities
• Each logged in user has OIDC_USER
• All OIDC scopes will be translated to SCOPE_name
Debugging & Resources
Debugging logging.level.org.springframework.securit=
ydebug
1. Add and debug=true
at your application.properties or application.yml
2. Add spring-boot-starter-actuator
at your pom.xml
3. Go to http://localhost:8080/actuator
Thank you for Listening!

More Related Content

Similar to OAuth2 and OpenID with Spring Boot

Intro to OAuth2 and OpenID Connect
Intro to OAuth2 and OpenID ConnectIntro to OAuth2 and OpenID Connect
Intro to OAuth2 and OpenID ConnectLiamWadman
 
Clef security architecture
Clef security architectureClef security architecture
Clef security architecturejessepollak
 
Deep Dive into OAuth for Connected Apps
Deep Dive into OAuth for Connected AppsDeep Dive into OAuth for Connected Apps
Deep Dive into OAuth for Connected AppsSalesforce Developers
 
Stateless Auth using OAUTH2 & JWT
Stateless Auth using OAUTH2 & JWTStateless Auth using OAUTH2 & JWT
Stateless Auth using OAUTH2 & JWTMobiliya
 
Securing APIs with OAuth 2.0
Securing APIs with OAuth 2.0Securing APIs with OAuth 2.0
Securing APIs with OAuth 2.0Kai Hofstetter
 
NextGenPSD2 OAuth SCA Mode Security Recommendations
NextGenPSD2 OAuth SCA Mode Security Recommendations NextGenPSD2 OAuth SCA Mode Security Recommendations
NextGenPSD2 OAuth SCA Mode Security Recommendations Torsten Lodderstedt
 
Spring4 security oauth2
Spring4 security oauth2Spring4 security oauth2
Spring4 security oauth2axykim00
 
Mit 2014 introduction to open id connect and o-auth 2
Mit 2014   introduction to open id connect and o-auth 2Mit 2014   introduction to open id connect and o-auth 2
Mit 2014 introduction to open id connect and o-auth 2Justin Richer
 
Oauth Nightmares Abstract OAuth Nightmares
Oauth Nightmares Abstract OAuth Nightmares Oauth Nightmares Abstract OAuth Nightmares
Oauth Nightmares Abstract OAuth Nightmares Nino Ho
 
Spring security oauth2
Spring security oauth2Spring security oauth2
Spring security oauth2axykim00
 
Spring4 security oauth2
Spring4 security oauth2Spring4 security oauth2
Spring4 security oauth2Sang Shin
 
Auth proxy pattern on Kubernetes
Auth proxy pattern on KubernetesAuth proxy pattern on Kubernetes
Auth proxy pattern on KubernetesMichał Wcisło
 
(1) OAuth 2.0 Overview
(1) OAuth 2.0 Overview(1) OAuth 2.0 Overview
(1) OAuth 2.0 Overviewanikristo
 
Stateless Auth using OAuth2 & JWT
Stateless Auth using OAuth2 & JWTStateless Auth using OAuth2 & JWT
Stateless Auth using OAuth2 & JWTGaurav Roy
 
CIS14: Working with OAuth and OpenID Connect
CIS14: Working with OAuth and OpenID ConnectCIS14: Working with OAuth and OpenID Connect
CIS14: Working with OAuth and OpenID ConnectCloudIDSummit
 
Introducing OpenID 1.0 Protocol: Security and Performance
Introducing OpenID 1.0 Protocol: Security and PerformanceIntroducing OpenID 1.0 Protocol: Security and Performance
Introducing OpenID 1.0 Protocol: Security and PerformanceAmin Saqi
 

Similar to OAuth2 and OpenID with Spring Boot (20)

Intro to OAuth2 and OpenID Connect
Intro to OAuth2 and OpenID ConnectIntro to OAuth2 and OpenID Connect
Intro to OAuth2 and OpenID Connect
 
Demystifying OAuth 2.0
Demystifying OAuth 2.0Demystifying OAuth 2.0
Demystifying OAuth 2.0
 
OpenID Connect Explained
OpenID Connect ExplainedOpenID Connect Explained
OpenID Connect Explained
 
Clef security architecture
Clef security architectureClef security architecture
Clef security architecture
 
Deep Dive into OAuth for Connected Apps
Deep Dive into OAuth for Connected AppsDeep Dive into OAuth for Connected Apps
Deep Dive into OAuth for Connected Apps
 
OAuth 2
OAuth 2OAuth 2
OAuth 2
 
Stateless Auth using OAUTH2 & JWT
Stateless Auth using OAUTH2 & JWTStateless Auth using OAUTH2 & JWT
Stateless Auth using OAUTH2 & JWT
 
Securing APIs with OAuth 2.0
Securing APIs with OAuth 2.0Securing APIs with OAuth 2.0
Securing APIs with OAuth 2.0
 
NextGenPSD2 OAuth SCA Mode Security Recommendations
NextGenPSD2 OAuth SCA Mode Security Recommendations NextGenPSD2 OAuth SCA Mode Security Recommendations
NextGenPSD2 OAuth SCA Mode Security Recommendations
 
Spring4 security oauth2
Spring4 security oauth2Spring4 security oauth2
Spring4 security oauth2
 
Mit 2014 introduction to open id connect and o-auth 2
Mit 2014   introduction to open id connect and o-auth 2Mit 2014   introduction to open id connect and o-auth 2
Mit 2014 introduction to open id connect and o-auth 2
 
Oauth Nightmares Abstract OAuth Nightmares
Oauth Nightmares Abstract OAuth Nightmares Oauth Nightmares Abstract OAuth Nightmares
Oauth Nightmares Abstract OAuth Nightmares
 
Iam f42 a
Iam f42 aIam f42 a
Iam f42 a
 
Spring security oauth2
Spring security oauth2Spring security oauth2
Spring security oauth2
 
Spring4 security oauth2
Spring4 security oauth2Spring4 security oauth2
Spring4 security oauth2
 
Auth proxy pattern on Kubernetes
Auth proxy pattern on KubernetesAuth proxy pattern on Kubernetes
Auth proxy pattern on Kubernetes
 
(1) OAuth 2.0 Overview
(1) OAuth 2.0 Overview(1) OAuth 2.0 Overview
(1) OAuth 2.0 Overview
 
Stateless Auth using OAuth2 & JWT
Stateless Auth using OAuth2 & JWTStateless Auth using OAuth2 & JWT
Stateless Auth using OAuth2 & JWT
 
CIS14: Working with OAuth and OpenID Connect
CIS14: Working with OAuth and OpenID ConnectCIS14: Working with OAuth and OpenID Connect
CIS14: Working with OAuth and OpenID Connect
 
Introducing OpenID 1.0 Protocol: Security and Performance
Introducing OpenID 1.0 Protocol: Security and PerformanceIntroducing OpenID 1.0 Protocol: Security and Performance
Introducing OpenID 1.0 Protocol: Security and Performance
 

More from Geert Pante

Kafka Introduction.pptx
Kafka Introduction.pptxKafka Introduction.pptx
Kafka Introduction.pptxGeert Pante
 
Kubernetes and Amazon ECS
Kubernetes and Amazon ECSKubernetes and Amazon ECS
Kubernetes and Amazon ECSGeert Pante
 
Docker in practice
Docker in practiceDocker in practice
Docker in practiceGeert Pante
 
Spring JMS and ActiveMQ
Spring JMS and ActiveMQSpring JMS and ActiveMQ
Spring JMS and ActiveMQGeert Pante
 
Log management with ELK
Log management with ELKLog management with ELK
Log management with ELKGeert Pante
 
Spring 4 en spring data
Spring 4 en spring dataSpring 4 en spring data
Spring 4 en spring dataGeert Pante
 
Spring and SOA (2006)
Spring and SOA (2006)Spring and SOA (2006)
Spring and SOA (2006)Geert Pante
 
Maven plugins, properties en profiles: Advanced concepts in Maven
Maven plugins, properties en profiles: Advanced concepts in MavenMaven plugins, properties en profiles: Advanced concepts in Maven
Maven plugins, properties en profiles: Advanced concepts in MavenGeert Pante
 
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRISThe glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRISGeert Pante
 
Version Management in Maven
Version Management in MavenVersion Management in Maven
Version Management in MavenGeert Pante
 

More from Geert Pante (11)

Kafka Introduction.pptx
Kafka Introduction.pptxKafka Introduction.pptx
Kafka Introduction.pptx
 
Kubernetes and Amazon ECS
Kubernetes and Amazon ECSKubernetes and Amazon ECS
Kubernetes and Amazon ECS
 
Docker in practice
Docker in practiceDocker in practice
Docker in practice
 
Spring JMS and ActiveMQ
Spring JMS and ActiveMQSpring JMS and ActiveMQ
Spring JMS and ActiveMQ
 
Log management with ELK
Log management with ELKLog management with ELK
Log management with ELK
 
Java EE 6
Java EE 6Java EE 6
Java EE 6
 
Spring 4 en spring data
Spring 4 en spring dataSpring 4 en spring data
Spring 4 en spring data
 
Spring and SOA (2006)
Spring and SOA (2006)Spring and SOA (2006)
Spring and SOA (2006)
 
Maven plugins, properties en profiles: Advanced concepts in Maven
Maven plugins, properties en profiles: Advanced concepts in MavenMaven plugins, properties en profiles: Advanced concepts in Maven
Maven plugins, properties en profiles: Advanced concepts in Maven
 
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRISThe glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
 
Version Management in Maven
Version Management in MavenVersion Management in Maven
Version Management in Maven
 

Recently uploaded

ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 

Recently uploaded (20)

ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 

OAuth2 and OpenID with Spring Boot

  • 2. Goals ・ Understand Oauth ・Grab the concept of OpenID Connect ・Integrate with OAuth2 Provider ・Implement spring security with OAuth2
  • 3. OAuth2 Use Cases • Login: OpenID connect • Access REST API for Users • Access REST API server-to-server
  • 4. Build Your Own Authentication? A Lot of Requirements ・Store user credentials safely ・Support LDAP//SSO integration? ・Develop a password reset process ・Develop MFA by your own ・User feel annoyed to each application with a unique password.
  • 5. OpenID Connect / OAuth2 ・Delegate storing user credentials ・Manages user registration easily ・Manage password reset process ・Delegate MFA implementation ・User can login with multiple applications with a single set of credentials
  • 6. What is the Concept of OAuth2 ? ・Authentication vs. Authorization ・Tokens ・Scopes ・Client Credentials ・Authorization Code
  • 7. Authentication vs. Authorization Authorization Authentication ・Identify who you are ・Must Prove your identity ・What are you allowed to do ・What API resources can you access
  • 8. Authorization Examples If you are in AWS environment, the access distribution would be... Administrator Developer Biz ・Have all access (Include billing access) ・Have access to create, delete, edit resources ・Only have access to read resources.
  • 9. Tokens Access Token Refresh Token ・To refresh the condition ・Bearer Tokens ・JWT Token ・Opaque Token
  • 10. Tokens' Metaphor Access Token Refresh Token Possession Used to buy more ticket
  • 11. Scopes vs Authorities Scopes in OAuth2 tells the application what user data it can access. • Personal data from the provider, like email • Application specific scope names? Can be (ab)used as Spring Security Authorities
  • 12. Authorities in Spring Security Roles ・Like, manager, chef, server, dish wash etc.. ・A permitted authority or action Permissions ・Permitted actions on specific data ・Like a manager for a specific division ・Or owner of a specific configuration
  • 13. What is OpenID Connect ?
  • 14. OpenID Connect is….. Features ・Confidential, secure & browser based ・Not access a resource directly so that we get id token instead of an access token. ・Hybrid flow with id tokens instead of access tokens.
  • 15. OpenID's Metaphor Theme Park (Resource) Ticket (Access Token) You (Client) Wrist Band (ID Token) You with wrist Band (Client with ID token ) You are allowed to enter ! Ticket gate (Open ID)
  • 16. OpenID Connect Flows Client Credentials flow: for server-to-server calls • Sends client id + client secret to OAuth2 Provider • Receives access token directly Authorization Code flow: for stateful applications • Redirects users to OAuth2 Provider • Receives authorization code • Exchange for access token via backend-to-backend call • Sends Session Cookie to frontend for subsequent calls Authorization Code with PKCE: for single-page-application or mobile • Application opens a separate browser for OAuth2 Provider login • Receives authorization code from the browser in the Application • Exchange for access token directly from the Application to the OAuth2 Provider • Application sends access token to the Backend in every REST call
  • 17. 2 Initialize the flow with the STS by redirecting the browser 4 5 3 I am Philippe with password FluffyDog17! Request to the STS to initialize the flow 6 Who are you? Please authenticate to me! Good. Now follow this redirect back to the application, so it can extract the authorization code from the URL 7 1 Follow redirect to the application's callback endpoint I want to authenticate (click the login button) 8 A server-to-server request to exchange the authorization code from step 7 9 The identity token representing the authenticated user 10 Use the identity token to authenticate the user THE AUTHORIZATION CODE FLOW FOR OIDC
  • 18. The authorization request (a redirect to the STS) 1 https://sts.restograde.com/authorize 2 ?response_type=code 3 &scope=openid profile email 4 &client_id=FN983CEYgx4mdUg3NKNKHjwfNAL5Fb42 5 &redirect_uri=https://restograde.com/callback Indicates the authorization code flow We want an ID token with email/profile info The client requesting authentication Where the STS should send the code 2 3
  • 19. The redirect back to the client application 1 https://restograde.com/callback 2 ?code=ySVyktqNkEKJyyIjOKCVwCurNlGoRDcaLYEbW2j5WxZY The temporary authorization code 6 7
  • 20. The request to exchange the authorization code 1 POST /oauth/token 2 3 grant_type=authorization_code 4 &client_id=FN983CEYgx4mdUg3NKNKHjwfNAL5Fb42 5 &client_secret=6ODRv0g…OVOSWI 7 &redirect_uri=https://restograde.com/callback 8 &code=ySVyktqNkEKJyyIjOKCVwCurNlGoRDcaLYEbW2j5WxZY 8 Indicates the code exchange request The client exchanging the code The client needs to authenticate to the STS The redirect URI used before The code received in step 7 pdr.online
  • 21. The response from the Security Token Service 1 { 2 "id_token": "eyJhbGciO...du6TY9w", 3 } 9 The identity token representing the authenticated user The identity token contains a sub claim with the user's unique identifier. The application can use this claim to lookup the user in its database and establish and authenticated session pdr.online
  • 22. Handle tokens according to the use case at hand 4 3 Request to the STS to initialize the flow I know you! Follow this redirect back to the application! 7 1 Follow redirect to the application's callback endpoint Request that triggers the initialization of the flow 8 A server-to-server request to exchange the authorization co de from step 7 9 Relevant tokens for this particular use case 10 Session Cookies The STS uses cookies to keep track of the authenticated user. Every subsequent request from the browser to the STS will carry this cookie, enabling session re-use and SSO. 2 Initialize the flow with the STS by redirecting the browser The backend can also use a cookie to store session id’s for authorized users.
  • 23. 1 Initialize the flow with the STS 2 Initialize the flow 3 Redirect with authorization code 4 Follow redirect with authorization code 7 A server-to-server request to exchange the authorization code 8 Relevant tokens associated with the victim user 10 Associate tokens with the attacker's account AN AUTHORIZATION CODE INJECTION ATTACK 5 Steal the authorization code 6 Send request to the callback with the stolen code
  • 24. 4 Initialize the flow and include the code challenge 6 7 5 I am Philippe with password FluffyDog17! Request to the STS to initialize the flow 9 Who are you? Please authenticate to me! Good. Now follow this redirect back to the application, so it can extract the authorization code from the URL 10 1 Follow redirect to the application's callback endpoint Request that triggers the initialization of the flow 11 Exchange the authorization code from step 10 and include the code verifier 13 Relevant tokens for this particular use case 14 Handle tokens according to the use case at hand THE AUTHORIZATION CODE FLOW WITH PKCE 2 Generate a random value (code verifier) and associate it with the user's session (e.g., keep in a cookie) 8 Store the code challenge along with the authorization code Calculate the SHA256 hash of the code verifier and compare to the stored code challenge 3 Calculate the SHA256 hash of the code verifier (code challenge) 12
  • 25. JWT Token • In Authorization code flow, JWT Tokens are received by the backend • JWT Tokens can also be used directly for REST API’s • “Authorization: Bearer “+ jwtToken
  • 27. Configure a Client application in an OIDC Provider Multiple OpenID Connect Providers • Azure AD, AWS Cognito, Google Account, GitHub • Okta, Auth0, OneLogin • For development: JBoss KeyCloak Need to register a client application • Allows access to user information • Client ID + Client Secret • Authorized callback URL’s • For spring: …/login/oauth2/code/{provider}
  • 28. Register an OAuth2 Client Github: • Set up Homepage URL • Authorization callback URL Keycloak: • Create Realm • Create Client • Configure callback URL • Add users
  • 29. Configure a Spring application for OIDC Login • spring-boot-starter-oauth2-client will autoconfigure OIDC logins. • spring-boot-starter-oauth2-resource-server will add support for REST API • issuer-uri has a /.well-known/openid-configuration path.
  • 30. Configure WebSecurity Authentication Default Authorities • Each logged in user has OIDC_USER • All OIDC scopes will be translated to SCOPE_name
  • 31. Debugging & Resources Debugging logging.level.org.springframework.securit= ydebug 1. Add and debug=true at your application.properties or application.yml 2. Add spring-boot-starter-actuator at your pom.xml 3. Go to http://localhost:8080/actuator
  • 32. Thank you for Listening!