SlideShare a Scribd company logo
OAuth and why you should
use it?
Presented to you by Sergey Podgornyy
1
About me
Sergey Podgornyy
Sergey Podgornyy
Full-Stack Web Developer
2
Agenda
1. Authentication
2. Introduction to OAuth 2.0
3. OAuth roles
4. OAuth protocol flow
5. Grant types
6. Achieving statelessness with JWT
7. Stored token vs JWT vs OAuth
8. DEMO - Token Authentication With OAuth & JWT
9. OAuth/JWT Cookbook
3
Authentication
Authentication
verify the identity of the user given
the credentials received
Authorization
Authorization
determine if the user should be
granted access to a particular
resource
4
Are our applications secure?
5
However,time went
6
Introduction to OAuth 2.0
An open protocol to allow secure authentication in a
simple and standard method from web, mobile and a
desktop applications
7
Resource owner
the person or the application that holds the data to be shared
Resource server
the application that holds the protected resource
Authorization server
the application that verifies the identity of the users
Client
the application that makes request to RS on behalf of the RO
OAuth 2.0: roles
8
OAuth 2.0: protocol flow
I want to get the
Death Star plans
9
OAuth 2.0: protocol flow
Hey, backend, could you please give
me a Death Star plans?
10
OAuth 2.0: protocol flow
Sorry mate, this is a protected resource. You will
need to present me an access token
11
OAuth 2.0: protocol flow
Hi, can I get an access token please?
Backend is asking
12
OAuth 2.0: protocol flow
Sure thing sir! I just need to ask a few
details to the user first
13
OAuth 2.0: protocol flow
Hi, could you please provide me your
credentials? I need to verify your identity
14
OAuth 2.0: protocol flow
That's no problem at all. I am vader@gmail.com
and my password is deathToJedi
15
OAuth 2.0: protocol flow
The user is who claims to be. Here is your
access token:
qfE2KhvKggluHqe7IpTBqZ4qziTQQbKa
16
OAuth 2.0: protocol flow
Hey, backend, this is my token:
qfE2KhvKggluHqe7IpTBqZ4qziTQQbKa
17
OAuth 2.0: protocol flow
Hi, I've been given qfE2KhvKggluHqe7IpTBqZ4qziTQQbKa .
Could you please tell me who it belongs to?
18
OAuth 2.0: protocol flow
Of course. That token is still valid and it belongs to
vader@gmail.com
19
OAuth 2.0: protocol flow
Everything is allright. This is the
Death Star plans. Enjoy!
20
OAuth 2.0: protocol flow
Here you are the Death Star plans! Thank you for your
bussiness and have a good day!
21
OAuth 2.0: protocol flow
OAuth 2.0 is a delegation protocol, as this guy
has no idea about the credentials of this guy
22
OAuth 2.0: grant types
1. Authorization code: for web server applications
2. Implicit: for JS front-end and mobile apps
3. Resource owner password credentials: for trusted clients
4. Client credentials: for service authentication
23
Authorization code grant
Involves the user granting the client an authorization code, which can be
exchanged for an Access Token
24
Implicit grant
25
Password credentials grant
26
Client credentials grant
This grant is suitable for machine-to-machine authentication where a specific
user’s permission to access data is not required
27
Responce example
{
"access_token": "RsT5OjbzRn430zqMLgV3Ia",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "e1qoXg7Ik2RRua48lXIV"
}
Except Implicit grant, where authorization server returns only an access token
01.
02.
03.
04.
05.
06.
“
28
Which OAuth 2.0 grant should I use?
Start
Client Credentials
Grant
Authorization
Code Grant
Implicit Grant
Password Grant
Access token
owner?
Client type?
First party or
third party client?
First party or
third party client?
Machine
User
User-agent-based
app
First party
First party
Third party
Third party
Web app
Native app
29
Tips for a front-end application
• Use the implicit grant
• Use HTML5's localStorage for access and refresh
tokens
30
RsT5OjbzRn430zqMLgV3Ia
Accessing the protected resource
Once the client has an access token, it can request a protected resource
GET /death-star/plans HTTP/1.1
Host: api.example.org
Authorization: Bearer
31
More grants???
Token expiration and Refresh
• If the Authorization server issues expiring tokens, they can be paired with
refresh tokens
• When the access token has expired, the refresh token can be used to get a
new access token
32
Stateful vs Stateless
• Authorization Servers are often stateful services
• They stored issued access token for future checking
• How can we achieve statelessness?
• Using JWT tokens as access tokens
33
RsT5OjbzRn430zqMLg
JWT and when it can be useful?
JWT (JSON Web Token) is a secure way to encapsulate arbitrary data that can be
sent over unsecure URL's
POST /transfer HTTP/1.1
from=acc1&to=acc2&amount=1000
vs
POST /transfer HTTP/1.1 {
"from": "acc1",
"to": "acc2",
"amount": 1000
}
“
01.
02.
03.
04.
05.
34
How does a JWT look like?
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
eyJleHAiOjE0MTY0NzE5MzQsInVzZXJfbmFtZSI6InVzZXIiLCJzY29
wZSI6WyJyZWFkIiwid3JpdGUiXSwiYXV0aG9yaXRpZXMiOlsiUk9MRV
9BRE1JTiIsIlJPTEVfVVNFUiJdLCJqdGkiOiI5YmM5MmE0NC0wYjFhL
TRjNWUtYmU3MC1kYTUyMDc1YjlhODQiLCJjbGllbnRfaWQiOiJteS1j
bGllbnQtd2l0aC1zZWNyZXQifQ.
AZCTD_fiCcnrQR5X7rJBQ5rO-2Qedc5_3qJJf-ZCvVY
Header Claims Signature
35
JWT Header
{
"alg": "HS256",
"typ": "JWT"
}
01.
02.
03.
04.
36
JWT Claims
{
"exp": 1416471934,
"user_name": "user",
"scope": [
"read",
"write"
],
"authorities": [
"ROLE_ADMIN",
"ROLE_USER"
],
"jti": "9bc92a44-0b1a-4c5e-be70-da52075b9a84",
"client_id": "my-client-with-secret"
}
01.
02.
03.
04.
05.
06.
07.
08.
09.
10.
11.
12.
13.
14.
37
JWT Signature
HMACSHA256(
base64(header) + "." + base64(payload),
"secret"
)
38
Sample access token response
{
"access_token": "eyJhbGciOiJIUzI1NiJ9.
eyJleHAiOjE0MTY0NzEwNTUsInVzZXJfbmFtZSI6InVzZXIiLCJzY29wZS
I6WyJyZWFkIiwid3JpdGUiXSwiYXV0aG9yaXRpZXMiOlsiUk9MRV9BRE1J
TiIsIlJPTEVfVVNFUiJdLCJqdGkiOiIzZGJjODE4Yi0wMjAyLTRiYzItYT
djZi1mMmZlNjY4MjAyMmEiLCJjbGllbnRfaWQiOiJteS1jbGllbnQtd2l0
aC1zZWNyZXQifQ.
Wao_6hLnOeMHS4HEel1UGWt1g86ad9N0qCexr1IL7IM",
"token_type": "bearer",
"expires_in": 43199,
"scope": "read write",
"jti": "3dbc818b-0202-4bc2-a7cf-f2fe6682022a"
}
01.
02.
03.
04.
05.
06.
07.
39
Achieving statelessness
• Instead of storing access token / principal relationship in a stateful way, do
it on a JWT
• Access tokens with the JWT-encoded principal can be securely stored on the
client's browser
• That way you are achieving one of the basic principal of RE S T :
State Transfer
40
So why I should use
OAuth?
41
Session IDs / Cookies
Pros
• Easy to code both the client and server
• Easy to destroy a session when someone logs out
Cons
• The server side periodically needs to delete expired sessions where the
client didn't logout
• Every HTTP request requires a lookup to the data store
• Storage requirements grow as more users have active sessions
• Sometimes you need to have multiple server, and session data needs to be
accessible by all of them
42
JSON Web Tokens (JWT)
Pros
• The server side storage issues are gone
• The client side code is easy
Cons
• The JWT size could be larger than a session ID. It could affect network performance
• The data stored in the JWT is readable by the client
• The server side needs code to generate, validate, and read JWTs
• Anyone who gets a copy of the signing key can create JWTs. You might not know when this
happens
• There was (is?) a bug in some libraries that accepted any JWT signed with the "none" algorithm
• In order to revoke a JWT before it expires you need to use a revocation list. This gets you back to
the server side storage issues you were trying to avoid
43
OAuth
Pros
• No code for users to signup or reset their password
• No code to send an email with a validation link
• Users do not need to learn/write-down another username and password
Cons
• If third party service goes down or they discontinue it then you need to figure something else out
how do you migrate the user's account data if their identity changes from "foo@a.com" to "bar@b.com"?
• Usually you have to write code for each provider
• You or your users might have privacy concerns on your system. The providers know which of their
users use your service
• You are trusting the provider. It is possible for a provider to issue tokens that are valid for one user
to someone else
44
DEMO
45
See more on GitHub
46
Cookbook
47
Node.js Cookbook
Passport.js
npm install passport
Supported by
48
PHP Cookbook
composer require league/oauth2-client
composer require league/oauth2-server
49
Useful links
• The OAuth 2.0 Authorization
Framework
• OAuth 2.0 Threat Model and
Security Considerations
• JSON Web Token (JWT)
• Alex Bilbie blog
• OAuthLib documentation (.py lib)
50
End of presentation this is!
Any question do you have?
51

