> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apinizer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# JWT Validation

> JWT Validation

In this scenario, it will be explained how a JWT sent to a **REST** architecture **API** named **Swagger PetStore** is controlled with the **JOSE Validation** policy.

The image below shows the JOSE Validation workflow that will be applied to a request.

<img src="https://mintcdn.com/apinizer/uEpU4gYmDePkcYS7/images/tutorials/j1.jpg?fit=max&auto=format&n=uEpU4gYmDePkcYS7&q=85&s=7f41bc5f7722c822c66e37866ae53bd8" alt="JOSE Validation Workflow" width="1000" data-path="images/tutorials/j1.jpg" />

## 1) Creating the API Proxy

In this scenario, a REST API named Swagger Petstore([https://petstore.swagger.io](https://petstore.swagger.io/)) will be used.

First, this address must be defined as an **API Proxy**.

For this, click on the **API Proxies** option under the **Development** menu.

<img src="https://mintcdn.com/apinizer/uEpU4gYmDePkcYS7/images/tutorials/j2.png?fit=max&auto=format&n=uEpU4gYmDePkcYS7&q=85&s=c2515a49a6ec7eb1c907f9ac65f5b497" alt="API Proxies Menu" width="200" data-path="images/tutorials/j2.png" />

Since no **proxy** definition has been made before on the opened page, the text **No records found!** appears.

Here, click on the **Create** button located in the top right corner and start creating a new **Api Proxy**.

<img src="https://mintcdn.com/apinizer/uEpU4gYmDePkcYS7/images/tutorials/j3.png?fit=max&auto=format&n=uEpU4gYmDePkcYS7&q=85&s=2292b8565f1660b33aa26b4962ea0369" alt="Create Button" width="600" data-path="images/tutorials/j3.png" />

In this section, it is necessary to select what type the **API Proxy** to be created is.

Since the type of API to be used in this scenario will be **Swagger 2.X**, this type is selected.

Click on the **Enter URL** expression to switch to the screen where the address of the API to be used will be entered.

<img src="https://mintcdn.com/apinizer/ocsi_kVjLluGlu4Z/images/tutorials/swagger.png?fit=max&auto=format&n=ocsi_kVjLluGlu4Z&q=85&s=13223791b611fc908487605c87b11809" alt="Senaryo Diyagramı" width="800" data-path="images/tutorials/swagger.png" />

As seen in the image below, enter the address to be accessed in the **URL section** and click the **Parse** button.

<img src="https://mintcdn.com/apinizer/6d3coyPLAezC6iKa/images/tutorials/5.png?fit=max&auto=format&n=6d3coyPLAezC6iKa&q=85&s=f80753f98c584f4cce3fba94bbd560f8" alt="URL Entry Screen" width="1000" data-path="images/tutorials/5.png" />

After the Parse operation is performed, the screen shown in the image below appears.

<img src="https://mintcdn.com/apinizer/6d3coyPLAezC6iKa/images/tutorials/6.png?fit=max&auto=format&n=6d3coyPLAezC6iKa&q=85&s=f0d03cbb6b75f205c83dde00d89fd4ff" alt="Screen After Parse" width="1000" data-path="images/tutorials/6.png" />

Settings for the API Proxy can be made from this screen. To get detailed information about these settings, you can visit the [API Proxy Creation](/en/develop/api-proxy-creation/api-proxy-creation) document.

The settings of the Api Proxy to be used in our scenario are as follows.

<img src="https://mintcdn.com/apinizer/6d3coyPLAezC6iKa/images/tutorials/7.png?fit=max&auto=format&n=6d3coyPLAezC6iKa&q=85&s=2b7c71a2c23200412075cf9cae529cb1" alt="API Proxy Settings" width="1000" data-path="images/tutorials/7.png" />

After the save operation, click on the **Develop** tab on the opened page.

<img src="https://mintcdn.com/apinizer/6d3coyPLAezC6iKa/images/tutorials/8.png?fit=max&auto=format&n=6d3coyPLAezC6iKa&q=85&s=ef6d3204d3ec710410c74b581127f00e" alt="Develop Tab" width="1000" data-path="images/tutorials/8.png" />

Here, **endpoints** belonging to the **REST API** are listed.

**JOSE Validation** policy can be added to **all methods** with the **All** expression or to **a single method**.

<img src="https://mintcdn.com/apinizer/6d3coyPLAezC6iKa/images/tutorials/9.png?fit=max&auto=format&n=6d3coyPLAezC6iKa&q=85&s=54949ce4e78b7455255bb7517afbbfb7" alt="Endpoints List" width="1000" data-path="images/tutorials/9.png" />

To perform **signature verification** in JOSE Validation, **JSON Web Keypair Sets** must be added.

## 2) JSON Web Keypair Sets

To add JSON Web Keypair Sets, go to the JSON Web Keypair Sets menu under Secret Manager from the left menu.

<img src="https://mintcdn.com/apinizer/3JKt9YDmMqfHHisB/images/tutorials/10.png?fit=max&auto=format&n=3JKt9YDmMqfHHisB&q=85&s=06c40cef5b82e4fed13101042d07a5f1" alt="JSON Web Keypair Sets Menu" width="200" data-path="images/tutorials/10.png" />

On the opened screen, click on the **Create** button placed in a rectangle in the top right corner.

<img src="https://mintcdn.com/apinizer/6d3coyPLAezC6iKa/images/tutorials/11.png?fit=max&auto=format&n=6d3coyPLAezC6iKa&q=85&s=ceac2be380908d8211147a7c944477a3" alt="Create Button" width="600" data-path="images/tutorials/11.png" />

This document will focus on the production of JSON Web Keypair Sets with Apinizer or with Keycloak (a 3rd party software).

**2.1) JWK Production from Apinizer:**

In this scenario, the Name field will be used as **testjwk scenario**.

JWK is created with the **Generate JWK** option and using the desired algorithm.

<img src="https://mintcdn.com/apinizer/6d3coyPLAezC6iKa/images/tutorials/12.png?fit=max&auto=format&n=6d3coyPLAezC6iKa&q=85&s=8719640ab9f642660fcbf863f70c5231" alt="Generate JWK Screen" width="1000" data-path="images/tutorials/12.png" />

As a result of using the Generate button, JWK is created. The created Public Key is ready to be used in verification operations.

<img src="https://mintcdn.com/apinizer/6d3coyPLAezC6iKa/images/tutorials/13.png?fit=max&auto=format&n=6d3coyPLAezC6iKa&q=85&s=ddaa36e005a0cfaa6b6cea210dec4fdb" alt="JWK Created" width="1000" data-path="images/tutorials/13.png" />

As the final step, click the **Save And Deploy** button to save.

**2.2) JWK Production from Keycloak:**

