This topic provides instructions on how to configure the JWT grant type. See the following sections for more information.
- Place the
org.wso2.carbon.identity.oauth2.grant.jwt-1.0.3.jardownloaded from store in the
To register the JWT grant type, configure the
<IS_HOME>/repository/conf/identity/identity.xmlfile by adding a new entry under the
<OAuth><SupportedGrantTypes>element. Add a unique identifier between the
<GrantTypeName>tags as seen in the code block below.
To store AUTHZ_USER and USER_DOMAIN values separately, Add SplitAuthzUser3Way property to the OAuth section of <IS_HOME>/repository/conf/identity/identity.xml file as follows: <SplitAuthzUser3Way>true</SplitAuthzUser3Way>
Restart the server.
Configure the JWT grant type
- Sign in to the WSO2 Identity Server. Enter your username and password to log on to the Management Console.
- In the Identity Providers section under the Main tab of the management console, click Add.
- Provide the following values to configure the IDP:
- Identity Provider Name: Enter a issuer name (this is used to generate the JWT assertion) as the identity provider name.
Identity Provider Public Certificate: The certificate used to sign the JWT assertion. You can find more information about adding certificate in Configuring an Identity Provider.
- Alias: Give the name of the alias if the Identity Provider identifies this token endpoint by an alias. E.g., https://localhost:9443/oauth2/token
- Navigate to the Main menu to access the Identity menu. Click Add under Service Providers.
- Fill in the Service Provider Name and provide a brief Description of the service provider. See Adding a Service Provider for more information.
- Expand the OAuth/OpenID Connect Configuration and click Configure.
- Enter a Callback URL. For example, use http://localhost:8080/playground2/oauth2client and click Add.
- The OAuth Client Key and OAuth Client Secret will now be visible.
The cURL commands below can be used to retrieve the access token and refresh the token using a JWT.
The -u flag should specify the “
<Client Id>:<Client Secret>” value. The assertion parameter value is the signed base64 encoded JWT. The value of the assertion parameter MUST contain a single JWT. You can refer JWT Bearer Grant for more information about assertion.
If you have configured the service provider and identity provider in a tenant, you have to add the tenant domain as a query parameter to the access token endpoint.
If the tenant domain is wso2.com, the access token endpoint will be as follows.
You would have now received the response from the token endpoint. The response would contain the access token, refresh token, expiry time and token type.
JWT Bearer Grant
JWT contains three parts that are separated by dots ".": header, payload, and a signature. The header identifies which algorithm is used to generate the signature.
The payload contains the claims mentioned below:
iss(issuer) - The JWT must contain an
iss(issuer) claim that contains a unique identifier that identifies the identity provider that issued the JWT.
sub(subject) - The JWT must contain a
sub(subject) claim that identifies the entity that the identity provider or the entity that issued the JWT vouches for.
aud(audience) - The JWT must contain an
aud(audience) claim which containing a value that identifies the authorization server as an intended audience. This value should be registered as token endpoint alias in the Identity Provider.
exp(expiration time) - The JWT must contain an
exp(expiration) claim that limits the time window during which the JWT can be used.
nbf(not before) - The JWT may contain a
nbf(not before time) claim that forces a JWT to be used only after a specified time.
iat(issued at) - The JWT may contain an
iat(issued at) claim that identifies the time at which the JWT was issued.
jti(json web token Id) - The JWT may contain
jti(JWT ID) claim that provides a unique identifier for the token.
- Other custom claims - JWT may contain claims other than the above mentioned ones. This is the extension point of the JWT specification.
For example, see the following code block.
The signature is calculated by base64 URL encoding the header and payload and concatenating them with a period as a separator and signing it:
Signature = sign(encodeBase64(header) + '.' + encodeBase64(payload))
The signature must then be base64 URL encoded. JWT assertion can be generated by concatenating these three encoded values with a separator dot ".".
assertion = encodeBase64(header) + '.' + encodeBase64(payload) + '.' + encodeBase64(signature)
The result is as follows:
If you are using OpenID connect token retrieved from WSO2 Identity Server as the assertion, “iss”(issuer) value of this JWT Bearer grant will be the token endpoint of the WSO2 Identity Server(For example, https://localhost:9443/oauth2/token). So you need to change the issuer value of Identity Server so that the grant handler can fetch the certificate of it’s resident identity provider by using following steps:
- Login to the management console.
- Go to Identity Provider --> Resident --> Inbound Authentication Configuration --> OAuth2/OpenID Connect Configuration and set the 'Identity Provider Entity Id' value as LOCAL.
Uncomment the following lines
This will make sure that the audience validation check will pass for the issued OpenID connect token.