More Related Content

What's hot

What the Heck is OAuth and OIDC - UberConf 2018
What the Heck is OAuth and OIDC - UberConf 2018What the Heck is OAuth and OIDC - UberConf 2018
What the Heck is OAuth and OIDC - UberConf 2018
Matt Raible
 
Full stack security
Full stack securityFull stack security
Full stack security
DPC Consulting Ltd
 
CIS14: Developing with OAuth and OIDC Connect
CIS14: Developing with OAuth and OIDC ConnectCIS14: Developing with OAuth and OIDC Connect
CIS14: Developing with OAuth and OIDC Connect
CloudIDSummit
 
OAuth Base Camp
OAuth Base CampOAuth Base Camp
OAuth Base Camp
Oliver Pfaff
 
Token Based Authentication Systems with AngularJS & NodeJS
Token Based Authentication Systems with AngularJS & NodeJSToken Based Authentication Systems with AngularJS & NodeJS
Token Based Authentication Systems with AngularJS & NodeJS
Hüseyin BABAL
 
Stateless authentication for microservices - Spring I/O 2015
Stateless authentication for microservices  - Spring I/O 2015Stateless authentication for microservices  - Spring I/O 2015
Stateless authentication for microservices - Spring I/O 2015
Alvaro Sanchez-Mariscal
 