From Keycloak, go to Realm Settings > Keys menu and click on the Public key field to get the Public key.

<img src="https://mintcdn.com/apinizer/6d3coyPLAezC6iKa/images/tutorials/14.png?fit=max&auto=format&n=6d3coyPLAezC6iKa&q=85&s=2d3320a9025bcc66ed1c44cfbf59e838" alt="Keycloak Public Key" width="1000" data-path="images/tutorials/14.png" />

<img src="https://mintcdn.com/apinizer/6d3coyPLAezC6iKa/images/tutorials/15.png?fit=max&auto=format&n=6d3coyPLAezC6iKa&q=85&s=cf2b21af31f30a8014f83e9da52063dc" alt="Keycloak Public Key Detail" width="1000" data-path="images/tutorials/15.png" />

The Public key must be converted to JWK with a 3rd party tool. For this, the following address can be used: [https://russelldavies.github.io/jwk-creator/](https://russelldavies.github.io/jwk-creator/)

To save the public key converted to JWK to Apinizer;

* Go to the JSON Web Keypair Sets page from the Secret Manager menu under the left menu.

* In this scenario, the Name field will be used as **testjwk scenario**.

* Select the **Paste the content of the JWT** option and enter the JWK in the relevant field.

* Enter the value in the **Kid** field in Keycloak into the **Key id** field and then click the **Save and Deploy** button to save.

<img src="https://mintcdn.com/apinizer/6d3coyPLAezC6iKa/images/tutorials/16.png?fit=max&auto=format&n=6d3coyPLAezC6iKa&q=85&s=2463d944b5f385f0c23b00f318a84263" alt="JWK Paste Screen" width="1000" data-path="images/tutorials/16.png" />

## 3) Adding Authentication Policy

The **JOSE Validation** policy is now ready to use.

Go to the page where API Proxies are listed and select the proxy named **Swagger Petstore** from here.

Then go to the **Develop** tab and click the **Add Policy** button.

On the opened page, select the **JOSE Validation** policy.

<img src="https://mintcdn.com/apinizer/6d3coyPLAezC6iKa/images/tutorials/17.png?fit=max&auto=format&n=6d3coyPLAezC6iKa&q=85&s=5891a6f715ba7f560282b9ec2a5206c7" alt="JOSE Validation Policy Selection" width="1000" data-path="images/tutorials/17.png" />

Selected

<img src="https://mintcdn.com/apinizer/6d3coyPLAezC6iKa/images/tutorials/18.png?fit=max&auto=format&n=6d3coyPLAezC6iKa&q=85&s=5949d4326abe7b518721bdffc7a7eacd" alt="JOSE Validation Settings" width="1000" data-path="images/tutorials/18.png" />

If you want to examine the expressions on this screen one by one, you can visit the [JWKS Configuration](/en/admin/secrets-management/jwks-configuration) page.

The settings to be used in this scenario are as shown in the image below. After making these changes, click the **Save** button located in the top right corner.

<img src="https://mintcdn.com/apinizer/6d3coyPLAezC6iKa/images/tutorials/19.png?fit=max&auto=format&n=6d3coyPLAezC6iKa&q=85&s=2f1cbba94477cd01673dc0bc023508fe" alt="JOSE Validation Settings Detail" width="1000" data-path="images/tutorials/19.png" />

## 4) Testing the API Proxy

Select the proxy named **Swagger Petstore**.

Select the endpoint named **/pet/findByStatus** under the **Develop** tab.

Click on the **Test Endpoint** expression to test this endpoint.

Enter the desired **status** value as **pending** in the URL, and when the **Send** button is pressed, it is seen that the returned response is an error message.

Place the **Authorization header** in the **Header** and use the **token information** produced from Keycloak or Apinizer here.

When you click the **Send** button, the answer received is the expression in the rectangle below on the image.

<img src="https://mintcdn.com/apinizer/6d3coyPLAezC6iKa/images/tutorials/20.png?fit=max&auto=format&n=6d3coyPLAezC6iKa&q=85&s=9cae84d42fbd40cd19f2d78918ef198c" alt="Test Endpoint Result" width="1000" data-path="images/tutorials/20.png" />

If an inappropriate token value is used, an error will be received.
