Configure JWT bearer grant¶
You can add a trusted token issuer to exchange JWT assertion with an OAuth 2.0 access token to access protected resources on behalf of the resource owner.
Learn how to configure the OAuth 2.0 JWT bearer grant flow in Asgardeo. Refer JWT bearer grant for more information on how the flow works.
Follow this guide for instructions.
Register a trusted token issuer¶
To exchange a third-party token for an Asgardeo token, you need to register the third-party token issuer as a trusted token issuer in your Asgardeo organization.
To register a trusted token issuer:
- On the Asgardeo console, go to Connections.
- Click New Connections and click Create on the Trusted Token Issuer.
-
Enter the following details of the trusted token issuer:
Parameter Description Trusted token issuer name A unique name for the new trusted token issuer. Issuer A unique issuer value of the trusted token issuer. This is the value of the issclaim in the JWT token generated from the configured identity provider.
Example:https://third-party-token-issuers.io/oauth2/tokenAlias The name by which the trusted token issuer knows Asgardeo. The audclaim of the token should include the Asgardeo organization's issuer value. If theaudclaim doesn't include the organization's issuer value, the system validates the alias value you assign here against theaudclaim.
Example:https://third-party-token-issuers.io/oauth2/token -
Click Next and provide the mode of certificate configuration.
-
JWKS endpoint: The JWKS endpoint of the trusted token issuer.
-
Use PEM certificate: Upload or paste the public certificate of the trusted token issuer in the PEM format.
Convert
.crt,.ceror.derto the.pemformat using OpenSSLConvert CRT to PEM
Convert CER to PEM:openssl x509 -in cert.crt -out cert.pemConvert DER to PEM:openssl x509 -in cert.cer -out cert.pemopenssl x509 -in cert.der -out cert.pem
-
-
Click Finish to add the new trusted token issuer.
Enable JWT bearer grant in your app¶
Before you begin
You need to register Standard-based OIDC application application types with Asgardeo.
To enable JWT bearer grant in your application:
-
On the Asgardeo Console, go to Applications.
-
Open your application from the list and go to the Protocol tab.
-
Add
JWT Bearerunder the Allowed grant types. -
Click Update to save the configurations.
Try it out¶
Follow the steps given below.
-
Get the JWT token received from the third-party token issuer.
-
The application sends the access request to the token endpoint in Asgardeo with the following:
-
JWT bearer grant type.
-
JWT assertioncreated by the third-party token issuer. -
Service provider's
client IDandclient secret.
-
-
Execute the following cURL command to exchange the third-party token for an Asgardeo token.
curl -v -k -X POST https://api.asgardeo.io/t/<organization_name>/oauth2/token \ --header "Authorization: Basic <Base64Encoded(CLIENT_ID:CLIENT_SECRET)>" \ --header "Content-Type:application/x-www-form-urlencoded" \ --data-urlencode "grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer" \ --data-urlencode "assertion=<jwt_token>"Upon successful execution, you will receive the exchanged token issued by Asgardeo.
Refer to JWT Bearer grant for more information on how the flow works.