Browser fingerprinting without cookies
Browser fingerprinting without cookiesBrowser fingerprinting without cookies
Browser fingerprinting without cookies
Aseem Rohatgi
 
Json web token api authorization
Json web token api authorizationJson web token api authorization
Json web token api authorization
Giulio De Donato
 
Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Stateless authentication with OAuth 2 and JWT - JavaZone 2015Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Alvaro Sanchez-Mariscal
 
Introduction to OAuth
Introduction to OAuthIntroduction to OAuth
Introduction to OAuthPaul Osman
 
Stateless authentication for microservices - Greach 2015
Stateless authentication for microservices - Greach 2015Stateless authentication for microservices - Greach 2015
Stateless authentication for microservices - Greach 2015
Alvaro Sanchez-Mariscal
 
Esquema de pasos de ejecución IdM
Esquema de pasos de ejecución IdMEsquema de pasos de ejecución IdM
Esquema de pasos de ejecución IdM
Fernando Lopez Aguilar
 
アプリ開発で知っておきたい認証技術 - OAuth 1.0 + OAuth 2.0 + OpenID Connect -
アプリ開発で知っておきたい認証技術 - OAuth 1.0 + OAuth 2.0 + OpenID Connect -アプリ開発で知っておきたい認証技術 - OAuth 1.0 + OAuth 2.0 + OpenID Connect -
アプリ開発で知っておきたい認証技術 - OAuth 1.0 + OAuth 2.0 + OpenID Connect -
Naoki Nagazumi
 
Getting Started with Spring Authorization Server
Getting Started with Spring Authorization ServerGetting Started with Spring Authorization Server
Getting Started with Spring Authorization Server
VMware Tanzu
 
OAuth1.0
OAuth1.0OAuth1.0
Cracking JWT tokens: a tale of magic, Node.JS and parallel computing - Node.j...
Cracking JWT tokens: a tale of magic, Node.JS and parallel computing - Node.j...Cracking JWT tokens: a tale of magic, Node.JS and parallel computing - Node.j...
Cracking JWT tokens: a tale of magic, Node.JS and parallel computing - Node.j...
Luciano Mammino
 
RFC6749 et alia 20130504
RFC6749 et alia 20130504RFC6749 et alia 20130504
RFC6749 et alia 20130504
Mattias Jidhage
 
Demystifying OAuth 2.0
Demystifying OAuth 2.0Demystifying OAuth 2.0
Demystifying OAuth 2.0
Karl McGuinness
 
Authentication and Authorization Architecture in the MEAN Stack
Authentication and Authorization Architecture in the MEAN StackAuthentication and Authorization Architecture in the MEAN Stack
Authentication and Authorization Architecture in the MEAN Stack
FITC
 
RoadSec 2017 - Trilha AppSec - APIs Authorization
RoadSec 2017 - Trilha AppSec - APIs AuthorizationRoadSec 2017 - Trilha AppSec - APIs Authorization
RoadSec 2017 - Trilha AppSec - APIs Authorization
Erick Belluci Tedeschi
 

What's hot (20)

What the Heck is OAuth and OIDC - UberConf 2018
What the Heck is OAuth and OIDC - UberConf 2018What the Heck is OAuth and OIDC - UberConf 2018
What the Heck is OAuth and OIDC - UberConf 2018
 
Full stack security
Full stack securityFull stack security
Full stack security
 
CIS14: Developing with OAuth and OIDC Connect
CIS14: Developing with OAuth and OIDC ConnectCIS14: Developing with OAuth and OIDC Connect
CIS14: Developing with OAuth and OIDC Connect
 
OAuth Base Camp
OAuth Base CampOAuth Base Camp
OAuth Base Camp
 
Token Based Authentication Systems with AngularJS & NodeJS
Token Based Authentication Systems with AngularJS & NodeJSToken Based Authentication Systems with AngularJS & NodeJS
Token Based Authentication Systems with AngularJS & NodeJS
 
Stateless authentication for microservices - Spring I/O 2015
Stateless authentication for microservices  - Spring I/O 2015Stateless authentication for microservices  - Spring I/O 2015
Stateless authentication for microservices - Spring I/O 2015
 
Browser fingerprinting without cookies
Browser fingerprinting without cookiesBrowser fingerprinting without cookies
Browser fingerprinting without cookies
 
Json web token api authorization
Json web token api authorizationJson web token api authorization
Json web token api authorization
 
Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Stateless authentication with OAuth 2 and JWT - JavaZone 2015Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Stateless authentication with OAuth 2 and JWT - JavaZone 2015
 
