Skip to content

Commit e63d9f7

Browse files
authored
Merge pull request #5627 from piraveena/jwt-bearer-grant
Add jwt bearer grant docs
2 parents 127d1da + cb1a6ca commit e63d9f7

File tree

5 files changed

+168
-1
lines changed

5 files changed

+168
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{% set product_name = "WSO2 Identity Server" %}
2+
{% set product_url_format = "https://localhost:9443" %}
3+
{% set product_url_sample = "https://localhost:9443" %}
4+
{% include "../../../../../includes/guides/authentication/configure-jwt-bearer-grant.md" %}

en/identity-server/next/mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ nav:
600600
- JWT Secured Authorization Response Mode (JARM) for OAuth 2.0: guides/authentication/oidc/jarm.md
601601
- Implement login using the OIDC Hybrid Flow: guides/authentication/oidc/implement-oidc-hybrid-flow.md
602602
- Configure token exchange: guides/authentication/configure-token-exchange.md
603+
- Configure JWT Bearer Grant: guides/authentication/configure-jwt-bearer-grant.md
603604
- Validate ID tokens: guides/authentication/oidc/validate-id-tokens.md
604605
- Request user information: guides/authentication/oidc/request-user-info.md
605606
- Validate tokens: guides/authentication/oidc/token-validation-resource-server.md
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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.

en/includes/guides/authentication/configure-token-exchange.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,4 @@ Follow the steps given below.
189189
{{ product_name }} only copies the `sub` claim from the token received from the trusted token issuer to the exchanged {{ product_name }} token.
190190

191191
Upon successful execution, you will receive the exchanged token issued by {{ product_name }}.
192+

