OpenID Connect (OIDC) is an authentication layer built on top of the OAuth 2.0 framework.  It is specifically built to address the authentication use case. The major difference is that in addition to access token , the client gets an identity token which the client can use for information pertaining to identity.

The OpenID Connect specification defines a set of standard claims. The set of standard claims include name, email, gender, birth date. It also introduces userinfo endpoint,  an API that returns information about the user.

Having a valid id_token means that the user is authenticated. used for token based authentication in which cookies can carry self contained id_token with user information.

You can pass an ID Token around different components of your client (eg in microservices architecture) , and these components can use the ID Token to confirm that the user is authenticated and also to retrieve information about them.

OpenID Connect (OIDC) is used for both pure authentication use cases (only id token is required, access token are not required as 3rd party authorization not there)  and (authentication + authorization) use cases . 

Federated identity pattern with OIDC 

Federated identity pattern steps

The key advangate is that authentication is no longer inside the application. it is carved out as seprate service. this has multiple advantages. Read more about this pattern in this article Federated identity pattern.

OIDC Single Signon 

Hence all applications which trust the authserver will be able to do single sign on based on SSO cookie set by authentication server.The presense of the cookie will determine if the user has logged on to the device.

OIDC for authorization and authentication use case for 3rd party apps

The sequence diagram shows the flow for a 3rd party image editing software gaining access to user identity and data on google drive.

Here the user is both authenticating and authorizing, ie the user is not allready logged in.

Step 1.a (Request to authorization end point,response_type=code id_token and openid in scope)

https://auth-server.com/authorize?response_type=code& client_id=CLIENT_ID&redirect_uri=REDIRECT_URI&scope=openid&state=stxyxze&nonce=1234

The OIDC flow begins with the client directing the user to the authorization endpoint . The request parameters are

When the authorization request reaches the authorization server the auth server will

authorize

If the user allows then the authorization service will redirect the user to redirect uri with auth code and state

Step 1.b (Response from authorization end point , response_type=code id_token and openid in scope)

https://clientapp.com/redirectpage?code=AUTH_CODE&state=stxyxze&id_token=eyJo............

On receiving the redirect response  the client webserver server will

Step 2.a (Make POST request to token end point)

https://api.authorization-server.com/token?grant_type=authorization_code& code=AUTH_CODE& redirect_uri=REDIRECT_URI& client_id=CLIENT_ID& client_secret=CLIENT_SECRET

The client webserver will typically initiate a POST request to token end point to get access and/or id token with

Step 2.b (The token end point responds with access token and id token)

Step 3 - client uses access token to interact with resource server.

note that as per the spec

The resource server MUST validate the access token and ensure it has not expired and that its scope covers the requested resource. The methods used by the resource server to validate the access token (as well as any error responses) are beyond the scope of this specification, but generally involve an interaction or coordination between the resource server and the authorization server.

The reason why the spec does not cover how the access token is validated is that the interaction between resource server and authorization server is dependent upon the architecture of the deployment. For instance the authorization service and resource server may the the same or it may be distributed.

Attacks (CSRF/REPLAY)

Both authorization code injection attack (via CSRF on genunine user's browser) and authorization code repaly attack on attacker's browser can be blocked by establishing request and response(auth code) co-relation via the state parameter. while state paremter is oauth parameter and blocks attacks against authorization code, nonce introduced by oidc also does request response(id_token) co-relation and blocks injection and replay attack on id token (in implict and hybrid flow). In general in implicit/hybrid flow token exposure / interception by malicious client is always a risk as opposed to authorization code flow , where the exposed code is useless without client secret.

OpenID Connect Discovery

OpenID Connect defines a discovery mechanism, called OpenID Connect Discovery. OpenID Connect describes a metadata document (RFC) that contains most of the information required for an application to do sign in. This includes information such as the OpenID/OAuth endpoints to use and the location of the service's public keys. This document can be found by appending the discovery document path to the well known URL:

https://my-company-domain/.well-known/openid-configuration