Date and Time: 2023-10-20 16:27 Status:LearningIT Tags:API, Authentication and Authorization
OpenID Connect
OpenID Connect (OIDC) is an authentication protocol that adds an identity layer on top of OAuth 2.0. It helps securely authenticate users and enables applications to obtain user information from identity providers. OIDC is often used for Single Sign-On (SSO) scenarios, where a user only has to log in once in order to access multiple applications.
OIDC Components
OpenID Connect introduces several key terminologies and concepts that are essential to understand. These new terminologies include:
- Identity Provider (IdP) or OpenID Provider (OP):Â An Identity Provider is a service that authenticates users and provides identity information to relying parties (RPs) or client applications. The IdP is responsible for verifying the userâs identity.
- Relying Party (RP):Â A Relying Party, also known as a client application, is a web or mobile application that relies on the Identity Provider for user authentication and identity information. The RP requests authentication and user information from the IdP.
- End-User:Â The End-User is the person who interacts with the Relying Party and the Identity Provider. In OIDC, the End-User is the entity whose identity is being authenticated and whose information is being accessed.
- Identity Token (ID Token):Â The ID Token is a JSON Web Token (JWT) issued by the Identity Provider after a successful user authentication. It contains information about the authenticated user, such as their user ID and name. The ID Token is the primary extension that OIDC makes to OAuth 2.0 to make authentication possible.
- Claims:Â Claims are user attributes or data points related to the authenticated End-User.
OIDC Steps
Step 1: Client registration
Before any OIDC interaction takes place, the Relying Party (RP) must be registered with the Identity Provider (IdP). During registration, the IdP provides the client with a client_id (a public identifier) and, optionally, a client_secret (a private key). The latter is often used for confidential clients (like web applications) to authenticate themselves to the IdP.
Step 2: Authentication request
Authentication begins when the End-User decides to log in using a third-party provider, such as Google or Facebook. OIDC makes an authentication request by relying on the authorization server as specified in the OAuth 2.0 specification, but it uses extension parameters and scopes defined by OIDC to request that the End-User be authenticated by the resource server. In this case, the resource server is an OIDC provider to the client. Some of these extension parameters are:
- Scopes:Â The client specifies scopes, which determine the type of information (âclaimsâ in OIDC terms) the client wants.Â
openid
 is a mandatory scope for OIDC, but othersâsuch asÂprofile
,Âemail
, orÂaddress
âcan also be requested. - Response Type:Â This parameter indicates what kind of authorization the client is seeking. For OIDC, the value is typicallyÂ
code
, which implies the client wants an authorization code that can later be exchanged for an ID Token and possibly an access token. - State:Â This parameter holds a random value generated by the client to prevent cross-site request forgery (CSRF) attacks. The IdP will send this value back in the response, allowing the client to ensure the validity of the response.
- Nonce:Â This random string is another security measure that will be included in the subsequent ID Token. The client can then verify the tokenâs authenticity and confirm that it wasnât reused.
Step 3: User authentication and consent
User authentication happens via the Identity Provider. The End-User is redirected to the IdP, which then authenticates the user, checks the requested scopes, and presents a consent screen if these scopes are not already granted to the client by the user.
Step 4: Authorization response
Upon successful authentication, the IdP redirects the user back to the client with an authorization code (if the response type was code
 in the authentication request) and a state. The state should match the one sent in the original request to ensure the integrity of the flow.
Step 5: Token request and response
The client is able to use the client_id
 and client_secret
 (optional) to authenticate itself with the IdP and exchange the obtained authorization code for tokens.
The IdP validates the provided authorization code and returns an ID Token, as well as an access/refresh token pair.
Step 6:Â UserInfo
 endpoint
The client uses the UserInfo
 endpoint when it needs more information (i.e., claims) about the End-User. The client sends the access token as a bearer token to the resource server, and the requested information within the granted scopes is returned to the client.
OAuth 2.0 and OpenID Connect
OAuth 2.0 and OpenID Connect
OAuth 2.0Â is an authorization framework that defines a token-based authorization process for how third-party applications can get consented access to usersâ data. OAuth 2.0 is a very powerful protocol for user authorization, but it does not define a clear and secure way to handle user authentication.
The OpenID protocol was introduced in 2005 as an open standard for single sign-on (SSO) and decentralized user authentication. It allowed users to log in to multiple websites using a single digital identity. An example of this type of flow is logging in to multiple websites using a Google account. OpenID defines how user authentication can be simplified, but it does not specify how user information should be securely exchanged between the client application and the identity provider.
The OpenID Foundation realized the need to integrate authentication into OAuth 2.0, and in 2014, they released the OpenID Connect protocol.
By combining the two, developers can leverage the authorization capabilities of OAuth 2.0 while obtaining verified user identity from OpenID Connect.
To achieve this synergy, OpenID Connect introduces new endpoints and token types to the OAuth 2.0 framework. It extends the standard OAuth 2.0 authorization flow by adding the ID token as an additional response. The ID token contains essential user information, allowing the client application to establish the userâs identity with confidence.
Once a user has authenticated with Identity Provider (IdP) or OpenID Provider (OP), subsequent requests to other applications that support OpenID Connect can leverage the existing session. This eliminates the need for the user to log in multiple times.
These protocols provide standardized mechanisms for handling authentication and authorization, reducing the complexity of implementation and promoting interoperability across various systems and platforms.
Link to original
OpenID and JSON Web Tokens
JWTs contain claims, which are statements (such as name or email address) about an entity (typically, the user) and additional metadata. The OpenID Connect specification defines a set of standard claims. The set of standard claims include name, email, gender, birth date, and so on. However, if you want to capture information about a user and there currently isnât a standard claim that best reflects this piece of information, you can create custom claims and add them to your tokens.
The OIDC middleware does not support JWTs signed with symmetric keys. Make sure you configure your app to use the RSA algorithm using public/private keys.
- Go to Dashboard > Settings.
- Click Show Advanced Settings.
- SetÂ
RS256
 as JsonWebToken Token Signature Algorithm and click Save.
OpenID Auth UseAuth
Reference:
https://openid.net/developers/how-connect-works/ https://blog.postman.com/what-is-openid-connect/