Configuring OAuth2-OpenID Connect Single-Sign-On¶
OAuth 2.0 has three main phases. They are:
- Requesting an Authorization Grant
- Exchanging the Authorization Grant for an Access Token
- Accessing the resources using the obtained Access Token
OpenID Connect is another identity layer on top of OAuth 2.0. OAuth applications can get authentication event information over the IDToken and can get the extra claims of the authenticated user from the OpenID Connect UserInfo endpoint.
To enable OAuth support for your client application, you must first register your application. Follow the instructions below to add a new application.
Before you begin
You must first register a service provider. To register a service provider:
- Sign in to WSO2 Identity Server Management Console as an admin.
- On the Main menu, click Identity > Service Providers > Add.
- Enter a service provider name.
- Click Register. The Service Provider Details page appears.
Let's get started to configure the service provider you created!
- Expand the Inbound Authentication Configuration section and then expand OAuth/OpenID Connect Configuration. Click Configure.
Fill in the form that appears. For the Allowed Grant Types you can disable the ones you do not require or wish to block.
The grant type highlighted below is a custom grant type. This will only appear on the UI if you have configured the JWT grant type. The value specified as the
deployment.tomlfile when creating the custom grant type is the value that will appear on the UI. For more information on writing a custom grant type, see Writing a Custom OAuth 2.0 Grant Type.
When filling out the New Application form, the following details should be taken into consideration.
Field Notes OAuth Version
Selecting OAuth Version as 1.0a removes all the configurable Allowed Grant Types. This is because this version of OAuth does not support grant types.
Allowed Grant Types
The following grant types are used to generate the access token:
- Code : Entering the username and password required at the service provider will result in a code being generated. This code can be used to obtain the access token. For more information on this grant type, see this Authorization Code specification.
- Implicit : This is similar to the code grant type, but instead of generating a code, this directly provides the access token. For more information on this grant type, see this Implicit Grant specification.
- Password : This authenticates the user using the password provided and the access token is provided. For more information on this grant type, see this Resource Owner Password Credentials Grant specification.
- Client Credential : This is the grant type for the client key and client secret. If these two items are provided correctly by the service provider, the access token is sent. For more information on this grant type, see this Client Credentials specification.
- Refresh Token : This will enable the user to obtain an access token by using the refresh token once the originally provided access token is used up. For more information on this grant type, see this Refresh Token specification.
- SAML2 : This uses SAML assertion to obtain the access token. For more information on this grant type, see this SAML2 Bearer specification.
- IWA-NTLM : This is similar to the password grant type, but it is specific to Microsoft Windows users.
- urn:ietf:params:oauth: grant-type:jwt-bearer : This is a custom grant type. It uses a JWT token to obtain the access token. For more information about this grant type, see this JWT specification.
This is the exact location in the service provider's application where an access token would be sent. This is a required field (if the grant type is anything other than 'Code' or 'Implicit') and it is important to configure, as it is imperative that the service provider receives the access token. This is necessary for security purposes to ensure that the token is not compromised.
Configure multiple callback URLs
From IS 5.2.0 onwards, regex-based consumer URLs are supported when defining the callback URL. This enables you to configure multiple callback URLs for one application by entering a regex pattern as the value for the callback URL field.
For example, if you have two service providers that use the same application, you can now define a regex pattern which will work for both callback URLs instead of having to configure two different applications for the two service providers. Assume the two callback URLs for your two service providers are as follows:
To configure the callback URL to work for both of these URLs, set it using a regex pattern as follows:
You must have the prefix ' regexp= ' before your regex pattern. To define a normal URL, you can specify the callback URL without this prefix.
You can also configure a regex pattern that contains dynamic values as seen below.
PKCE Mandatory Select this if you are using the Code grant type. PKCE is a recommended security measure used to mitigate a code interception attack. See Mitigating Authorization Code Interception Attacks for more information. Support PKCE 'Plain' Transform Algorithm Select this if you are using PKCE. Allow Authentication without the client secret This enables authenticating the client without the
Access Token Binding Type
This section provides the capability to attach the OAuth2 access token and refresh token to an external attribute during the token generation and optionally validate the external attribute during the API invocation.
- None : No binding.
- Cookie Based : This binding type is designed to improve the security of Single Page Applications(SPA) where access_token is stored at the browser. With this binding, additionally to the access token validation, a cookie with
HttpOnlyparameters will be validated to grant access. In the current implementation, this binding type can be enabled for authorization code grant with Allow Authentication without the client secret option. When this is enabled new cookie named atbv will be returned with the authorization code to the client browser. When the application makes the token request with this cookie, that cookie will get validated and attached to the generated tokens. Now, whenever the SPA tries to access the Identity Server API, it needs to present the access token + cookie for successful authorization.
- SSO Session Based : This binding type is designed to generate different tokens for each new browser instance. With this, you can avoid the same access token getting shared with multiple browser instances of the same application. Also, you can revoke the access token when you are logging out from one application(browser) instance and not break other instances. This binding type is supported for authorization code grant type.
User Access Token Expiry Time, Application Access Token Expiry Time, Refresh Token Expiry Time, Id Token Expiry Time
Set the validity period (in seconds) for User Access Token, Application Access Token, Refresh Token, and Id Token. Enable Audience Restriction
Select this to enable audience restrictions for OAuth applications. If necessary, you can add multiple audiences. To add an audience, specify a required Audience value and click Add. All audience values that you add would be available in the ID token generated for the corresponding application.
Enable Request Object Signature Validation
This is to define whether to only accept signed request objects in an authorization rqeuest or not. For more information, see Enforcing Signature Validation for Request Objects.
Enable ID Token Encryption This is to define whether to ID token encryption should be enabled or not. For a tutorial on this, see Testing OIDC Encrypted ID Token with IS. Enable OIDC Back Channel Logout This is to define whether OIDC back channel logout should be enabled or not. For more information, see Configuring OpenID Connect Back-Channel Logout. Scope Validators This is to define the scope validation mechanisms. For more information on XACML scope validation, see Validating the Scope of OAuth Access Tokens using XACML Policies. Token Issuer
Select either JWT or Default as the token issuer for the service provider.
- If you want to enable default token generation for a service provider, select Default as the Token Issuer. This is the default Token Issuer that is selected when you apply the WUM update.
When you enable default token generation, the hash value of the token is stored in the ACCESS_TOKEN_HASH column, and the plain text token is stored in the ACCESS_TOKEN column
- If you want to enable JWT token generation for a service provider, select JWT as the Token Issuer.
When you enable JWT token generation, the hash value of the JWT is stored in the ACCESS_TOKEN_HASH column, and the full JWT is stored in the ACCESS_TOKEN column.
Click Add. Note that
client secretget generated.
- OAuth Client Key - This is the client key of the service provider, which will be checked for authentication by the Identity Server before providing the access token.
- OAuth Client Secret - This is the client secret of the service provider, which will be checked for authentication by the Identity Server before providing the access token. Click the Show button to view the exact value of this.
Edit: Click to edit the OAuth/OpenID Connect Configurations
Revoke: Click to revoke (deactivate) the OAuth application. This action revokes all tokens issued for this application. In order to activate the application, you have to regenerate the consumer secret.
Regenerate Secret: Click to regenerate the secret key of the OAuth application.
Delete: Click to delete the OAuth/OpenID Connect Configurations.
The OAuth client key and client secret are stored in plain text. To encrypt the client secret, access token and refresh token, do the following:
Add the following property to the
deployment.tomlfile found in the
[oauth] hash_tokens_and_secrets= true
After updating the configuration, make sure to restart the server for the changes to be applied on WSO2 IS.
See Configuring OpenID Connect Single Logout to configure single logout or session management with OpenID Connect.
See Delegated Access Control for more information on working with OAuth2/OpenIDConnect. See the following topics for samples of configuring delegated access control:Top