# Digibee JWT implementation

The [Digibee JWT](https://docs.digibee.com/documentation/connectors-and-triggers/connectors/security/digibee-jwt) connector is most commonly used to authorize access to a service exposed on the network via the HTTP protocol. To access these services, it’s necessary to log in using a pipeline, which will be responsible for generating the JWT token. With this token, you have access to permitted routes, services, and resources.

## Step 1 - Creating a pipeline for authentication and JWT generation

The first step to create an authentication pipeline is to configure the trigger to login:

1. On the Digibee Platform home page, open the  **Build** page.&#x20;
2. Click **Create** and then select **Pipeline**.
3. Inside the Canvas, click on the **Configurations** icon on the trigger.&#x20;
4. In the trigger configuration, select [REST](https://docs.digibee.com/documentation/connectors-and-triggers/triggers/web-protocols/rest).
5. Activate the **External API** and **API Key** options and configure the rest as desired. After configuring the trigger, add the Digibee JWT connector to your integration.
6. Click the **+** button next to the trigger and search for the connector **Digibee JWT** or drag the connector to your Canvas.&#x20;
7. Open connector settings and select **Generate** operation to create  the token.&#x20;
8. In the **Scopes** field, set the scopes for the JWT token, separated by comma.&#x20;
9. In the  **Expiration** field, set the token expiration time (in milliseconds). The maximum expiration is 365 days (31536000000 milliseconds).
10. Click **Confirm** to implement the connector settings.&#x20;

{% hint style="info" %}
JWT token generation is not done in test mode. This is only possible when the pipeline is published in one of the environments (Test or Prod).
{% endhint %}

## Stage 2 – Using the Assert v2 connector

Use the connector [Assert v2](https://docs.digibee.com/documentation/connectors-and-triggers/connectors/tools/assert-v2) to create a validation using a pre-registered username and password on the Digibee Integration Platform by following the steps below:<br>

1. Click the  **+** button next to the **Digibee JWT** connector and search for the  **Assert V2** connector or drag the connector to your Canvas.&#x20;
2. Open the connector settings and enter the following code in the **Condition** field:

```
#{body.user} == #{globals.user} && #{body.password} == #{globals.password}
```

3. Click **Confirm** to implement the connector setting.

## Step 3 - Calling the pipeline for login

After you finish the configuration, you need to deploy the pipeline in your appropriate test or production environment to test the flow. Learn more about [deploying pipelines on the Platform](https://app.gitbook.com/s/jvO5S91EQURCEhbZOuuZ/development-cycle/overview/deployment/deployments).&#x20;

With the API Key configured, you can start testing. See in the following example how to do this using Postman. You can also use the client you typically use or any other application you prefer.

To perform the operation in Postman:&#x20;

1. Provide the API Key in the header of the request.
2. Provide the username and password configured in step 2 as mandatory in the flow.

<figure><img src="https://content.gitbook.com/content/EKM2LD3uNAckQgy1OUyZ/blobs/w1oWGrMQRWl9fxxGbmTh/image1.png" alt=""><figcaption></figcaption></figure>

When this request is made, the service returns a successful status:

<figure><img src="https://content.gitbook.com/content/EKM2LD3uNAckQgy1OUyZ/blobs/M7AeA3Zbat7QjrffGiD0/image2.png" alt=""><figcaption></figcaption></figure>

3. Search for the necessary information in the headers of the response, in the **Authorization** field. This is the authentication, which means that the generated JWT that will be used in combination with the API Key for other flows that use the REST API and HTTP triggers.

## Configuring the trigger for flows with new key-based authentication

With Digibee JWT, you can customize security in the construction of your next pipeline projects. Make the necessary adjustments in the trigger following the instructions below:

1. On the Digibee Integration Platform home page, open the **Build** page.&#x20;
2. Click **Create** and then select **Pipeline**.
3. Inside the Canvas, click on the **Configurations** icon on the trigger.&#x20;
4. In the trigger configuration, select **REST**.
5. Activate the **External API**, **API Key**, and **Token JWT** options. This way, whenever routes are called, it will be necessary to inform the API Key and the  JWT token generated. If you just inform the API Key without the token, an authorization error will be returned:

<figure><img src="https://content.gitbook.com/content/EKM2LD3uNAckQgy1OUyZ/blobs/RQ10m7ap1XJa7FbK6fLa/image3.png" alt=""><figcaption></figcaption></figure>
