OAuth2/OpenID Connect (OIDC)#
Sources#
The colored mermaids diagram are Joerg’s creations, drawing from https://medium.com/identity-beyond-borders/oauth-2-0-basics-3d06bce33870
The fine ASCII art is from the RFC itself, https://datatracker.ietf.org/doc/html/rfc6749
Roles/Participants#
Resource server: the server holding valuable resources, e.g. user info or cat pictures
Client application: a service that wants to access something, e.g. a printing service
Resource owner / User / Browser: typically a human that has control over the valuable resources on the server. Clicks the web in the browser.
Authorization server: a service that grants access tokens. Trusted by the resource server.
OAuth flows#
Preparation#
Done as a preparation in all following scenarios
Implicit#
Insecure, better use authorization code
+----------+
| Resource |
| Owner |
| |
+----------+
^
|
(B)
+----|-----+ Client Identifier +---------------+
| -+----(A)-- & Redirection URI --->| |
| User- | | Authorization |
| Agent -|----(B)-- User authenticates -->| Server |
| | | |
| |<---(C)--- Redirection URI ----<| |
| | with Access Token +---------------+
| | in Fragment
| | +---------------+
| |----(D)--- Redirection URI ---->| Web-Hosted |
| | without Fragment | Client |
| | | Resource |
| (F) |<---(E)------- Script ---------<| |
| | +---------------+
+-|--------+
| |
(A) (G) Access Token
| |
^ v
+---------+
| |
| Client |
| |
+---------+
Note: The lines illustrating steps (A) and (B) are broken into two
parts as they pass through the user-agent.
(A) The client initiates the flow by directing the resource owner's
user-agent to the authorization endpoint. The client includes
its client identifier, requested scope, local state, and a
redirection URI to which the authorization server will send the
user-agent back once access is granted (or denied).
(B) The authorization server authenticates the resource owner (via
the user-agent) and establishes whether the resource owner
grants or denies the client's access request.
(C) Assuming the resource owner grants access, the authorization
server redirects the user-agent back to the client using the
redirection URI provided earlier. The redirection URI includes
the access token in the URI fragment.
(D) The user-agent follows the redirection instructions by making a
request to the web-hosted client resource (which does not
include the fragment per [RFC2616]). The user-agent retains the
fragment information locally.
(E) The web-hosted client resource returns a web page (typically an
HTML document with an embedded script) capable of accessing the
full redirection URI including the fragment retained by the
user-agent, and extracting the access token (and other
parameters) contained in the fragment.
(F) The user-agent executes the script provided by the web-hosted
client resource locally, which extracts the access token.
(G) The user-agent passes the access token to the client.
from https://datatracker.ietf.org/doc/html/rfc6749#section-4.2
Password#
Getting even worse then implicit.
+----------+
| Resource |
| Owner |
| |
+----------+
v
| Resource Owner
(A) Password Credentials
|
v
+---------+ +---------------+
| |>--(B)---- Resource Owner ------->| |
| | Password Credentials | Authorization |
| Client | | Server |
| |<--(C)---- Access Token ---------<| |
| | (w/ Optional Refresh Token) | |
+---------+ +---------------+
Figure 5: Resource Owner Password Credentials Flow
The flow illustrated in Figure 5 includes the following steps:
(A) The resource owner provides the client with its username and
password.
(B) The client requests an access token from the authorization
server's token endpoint by including the credentials received
from the resource owner. When making the request, the client
authenticates with the authorization server.
(C) The authorization server authenticates the client and validates
the resource owner credentials, and if valid, issues an access
token.
from https://datatracker.ietf.org/doc/html/rfc6749#section-4.3
Client credentials#
The client application is the resource owner. No human involved
+---------+ +---------------+
| | | |
| |>--(A)- Client Authentication --->| Authorization |
| Client | | Server |
| |<--(B)---- Access Token ---------<| |
| | | |
+---------+ +---------------+
Figure 6: Client Credentials Flow
The flow illustrated in Figure 6 includes the following steps:
(A) The client authenticates with the authorization server and
requests an access token from the token endpoint.
(B) The authorization server authenticates the client, and if valid,
issues an access token.
from https://datatracker.ietf.org/doc/html/rfc6749#section-4.4
OpenID Connect (OIDC)#
On top of OAuth2. Looks quite similar.
The id token in (6) is the crucial bit. The client can access resources after this as well, because the client also received an access token
Reading materials#
https://developer.okta.com/blog/2019/10/21/illustrated-guide-to-oauth-and-oidc
https://www.onelogin.com/blog/openid-connect-explained-in-plain-english-2
https://connect2id.com/learn/openid-connect, especially https://connect2id.com/learn/openid-connect#example-auth-code-flow
https://hutten.knut.univention.de/mediawiki/index.php/Uttuusch (search for “Erik”)