Introduction to OAuth
Introduction to OAuthIntroduction to OAuth
Introduction to OAuth
 
Stateless authentication for microservices - Greach 2015
Stateless authentication for microservices - Greach 2015Stateless authentication for microservices - Greach 2015
Stateless authentication for microservices - Greach 2015
 
Esquema de pasos de ejecución IdM
Esquema de pasos de ejecución IdMEsquema de pasos de ejecución IdM
Esquema de pasos de ejecución IdM
 
アプリ開発で知っておきたい認証技術 - OAuth 1.0 + OAuth 2.0 + OpenID Connect -
アプリ開発で知っておきたい認証技術 - OAuth 1.0 + OAuth 2.0 + OpenID Connect -アプリ開発で知っておきたい認証技術 - OAuth 1.0 + OAuth 2.0 + OpenID Connect -
アプリ開発で知っておきたい認証技術 - OAuth 1.0 + OAuth 2.0 + OpenID Connect -
 
Getting Started with Spring Authorization Server
Getting Started with Spring Authorization ServerGetting Started with Spring Authorization Server
Getting Started with Spring Authorization Server
 
OAuth1.0
OAuth1.0OAuth1.0
OAuth1.0
 
Cracking JWT tokens: a tale of magic, Node.JS and parallel computing - Node.j...
Cracking JWT tokens: a tale of magic, Node.JS and parallel computing - Node.j...Cracking JWT tokens: a tale of magic, Node.JS and parallel computing - Node.j...
Cracking JWT tokens: a tale of magic, Node.JS and parallel computing - Node.j...
 
RFC6749 et alia 20130504
RFC6749 et alia 20130504RFC6749 et alia 20130504
RFC6749 et alia 20130504
 
Demystifying OAuth 2.0
Demystifying OAuth 2.0Demystifying OAuth 2.0
Demystifying OAuth 2.0
 
Authentication and Authorization Architecture in the MEAN Stack
Authentication and Authorization Architecture in the MEAN StackAuthentication and Authorization Architecture in the MEAN Stack
Authentication and Authorization Architecture in the MEAN Stack
 
RoadSec 2017 - Trilha AppSec - APIs Authorization
RoadSec 2017 - Trilha AppSec - APIs AuthorizationRoadSec 2017 - Trilha AppSec - APIs Authorization
RoadSec 2017 - Trilha AppSec - APIs Authorization
 

Viewers also liked

Web Services with OAuth
Web Services with OAuthWeb Services with OAuth
Web Services with OAuth
Marcus Ramberg
 
Implementing OAuth
Implementing OAuthImplementing OAuth
Implementing OAuth
leahculver
 
OAuth - Open API Authentication
OAuth - Open API AuthenticationOAuth - Open API Authentication
OAuth - Open API Authentication
leahculver
 
REST API Security: OAuth 2.0, JWTs, and More!
REST API Security: OAuth 2.0, JWTs, and More!REST API Security: OAuth 2.0, JWTs, and More!
REST API Security: OAuth 2.0, JWTs, and More!
Stormpath
 
Securing RESTful APIs using OAuth 2 and OpenID Connect
Securing RESTful APIs using OAuth 2 and OpenID ConnectSecuring RESTful APIs using OAuth 2 and OpenID Connect
Securing RESTful APIs using OAuth 2 and OpenID Connect
Jonathan LeBlanc
 
An Introduction to OAuth 2
An Introduction to OAuth 2An Introduction to OAuth 2
An Introduction to OAuth 2
Aaron Parecki
 
Einstein 2286 Frases
Einstein 2286 FrasesEinstein 2286 Frases
Einstein 2286 FrasesJose Mario
 
Bcn agenda dones segona quinzena de març
Bcn   agenda dones segona quinzena de marçBcn   agenda dones segona quinzena de març
Bcn agenda dones segona quinzena de març
Dones en Xarxa
 
El futuro en la comunicación 1
El futuro en la comunicación 1El futuro en la comunicación 1
El futuro en la comunicación 1carlaornella
 
WOMANLIDERTIC Mesa 2 Mujeres liderando la economia digital. Alicia calvo Orange
WOMANLIDERTIC Mesa 2  Mujeres liderando la economia digital. Alicia calvo OrangeWOMANLIDERTIC Mesa 2  Mujeres liderando la economia digital. Alicia calvo Orange
WOMANLIDERTIC Mesa 2 Mujeres liderando la economia digital. Alicia calvo Orange
Dones en Xarxa
 
Xerrada: "La xarxa, en espai de participacio"
Xerrada: "La xarxa, en espai de participacio"Xerrada: "La xarxa, en espai de participacio"
Xerrada: "La xarxa, en espai de participacio"
Dones en Xarxa
 
Дмитрий Мартынов: О подписке на газеты и журналы в I полугодии 2017 года  и п...
Дмитрий Мартынов: О подписке на газеты и журналы в I полугодии 2017 года  и п...Дмитрий Мартынов: О подписке на газеты и журналы в I полугодии 2017 года  и п...
Дмитрий Мартынов: О подписке на газеты и журналы в I полугодии 2017 года  и п...
Ассоциация распространителей печатной продукции
 