en/includes/references/grant-types.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Grant types in OAuth 2.0 are defined as the methods used by a client to obtain a
1414
{% endif %}
1515
- [Token exchange grant](#token-exchange-grant)
1616
{% if product_name == "WSO2 Identity Server" %}
17+
- [JWT Bearer Grant](#jwt-bearer-grant)
1718
- [SAML 2.0 bearer grant](#saml-20-bearer-grant)
1819
{% endif %}
1920

@@ -431,9 +432,49 @@ The following diagram shows how the token exchange grant flow works.
431432
6. The client application can now request resources from the resource server by providing the access token.
432433
7. As the resource server trusts {{ product_name }} issued tokens, it returns the requested resources to the client application.
433434

434-
See [configure the token exchange flow]({{base_path}}/guides/authentication/configure-token-exchange) for more details.
435+
Token exchange can be used for delegation and impersonation use cases. See [configure the token exchange flow]({{base_path}}/guides/authentication/configure-token-exchange) for more details about delegation usecase. See [user impersonation]({{base_path}}/guides/authorization/user-impersonation/via-business-application) for more details on user impersonation with token exchange grant.
435436

436437
{% if product_name == "WSO2 Identity Server" %}
438+
439+
## JWT Bearer grant
440+
441+
OAuth 2.0 JWT bearer is a grant type in the OAuth 2.0 framework that enables the exchange of one type of token for another with a different set of permissions or attributes. This grant type is defined in the [RFC7523](https://datatracker.ietf.org/doc/html/rfc7523).
442+
443+
The following diagram shows how the JWT Bearer grant flow works.
444+
445+
![How the JWT bearer grant works]({{base_path}}/assets/img/references/grants/token-exchange-grant.png)
446+
447+
1. The user sends a login request to the client application.
448+
2. The client application sends an authorization request to the third-party IdP.
449+
3. The third-party IdP returns the JWT access token for the user to the client application.
450+
4. The client application makes a token exchange request to the authorization server:
451+
452+
=== "Request format (/token)"
453+
454+
```bash
455+
curl -v -k -X POST {{base_url}}/oauth2/token \
456+
--header "Authorization: Basic <Base64Encoded(CLIENT_ID:CLIENT_SECRET)>" \
457+
--header "Content-Type:application/x-www-form-urlencoded" \
458+
--data-urlencode "grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer" \
459+
--data-urlencode "assertion=<jwt_token>"
460+
```
461+
462+
=== "Sample request (/token)"
463+
464+
```bash
465+
curl -v -k -X POST {{base_url_example}}/oauth2/token \
466+
--header "Authorization: Basic RWkwV2Y5YnpmTXE0UTBsZndTdlRQamU4a2NFYTpIRvvyUzJIUjlrZE9YMjBXTG9JNmY1eE1wdUlBamdKeG5aUVVUMV9lNTJnYQ==" \
467+
--header "Content-Type:application/x-www-form-urlencoded" \
468+
--data-urlencode "grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer" \
469+
--data-urlencode "assertion=eyJ4NXQiOiJJSm5VOF9rbkpQOC1jMEJHWTdOT2N1eWEtSlEiLCJraWQiOiJPRE0wWkRBMk5qQTFOREl4TkdFd05ERmlOakl5TWpRd05qQTJNMlppWVRKak1UbGxObVkzTm1FMVpXWmhPVEV3T1RZd01EQXdOREZpWVROaVpUQTFOQV9SUzI1NiIsInR5cCI6ImF0K2p3dCIsImFsZyI6IlJTMjU2In0.ewogICJzdWIiOiAiNDUzZDBjYTMtN2ZkNi00ZWJhLWJiYWUtNjEwNjI5OSIsCiAgImF1dCI6ICJBUFBMSUNBVElPTl9VU0VSIiwKICAiaXNzIjogImh0dHBzOi8vYXBpLmFzZ2FyZGVvLmlvL3Qvb3JnbmFtZS9vYXV0aDIvdG9rZW4iLAogICJjbGllbnRfaWQiOiAiS2tXclNQMzM0VkVKazNFbnV4NXE3YlFhIiwKICAiYXVkIjogWwogICAgIktrV3JTUDMzNFZFSmszRW51eDVxN2JRYSIsCiAgICAiaHR0cHM6Ly9sb2NhbGhvc3Q6OTQ0My9vYXV0aDIvdG9rZW4iCiAgXSwKICAibmJmIjogMTc2MDA3NDEzOSwKICAiYXpwIjogIktrV0puclNQMzM0VkVKazNFblFBdXg1cTdiUWEiLAogICJvcmdfaWQiOiAiMWY5ZTk4MWIiLAogICJzY29wZSI6ICJvcGVuaWQiLAogICJleHAiOiAxNzYwMDc3NzM5LAogICJvcmdfbmFtZSI6ICJvcmduYW1lIiwKICAiaWF0IjogMTc2MDA3NDEzOSwKICAianRpIjogImRmZTMzZDRiIiwKICAib3JnX2hhbmRsZSI6ICJvcmduYW1lIgp9.GXwYyOkaMNgFWyksSgSaAKmj6FqSRJX_3e1CxlLZwtoLtndrM2VfzRdx2J-uTdJLNSLF4fyDvdLzM0OC1TAfGaJNxJ2l_CYNvDnNcncMa1nfnmKeydmDbGksLasZah384jt8i49zD1DboMsglv2vFq9v7Ce6BHfPvHiL_nqOW8q34uXt8QmZLugalPA-2qchsi1C0NDu1niXz3DEO7VPMy7S2SZGHBmeoydoifWtKeqzKr5ArU0xJ9w5pW-VmQT8XWctE4UfRaYzpubl6DvAijT4uTAQYAgpk1IJC6Su_OTEEgnGf7L-iQxTf-KdvpNPvL6i-CFkBf9IktMm0o5kXw"
470+
```
471+
472+
5. The authorization server responds to the client with the new access token.
473+
6. The client application can now request resources from the resource server by providing the access token.
474+
7. As the resource server trusts {{ product_name }} issued tokens, it returns the requested resources to the client application.
475+
476+
See [configure the JWT Bearer Grant flow]({{base_path}}/guides/authentication/configure-jwt-bearer-grant) for more details.
477+
437478
## SAML 2.0 bearer grant
438479

439480
SAML 2.0 bearer grant is a grant type in the OAuth 2.0 framework that enables the exchange of a SAML 2.0 assertion for an OAuth 2.0 access token. This grant type is defined in the [SAML 2.0 Profile for OAuth 2.0 Client Authentication and Authorization Grants specification (RFC 7522)](https://datatracker.ietf.org/doc/html/rfc7522){:target="_blank"}.

0 commit comments

Comments
 (0)