If you want to try out JWT Auth without linking up to a third-party IdP then you can skip step 1 and provide the base64 encoded public key for your JWT (in the
source field rather than configuring jwksURIs) in step 3. You’ll need to generate a JWT for the request, but otherwise everything stays the same.Now back to the tutorial…Prerequisites
- A Tyk installation (Cloud or Self-Managed) with Tyk Dashboard license
- An Auth0 account or Keycloak installation
- An existing Tyk OAS API (see this tutorial)
- Postman, cURL, or another API testing tool
Step-by-Step Guide
-
Configure Your Identity Provider to obtain your JWKS URI
The first step is to configure your Identity Provider (IdP) to issue JWTs and provide a JWKS URI that Tyk can use to validate the tokens. Below are instructions for both Auth0 and Keycloak.
- Auth0 Setup
- Keycloak Setup
- Log in to your Auth0 dashboard
- Navigate to Applications > APIs and click Create API
- Enter a name and identifier (audience) for your API
- Note your Auth0 domain (e.g.
your-tenant.auth0.com) - Your JWKS URI will be:
https://your-tenant.auth0.com/.well-known/jwks.json
-
Create a Security Policy
- In the Tyk Dashboard, navigate to Policies
- Click Add Policy
- Configure the policy:
- Name:
JWT Auth Policy - APIs: Select your Tyk OAS API
- Access Rights: Configure appropriate paths and methods
- Authentication: Select JWT
- JWT Scope Claim Name: Enter the JWT claim that contains scopes (e.g.
scopeorpermissions) - Required Scopes: Add any required scopes for access (optional)
- Name:
- Click Create to save your policy
-
Configure JWT Authentication in Tyk OAS API
- Navigate to APIs and select your API
- Click Edit
- Enable Authentication in the Server section, select JSON Web Token (JWT) as the authentication method
- Configure the JWT settings:
- Token Signing Method: Select
RSA Public Key - Subject identity claim: Set to
sub - JWKS Endpoint: Enter your JWKS URI for your IdP obtained in step 1
- Policy claim: Set to
pol - Default policy: Select
JWT Auth Policy(the policy you created previously) - Clock Skew (optional): Set to accommodate time differences (e.g.
10) - Authentication Token Location:
header - Header Name:
Authorization - Strip Authorization Data:
Enabled
- Token Signing Method: Select
- Click Save API
-
Test your API
- Obtain a JWT from your IdP
- Make a request to your API providing the JWT as a Bearer token in the
Authorizationheader; Tyk will validate the JWT using the JWKS that it retrieves from your JWKS URI - Observe that the request is successful