Presentació de FEMITIC
Presentació de FEMITICPresentació de FEMITIC
Presentació de FEMITIC
Dones en Xarxa
 
Tax advisors
Tax advisors Tax advisors

Viewers also liked (20)

Web Services with OAuth
Web Services with OAuthWeb Services with OAuth
Web Services with OAuth
 
Implementing OAuth
Implementing OAuthImplementing OAuth
Implementing OAuth
 
OAuth - Open API Authentication
OAuth - Open API AuthenticationOAuth - Open API Authentication
OAuth - Open API Authentication
 
REST API Security: OAuth 2.0, JWTs, and More!
REST API Security: OAuth 2.0, JWTs, and More!REST API Security: OAuth 2.0, JWTs, and More!
REST API Security: OAuth 2.0, JWTs, and More!
 
Securing RESTful APIs using OAuth 2 and OpenID Connect
Securing RESTful APIs using OAuth 2 and OpenID ConnectSecuring RESTful APIs using OAuth 2 and OpenID Connect
Securing RESTful APIs using OAuth 2 and OpenID Connect
 
An Introduction to OAuth 2
An Introduction to OAuth 2An Introduction to OAuth 2
An Introduction to OAuth 2
 
Biejing Rosario
Biejing RosarioBiejing Rosario
Biejing Rosario
 
Beijing[1]
Beijing[1]Beijing[1]
Beijing[1]
 
Einstein 2286 Frases
Einstein 2286 FrasesEinstein 2286 Frases
Einstein 2286 Frases
 
Bcn agenda dones segona quinzena de març
Bcn   agenda dones segona quinzena de marçBcn   agenda dones segona quinzena de març
Bcn agenda dones segona quinzena de març
 
Chuyên
ChuyênChuyên
Chuyên
 
El futuro en la comunicación 1
El futuro en la comunicación 1El futuro en la comunicación 1
El futuro en la comunicación 1
 
WOMANLIDERTIC Mesa 2 Mujeres liderando la economia digital. Alicia calvo Orange
WOMANLIDERTIC Mesa 2  Mujeres liderando la economia digital. Alicia calvo OrangeWOMANLIDERTIC Mesa 2  Mujeres liderando la economia digital. Alicia calvo Orange
WOMANLIDERTIC Mesa 2 Mujeres liderando la economia digital. Alicia calvo Orange
 
Xerrada: "La xarxa, en espai de participacio"
Xerrada: "La xarxa, en espai de participacio"Xerrada: "La xarxa, en espai de participacio"
Xerrada: "La xarxa, en espai de participacio"
 
Дмитрий Мартынов: О подписке на газеты и журналы в I полугодии 2017 года  и п...
Дмитрий Мартынов: О подписке на газеты и журналы в I полугодии 2017 года  и п...Дмитрий Мартынов: О подписке на газеты и журналы в I полугодии 2017 года  и п...
Дмитрий Мартынов: О подписке на газеты и журналы в I полугодии 2017 года  и п...
 
Gandhi
GandhiGandhi
Gandhi
 
Presentació de FEMITIC
Presentació de FEMITICPresentació de FEMITIC
Presentació de FEMITIC
 
tp
tptp
tp
 
Partner With Shoes For Crews
Partner With Shoes For CrewsPartner With Shoes For Crews
Partner With Shoes For Crews
 
Tax advisors
Tax advisors Tax advisors
Tax advisors
 

Similar to OAuth and why you should use it

What the Heck is OAuth and OpenID Connect - DOSUG 2018
What the Heck is OAuth and OpenID Connect - DOSUG 2018What the Heck is OAuth and OpenID Connect - DOSUG 2018
What the Heck is OAuth and OpenID Connect - DOSUG 2018
Matt Raible
 
JHipster and Okta - JHipster Virtual Meetup December 2020
JHipster and Okta - JHipster Virtual Meetup December 2020JHipster and Okta - JHipster Virtual Meetup December 2020
JHipster and Okta - JHipster Virtual Meetup December 2020
Matt Raible
 
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
Justin Richer
 
What the Heck is OAuth and OpenID Connect - RWX 2017
What the Heck is OAuth and OpenID Connect - RWX 2017What the Heck is OAuth and OpenID Connect - RWX 2017
What the Heck is OAuth and OpenID Connect - RWX 2017
Matt Raible
 
apidays Helsinki & North 2023 - API authorization with Open Policy Agent, And...
apidays Helsinki & North 2023 - API authorization with Open Policy Agent, And...apidays Helsinki & North 2023 - API authorization with Open Policy Agent, And...
apidays Helsinki & North 2023 - API authorization with Open Policy Agent, And...
apidays
 
Distributed Authorization with Open Policy Agent.pdf
Distributed Authorization with Open Policy Agent.pdfDistributed Authorization with Open Policy Agent.pdf
Distributed Authorization with Open Policy Agent.pdf
Nordic APIs
 
Securing Web Applications with Token Authentication
Securing Web Applications with Token AuthenticationSecuring Web Applications with Token Authentication
Securing Web Applications with Token Authentication
Stormpath
 
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager
WSO2
 
