An overview of the OpenID Connect hybrid flow as well as of the authorization and token endpoint requests.

OpenID Connect Hybrid Flow

On this page

The hybrid flow is an OpenID Connect flow that incorporates characteristics of both the implicit flow and the authorization code flow. It enables clients to obtain ID tokens straight from the authorization endpoint (via front-channel), while still being able to obtain access and refresh tokens from the token endpoint (via back-channel). This makes the hybrid flow particularly suitable for applications needing a balance between security and responsiveness.

This article explains the main components of the hybrid flow and how it combines the implicit flow for the ID token with the authorization code flow for the access token.

Best Practices

The OAuth implicit flow is deprecated. As a result, do not include the string token in the response_type request parameter. Only use code id_token for the hybrid flow. If possible, rely on the code flow to retrieve all tokens

How the OIDC Hybrid Flow Works

Authorization Request and Response

An example of the Hybrid Flow, incorporating characteristics of both the Implicit flow and the Authorization Code flow, part 1
  1. The browser redirects to the authorization endpoint at the token service of the authorization server.

  2. If the user is not yet authenticated, the token service redirects to the authentication service.

  3. The user authenticates and is redirected back to the token service.

  4. The authorization server redirects back to the client with appropriate parameters in the response, based on the value of the response_type request parameter:

    • If the client used code id_token, then the server returns the authorization code and an ID token.

Token Request and Response

An example of the Hybrid Flow, incorporating characteristics of both the Implicit flow and the Authorization Code flow, part 2
  1. The client sends the authorization code to the token endpoint, like in the authorization code flow.
  2. The authorization server returns tokens, typically including the access token and the ID token. If the server settings permit, the authorization server also issues a refresh token.

User Authentication

The user is authenticated during the authorization flow. Neither the OAuth nor the OpenID Connect specifications define the particulars for user authentication. It may thus involve any authentication method or multiple factors. Modern authorization servers apply conditional authentication, which adapts the flow depending on the context. In the Curity Identity Server, all user authentication is configured in the Authentication Service ensuring fine-grained control over authentication policies.

Client Authentication

In the hybrid flow, the client is not authenticated when calling the authorization endpoint but is identified through the redirect URI. The client must authenticate at the token endpoint, though, just like in the authorization code flow. Thanks to that, the client can obtain access tokens and longer-lived refresh tokens using the back-channel during the hybrid flow.

The Access Token

The authorization server should not return any access tokens through the front-channel (i.e., as part of the browser redirect). Instead, the client should fetch access tokens in a back-channel request from the token endpoint. The authorization server may return a refresh token as well.

The Curity Identity Server supports returning access tokens in the front-channel. However, such tokens are limited in terms of scope, lifetime, and audience to mitigate security risks. For the same reason, the Curity Identity Server does not return refresh tokens in the front-channel.

The Refresh Token

The authorization server can, depending on its policies, return refresh tokens to the client. This token can be used to obtain more access tokens once the first one expires. The refresh token may have a very long lifetime, ranging from hours to years.

The refresh token can only be obtained from the token endpoint; the Curity Identity Server will never return it from the authorization endpoint.

The Authorization Request

  • Method: GET
  • Agent: Browser
  • Response Type: Redirect to pre-registered callback URI at client with parameters in the fragment

The following table outlines the parameters for the front-channel communication in the hybrid flow.

Request Parameters

ParameterValueMandatoryDescription
client_idThe client IDyesThe ID of the requesting client.
response_typecode id_token*yesDefines the flow type: hybrid flow.
stateA random valuenoWill be provided back to the client in (4). Useful to keep track of the session in the client or to prevent unsolicited flows.
scopeSpace-separated string of scopesyes*List the scopes the client is requesting access to. *Mandatory if ID token is requested in the response_type.
redirect_uriThe client callback URLyesThe URI that the client wants the authorization response in step (4) to redirect to.
nonceA random valueyes*A value that is used to mitigate replay attacks. *Mandatory if ID token is requested in the response_type.
code_challengeA high entropy random challengeyes*A challenge generated by the client, if sent, the code_verifier must be sent on the token call. *Part of PKCE (RFC 7636), recommended.
code_challenge_methodSHA256yes*The hash method to validate the PKCE (RFC 7636) flow. *Should be S256 and is then required if code_challenge method is included.

Response

The authorization server creates a redirect back to the redirect_uri. It provides the response parameters on the fragment part of the URL. This means that only the browser can access the values of the response. The client server will not receive these values.

ParameterValueMandatoryDescription
stateThe same value as given in the requestyes*The same value as the client sent in the request. Use to match request to the redirect response. *Mandatory if the state was sent in the request.
codeAn Authorization CodeyesAn authorization code, to be used in the token request.
id_tokenJSON Web Tokenyes*A JWT representing the ID token. *Mandatory if the ID token is requested in the response_type.

The Token Request

Request Parameters

  • Method: POST
  • Content-Type: application/x-www-form-urlencoded
  • Response Type: json

This represents the back-channel token exchange, providing enhanced confidentiality for sensitive tokens.

ParameterValueMandatoryDescription
client_idThe client IDyesThe ID of the requesting client.
client_secretThe client secretyes*The secret of the client. *Mandatory if client authentication is of type secret and the authentication is not done using basic authentication. Other methods of client authentication may require different parameters sent in the request.
grant_typeauthorization_codeyesTells the token endpoint to do the second part of the hybrid flow.
codeThe authorization codeyesThe code is given in the response to the authorization request.
redirect_uriThe callback URL of the ClientyesThe same redirect URI as was sent in the authorize request.
code_verifierThe verifier that matches the code_challengeno**Mandatory if code_challenge was used in the authorize request.

Response

  • Response Type: application/json
ParameterValueMandatoryDescription
access_tokenA newly issued access tokenyesThe resulting access token.
refresh_tokenA newly issued refresh tokennoOnly issued if the client is configured to receive refresh tokens.
expires_inExpiration in secondsyesThe time to live of the access token in seconds.
scopeSpace-separated stringnoIf not present, the requested scopes where issued. If present, the issued scopes may differ from the requested scopes.
token_typeBearer or other token typeyesDescribes how the token can be used. Most commonly bearer token usage.
id_tokenJSON Web TokennoJWT represents the ID token. Present if openid scope was requested and the user has given consent to this scope.

Key Takeaways

The OpenID Connect hybrid flow provides a flexible and secure mechanism for handling authentication and authorization in modern web and mobile applications. By combining features of the implicit and authorization code flows, it allows clients to receive tokens both immediately and through secure exchanges, ensuring an optimal balance of user experience and security. It is particularly valuable when applications require both immediate access and long-term session management through refresh tokens.

Photo of Michał Trojanowski

Michał Trojanowski

Product Marketing Engineer at Curity

Newsletter

Join our Newsletter

Get the latest on identity management, API Security and authentication straight to your inbox.

Newsletter

Start Free Trial

Try the Curity Identity Server for Free. Get up and running in 10 minutes.

Start Free Trial

Was this helpful?