|
| 1 | +# Configure JWT Bearer Grant |
| 2 | + |
| 3 | +You can add a trusted token issuer to a exchange JWT assertion with an OAuth 2.0 access token in order to access protected resources on behalf of the resource owner. |
| 4 | + |
| 5 | +Learn how to configure the OAuth 2.0 JWT Bearer Grant flow in WSO2 Identity Server. Refer [JWT Bearer grant]({{base_path}}/references/grant-types/#jwt-bearer-grant) for more information on how the flow works. |
| 6 | + |
| 7 | +Follow this guide for instructions. |
| 8 | + |
| 9 | +## Register a trusted token issuer |
| 10 | + |
| 11 | +To exchange a third-party token for an {{ product_name }} token, you need to register the third-party token issuer as a trusted token issuer in your {{ product_name }} organization. |
| 12 | + |
| 13 | +To register a trusted token issuer: |
| 14 | + |
| 15 | +1. On the {{ product_name }} console, go to **Connections**. |
| 16 | +2. Click **New Connections** and click **Create** on the **Trusted Token Issuer**. |
| 17 | +3. Enter the following details of the trusted token issuer: |
| 18 | + |
| 19 | + <table> |
| 20 | + <tr> |
| 21 | + <th>Parameter</th> |
| 22 | + <th>Description</th> |
| 23 | + </tr> |
| 24 | + <tr> |
| 25 | + <td>Trusted token issuer name</td> |
| 26 | + <td>A unique name for the new trusted token issuer.</td> |
| 27 | + </tr> |
| 28 | + <tr> |
| 29 | + <td>Issuer</td> |
| 30 | + <td>A unique issuer value of the trusted token issuer. This is the value of the `iss` claim in the JWT token generated from the configured identity provider. <br> |
| 31 | + Example: <code>https://third-party-token-issuers.io/oauth2/token</code></td> |
| 32 | + </tr> |
| 33 | + <tr> |
| 34 | + <td>Alias</td> |
| 35 | + <td>The name by which the trusted token issuer knows {{ product_name }}. The <code>aud</code> claim of the token should include the {{ product_name }} organization's issuer value. If the <code>aud</code> claim doesn't include the organization's issuer value, the system validates the alias value you assign here against the <code>aud</code> claim. <br> |
| 36 | + Example: <code>https://third-party-token-issuers.io/oauth2/token</code></td> |
| 37 | + </td> |
| 38 | + </tr> |
| 39 | + </table> |
| 40 | + |
| 41 | +4. Click **Next** and provide the mode of certificate configuration. |
| 42 | + |
| 43 | + - **JWKS endpoint**: The JWKS endpoint of the trusted token issuer. |
| 44 | + |
| 45 | + {% if product_name == "WSO2 Identity Server" %} |
| 46 | + |
| 47 | + !!! note |
| 48 | + For JWKS endpoints, the default read timeout equals 1000 milliseconds. To modify this value, add the following parameter to the `deployment.toml` file in the `<PRODUCT_HOME>/conf/repository` directory. |
| 49 | + |
| 50 | + ```toml |
| 51 | + [oauth.jwks_endpoint] |
| 52 | + read_timeout = <value in milliseconds> |
| 53 | + ``` |
| 54 | + {% endif %} |
| 55 | + |
| 56 | + - **Use PEM certificate**: Upload or paste the public certificate of the trusted token issuer. The certificate should be in PEM format. |
| 57 | + |
| 58 | + ??? note "If you have a certificate in other formats such as `.crt`, `.cer` or `.der`, expand here to see how you can convert them to PEM format using [OpenSSL](https://www.openssl.org/){:target="_blank"}" |
| 59 | + **Convert CRT to PEM** |
| 60 | + ```bash |
| 61 | + openssl x509 -in cert.crt -out cert.pem |
| 62 | + ``` |
| 63 | + **Convert CER to PEM:** |
| 64 | + ```bash |
| 65 | + openssl x509 -in cert.cer -out cert.pem |
| 66 | + ``` |
| 67 | + **Convert DER to PEM:** |
| 68 | + ```bash |
| 69 | + openssl x509 -in cert.der -out cert.pem |
| 70 | + ``` |
| 71 | + |
| 72 | +5. Click **Finish** to add the new trusted token issuer. |
| 73 | + |
| 74 | +## Enable JWT Bearer Grant in your app |
| 75 | + |
| 76 | +!!! note "Before you begin" |
| 77 | + You need to register [Standard-based OIDC application]({{base_path}}/guides/applications/register-standard-based-app/) application types with WSO2 Identity Server. |
| 78 | + |
| 79 | + |
| 80 | +To enable JWT bearer grant in your application: |
| 81 | + |
| 82 | +1. On the {{ product_name }} Console, go to **Applications**. |
| 83 | + |
| 84 | +2. Open your application from the list and go to the **Protocol** tab. |
| 85 | + |
| 86 | +3. Add `JWT Bearer` under the **Allowed grant types**. |
| 87 | + |
| 88 | +4. Click **Update** to save the configurations. |
| 89 | + |
| 90 | +## Try it out |
| 91 | + |
| 92 | +Follow the steps given below. |
| 93 | + |
| 94 | +1. Obtain the JWT token received from the third-party token issuer. |
| 95 | +2. The application sends the access request to the token endpoint in WSO2 Identity Server with the following: |
| 96 | + - JWT bearer grant type. |
| 97 | + - `JWT assertion` that is created by the third-party token issuer. |
| 98 | + - Service provider's `client ID` and `client secret`. |
| 99 | +3. Execute the following cURL command to exchange the third-party token for an {{ product_name }} token. |
| 100 | + |
| 101 | + ```bash |
| 102 | + curl -v -k -X POST {{base_url}}/oauth2/token \ |
| 103 | + --header "Authorization: Basic <Base64Encoded(CLIENT_ID:CLIENT_SECRET)>" \ |
| 104 | + --header "Content-Type:application/x-www-form-urlencoded" \ |
| 105 | + --data-urlencode "grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer" \ |
| 106 | + --data-urlencode "assertion=<jwt_token>" |
| 107 | + ``` |
| 108 | + |
| 109 | +Upon successful execution, you will receive the exchanged token issued by {{ product_name }}. |
| 110 | + |
| 111 | + |
| 112 | +!!! note |
| 113 | + While configuring the JWT bearer grant type, the iat validating time period can also be configured in the `deployment.toml` file in the `<IS_HOME>/repository/conf` as shown below. The default value is 30 minutes. |
| 114 | + ```toml |
| 115 | + [oauth.grant_type.jwt] |
| 116 | + enable_iat_validation="true" |
| 117 | + iat_validity_period=30 |
| 118 | + ``` |
| 119 | + |
| 120 | +Refer [JWT Bearer grant]({{base_path}}/references/grant-types/#jwt-bearer-grant) for more information on how the flow works. |
0 commit comments