JSON WEB TOKEN
JSON WEB TOKENJSON WEB TOKEN
JSON WEB TOKEN
Knoldus Inc.
 
Stateless authentication for microservices
Stateless authentication for microservicesStateless authentication for microservices
Stateless authentication for microservices
Alvaro Sanchez-Mariscal
 
OAuth2 and OpenID with Spring Boot
OAuth2 and OpenID with Spring BootOAuth2 and OpenID with Spring Boot
OAuth2 and OpenID with Spring Boot
Geert Pante
 
The OpenID Connect Protocol
The OpenID Connect ProtocolThe OpenID Connect Protocol
The OpenID Connect ProtocolClément OUDOT
 
GSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 ModuleGSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 ModuleMayank Sharma
 
Stateless authentication for microservices applications - JavaLand 2015
Stateless authentication for microservices applications -  JavaLand 2015Stateless authentication for microservices applications -  JavaLand 2015
Stateless authentication for microservices applications - JavaLand 2015
Alvaro Sanchez-Mariscal
 
OAuth2 Authorization Server Under the Hood
OAuth2 Authorization Server Under the HoodOAuth2 Authorization Server Under the Hood
OAuth2 Authorization Server Under the Hood
Lohika_Odessa_TechTalks
 
[4developers2016] - Security in the era of modern applications and services (...
[4developers2016] - Security in the era of modern applications and services (...[4developers2016] - Security in the era of modern applications and services (...
[4developers2016] - Security in the era of modern applications and services (...
PROIDEA
 
OAuth2 - Introduction
OAuth2 - IntroductionOAuth2 - Introduction
OAuth2 - Introduction
Knoldus Inc.
 
Complete Guide to Setup Secure Scheme for Restful APIs
Complete Guide to Setup Secure Scheme for Restful APIsComplete Guide to Setup Secure Scheme for Restful APIs
Complete Guide to Setup Secure Scheme for Restful APIs
Xing (Xingheng) Wang
 
JavaOne 2014 - Securing RESTful Resources with OAuth2
JavaOne 2014 - Securing RESTful Resources with OAuth2JavaOne 2014 - Securing RESTful Resources with OAuth2
JavaOne 2014 - Securing RESTful Resources with OAuth2
Rodrigo Cândido da Silva
 

Similar to OAuth and why you should use it (20)

What the Heck is OAuth and OpenID Connect - DOSUG 2018
What the Heck is OAuth and OpenID Connect - DOSUG 2018What the Heck is OAuth and OpenID Connect - DOSUG 2018
What the Heck is OAuth and OpenID Connect - DOSUG 2018
 
JHipster and Okta - JHipster Virtual Meetup December 2020
JHipster and Okta - JHipster Virtual Meetup December 2020JHipster and Okta - JHipster Virtual Meetup December 2020
JHipster and Okta - JHipster Virtual Meetup December 2020
 
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
 
What the Heck is OAuth and OpenID Connect - RWX 2017
What the Heck is OAuth and OpenID Connect - RWX 2017What the Heck is OAuth and OpenID Connect - RWX 2017
What the Heck is OAuth and OpenID Connect - RWX 2017
 
apidays Helsinki & North 2023 - API authorization with Open Policy Agent, And...
apidays Helsinki & North 2023 - API authorization with Open Policy Agent, And...apidays Helsinki & North 2023 - API authorization with Open Policy Agent, And...
apidays Helsinki & North 2023 - API authorization with Open Policy Agent, And...
 
Distributed Authorization with Open Policy Agent.pdf
Distributed Authorization with Open Policy Agent.pdfDistributed Authorization with Open Policy Agent.pdf
Distributed Authorization with Open Policy Agent.pdf
 
Securing Web Applications with Token Authentication
Securing Web Applications with Token AuthenticationSecuring Web Applications with Token Authentication
Securing Web Applications with Token Authentication
 
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager
 
JSON WEB TOKEN
JSON WEB TOKENJSON WEB TOKEN
JSON WEB TOKEN
 
Stateless authentication for microservices
Stateless authentication for microservicesStateless authentication for microservices
Stateless authentication for microservices
 
OAuth2 and OpenID with Spring Boot
OAuth2 and OpenID with Spring BootOAuth2 and OpenID with Spring Boot
OAuth2 and OpenID with Spring Boot
 
The OpenID Connect Protocol
The OpenID Connect ProtocolThe OpenID Connect Protocol
The OpenID Connect Protocol
 
GSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 ModuleGSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 Module
 
Presentation
PresentationPresentation
Presentation
 
Stateless authentication for microservices applications - JavaLand 2015
Stateless authentication for microservices applications -  JavaLand 2015Stateless authentication for microservices applications -  JavaLand 2015
Stateless authentication for microservices applications - JavaLand 2015
 
OAuth2 Authorization Server Under the Hood
OAuth2 Authorization Server Under the HoodOAuth2 Authorization Server Under the Hood
OAuth2 Authorization Server Under the Hood
 
[4developers2016] - Security in the era of modern applications and services (...
[4developers2016] - Security in the era of modern applications and services (...[4developers2016] - Security in the era of modern applications and services (...
[4developers2016] - Security in the era of modern applications and services (...
 
OAuth2 - Introduction
OAuth2 - IntroductionOAuth2 - Introduction
OAuth2 - Introduction
 
Complete Guide to Setup Secure Scheme for Restful APIs
Complete Guide to Setup Secure Scheme for Restful APIsComplete Guide to Setup Secure Scheme for Restful APIs
Complete Guide to Setup Secure Scheme for Restful APIs
 
JavaOne 2014 - Securing RESTful Resources with OAuth2
JavaOne 2014 - Securing RESTful Resources with OAuth2JavaOne 2014 - Securing RESTful Resources with OAuth2
JavaOne 2014 - Securing RESTful Resources with OAuth2
 

Recently uploaded

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 

OAuth and why you should use it

  • 1. OAuth and why you should use it? Presented to you by Sergey Podgornyy 1
  • 2. About me Sergey Podgornyy Sergey Podgornyy Full-Stack Web Developer 2
  • 3. Agenda 1. Authentication 2. Introduction to OAuth 2.0 3. OAuth roles 4. OAuth protocol flow 5. Grant types 6. Achieving statelessness with JWT 7. Stored token vs JWT vs OAuth 8. DEMO - Token Authentication With OAuth & JWT 9. OAuth/JWT Cookbook 3
  • 4. Authentication Authentication verify the identity of the user given the credentials received Authorization Authorization determine if the user should be granted access to a particular resource 4
  • 7. Introduction to OAuth 2.0 An open protocol to allow secure authentication in a simple and standard method from web, mobile and a desktop applications 7
  • 8. Resource owner the person or the application that holds the data to be shared Resource server the application that holds the protected resource Authorization server the application that verifies the identity of the users Client the application that makes request to RS on behalf of the RO OAuth 2.0: roles 8
  • 9. OAuth 2.0: protocol flow I want to get the Death Star plans 9
  • 10. OAuth 2.0: protocol flow Hey, backend, could you please give me a Death Star plans? 10
  • 11. OAuth 2.0: protocol flow Sorry mate, this is a protected resource. You will need to present me an access token 11
  • 12. OAuth 2.0: protocol flow Hi, can I get an access token please? Backend is asking 12
  • 13. OAuth 2.0: protocol flow Sure thing sir! I just need to ask a few details to the user first 13
  • 14. OAuth 2.0: protocol flow Hi, could you please provide me your credentials? I need to verify your identity 14
  • 15. OAuth 2.0: protocol flow That's no problem at all. I am vader@gmail.com and my password is deathToJedi 15
  • 16. OAuth 2.0: protocol flow The user is who claims to be. Here is your access token: qfE2KhvKggluHqe7IpTBqZ4qziTQQbKa 16
  • 17. OAuth 2.0: protocol flow Hey, backend, this is my token: qfE2KhvKggluHqe7IpTBqZ4qziTQQbKa 17
  • 18. OAuth 2.0: protocol flow Hi, I've been given qfE2KhvKggluHqe7IpTBqZ4qziTQQbKa . Could you please tell me who it belongs to? 18
  • 19. OAuth 2.0: protocol flow Of course. That token is still valid and it belongs to vader@gmail.com 19
  • 20. OAuth 2.0: protocol flow Everything is allright. This is the Death Star plans. Enjoy! 20
  • 21. OAuth 2.0: protocol flow Here you are the Death Star plans! Thank you for your bussiness and have a good day! 21
  • 22. OAuth 2.0: protocol flow OAuth 2.0 is a delegation protocol, as this guy has no idea about the credentials of this guy 22
  • 23. OAuth 2.0: grant types 1. Authorization code: for web server applications 2. Implicit: for JS front-end and mobile apps 3. Resource owner password credentials: for trusted clients 4. Client credentials: for service authentication 23
  • 24. Authorization code grant Involves the user granting the client an authorization code, which can be exchanged for an Access Token 24
  • 27. Client credentials grant This grant is suitable for machine-to-machine authentication where a specific user’s permission to access data is not required 27
  • 28. Responce example { "access_token": "RsT5OjbzRn430zqMLgV3Ia", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "e1qoXg7Ik2RRua48lXIV" } Except Implicit grant, where authorization server returns only an access token 01. 02. 03. 04. 05. 06. “ 28
  • 29. Which OAuth 2.0 grant should I use? Start Client Credentials Grant Authorization Code Grant Implicit Grant Password Grant Access token owner? Client type? First party or third party client? First party or third party client? Machine User User-agent-based app First party First party Third party Third party Web app Native app 29
  • 30. Tips for a front-end application • Use the implicit grant • Use HTML5's localStorage for access and refresh tokens 30
  • 31. RsT5OjbzRn430zqMLgV3Ia Accessing the protected resource Once the client has an access token, it can request a protected resource GET /death-star/plans HTTP/1.1 Host: api.example.org Authorization: Bearer 31
  • 32. More grants??? Token expiration and Refresh • If the Authorization server issues expiring tokens, they can be paired with refresh tokens • When the access token has expired, the refresh token can be used to get a new access token 32
  • 33. Stateful vs Stateless • Authorization Servers are often stateful services • They stored issued access token for future checking • How can we achieve statelessness? • Using JWT tokens as access tokens 33
  • 34. RsT5OjbzRn430zqMLg JWT and when it can be useful? JWT (JSON Web Token) is a secure way to encapsulate arbitrary data that can be sent over unsecure URL's POST /transfer HTTP/1.1 from=acc1&to=acc2&amount=1000 vs POST /transfer HTTP/1.1 { "from": "acc1", "to": "acc2", "amount": 1000 } “ 01. 02. 03. 04. 05. 34
  • 35. How does a JWT look like? eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. eyJleHAiOjE0MTY0NzE5MzQsInVzZXJfbmFtZSI6InVzZXIiLCJzY29 wZSI6WyJyZWFkIiwid3JpdGUiXSwiYXV0aG9yaXRpZXMiOlsiUk9MRV 9BRE1JTiIsIlJPTEVfVVNFUiJdLCJqdGkiOiI5YmM5MmE0NC0wYjFhL TRjNWUtYmU3MC1kYTUyMDc1YjlhODQiLCJjbGllbnRfaWQiOiJteS1j bGllbnQtd2l0aC1zZWNyZXQifQ. AZCTD_fiCcnrQR5X7rJBQ5rO-2Qedc5_3qJJf-ZCvVY Header Claims Signature 35
  • 36. JWT Header { "alg": "HS256", "typ": "JWT" } 01. 02. 03. 04. 36
  • 37. JWT Claims { "exp": 1416471934, "user_name": "user", "scope": [ "read", "write" ], "authorities": [ "ROLE_ADMIN", "ROLE_USER" ], "jti": "9bc92a44-0b1a-4c5e-be70-da52075b9a84", "client_id": "my-client-with-secret" } 01. 02. 03. 04. 05. 06. 07. 08. 09. 10. 11. 12. 13. 14. 37
  • 38. JWT Signature HMACSHA256( base64(header) + "." + base64(payload), "secret" ) 38
  • 39. Sample access token response { "access_token": "eyJhbGciOiJIUzI1NiJ9. eyJleHAiOjE0MTY0NzEwNTUsInVzZXJfbmFtZSI6InVzZXIiLCJzY29wZS I6WyJyZWFkIiwid3JpdGUiXSwiYXV0aG9yaXRpZXMiOlsiUk9MRV9BRE1J TiIsIlJPTEVfVVNFUiJdLCJqdGkiOiIzZGJjODE4Yi0wMjAyLTRiYzItYT djZi1mMmZlNjY4MjAyMmEiLCJjbGllbnRfaWQiOiJteS1jbGllbnQtd2l0 aC1zZWNyZXQifQ. Wao_6hLnOeMHS4HEel1UGWt1g86ad9N0qCexr1IL7IM", "token_type": "bearer", "expires_in": 43199, "scope": "read write", "jti": "3dbc818b-0202-4bc2-a7cf-f2fe6682022a" } 01. 02. 03. 04. 05. 06. 07. 39
  • 40. Achieving statelessness • Instead of storing access token / principal relationship in a stateful way, do it on a JWT • Access tokens with the JWT-encoded principal can be securely stored on the client's browser • That way you are achieving one of the basic principal of RE S T : State Transfer 40
  • 41. So why I should use OAuth? 41
  • 42. Session IDs / Cookies Pros • Easy to code both the client and server • Easy to destroy a session when someone logs out Cons • The server side periodically needs to delete expired sessions where the client didn't logout • Every HTTP request requires a lookup to the data store • Storage requirements grow as more users have active sessions • Sometimes you need to have multiple server, and session data needs to be accessible by all of them 42
  • 43. JSON Web Tokens (JWT) Pros • The server side storage issues are gone • The client side code is easy Cons • The JWT size could be larger than a session ID. It could affect network performance • The data stored in the JWT is readable by the client • The server side needs code to generate, validate, and read JWTs • Anyone who gets a copy of the signing key can create JWTs. You might not know when this happens • There was (is?) a bug in some libraries that accepted any JWT signed with the "none" algorithm • In order to revoke a JWT before it expires you need to use a revocation list. This gets you back to the server side storage issues you were trying to avoid 43
  • 44. OAuth Pros • No code for users to signup or reset their password • No code to send an email with a validation link • Users do not need to learn/write-down another username and password Cons • If third party service goes down or they discontinue it then you need to figure something else out how do you migrate the user's account data if their identity changes from "foo@a.com" to "bar@b.com"? • Usually you have to write code for each provider • You or your users might have privacy concerns on your system. The providers know which of their users use your service • You are trusting the provider. It is possible for a provider to issue tokens that are valid for one user to someone else 44
  • 46. See more on GitHub 46
  • 48. Node.js Cookbook Passport.js npm install passport Supported by 48
  • 49. PHP Cookbook composer require league/oauth2-client composer require league/oauth2-server 49
  • 50. Useful links • The OAuth 2.0 Authorization Framework • OAuth 2.0 Threat Model and Security Considerations • JSON Web Token (JWT) • Alex Bilbie blog • OAuthLib documentation (.py lib) 50
  • 51. End of presentation this is! Any question do you have? 51