# Adding Custom Authentication to a REST Endpoint

**Cognigy Support**

April 15, 2021

## Challenge

You want to restrict access to a [REST endpoint](https://docs.cognigy.com/docs/rest-1) so that only authorized requests will be answered by the flow.

## Solution

You can use the [Input Transformer](https://docs.cognigy.com/docs/input-transformer) of a REST endpoint to achieve this.

The process would be to require any request made to the endpoint to include a secret token that is set within the transformer. The transformer would then filter any requests and check that this exact token has been included. If the token is found, proceed with allowing the bot to respond, if not, return a 401 unauthorized error.

You can find an example of the Input transformer code required to achieve this below:

```
handleInput: async ({ endpoint, request, response }) => {

const userId = request.body.userId;
        const sessionId = request.body.sessionId;
        const text = request.body.text;
        const data = request.body.data;

if (request.body.token == "testToken") {
                return {
                    userId,
                    sessionId,
                    text,
                    data
                }
            } else {
                response.sendStatus(401);
                return null;
                }
    },
}
```

With this input transformer in place, your REST endpoint requests must include the "token" = "testToken" as a parameter in the request body.

MG - 20210415

### QnA

- [Exchanging data with Microsoft SharePoint](https://support.cognigy.com/hc/en-us/articles/360017535580-Exchanging-data-with-Microsoft-SharePoint)  
- [Exchanging data with Microsoft SQL Server (MSSQL)](https://support.cognigy.com/hc/en-us/articles/360017591799-Exchanging-data-with-Microsoft-SQL-Server-MSSQL)  
- [Using CognigyScript in Twilio Twiml XML](https://support.cognigy.com/hc/en-us/articles/360017594519-Using-CognigyScript-in-Twilio-Twiml-XML)  
- [How can I adjust the style of the Webchat Widget](https://support.cognigy.com/hc/en-us/articles/360017744619-How-can-I-adjust-the-style-of-the-Webchat-Widget)  
- [Accessing Information about the Cognigy.AI API](https://support.cognigy.com/hc/en-us/articles/360017847180-Accessing-Information-about-the-Cognigy-AI-API)  
- [Trigger Microsoft Power Automate Flows](https://support.cognigy.com/hc/en-us/articles/360018426159-Trigger-Microsoft-Power-Automate-Flows)  
- [Handling HTTP Request Errors](https://support.cognigy.com/hc/en-us/articles/360018593139-Handling-HTTP-Request-Errors)  
- [How to add a member to your virtual agent](https://support.cognigy.com/hc/en-us/articles/360018858279-How-to-add-a-member-to-your-virtual-agent)  
- [Add a new user to your Cognigy.AI organization](https://support.cognigy.com/hc/en-us/articles/360018858559-Add-a-new-user-to-your-Cognigy-AI-organization)  
- [Identifying a Unique Endpoint via analytics](https://support.cognigy.com/hc/en-us/articles/360020000099-Identifying-a-Unique-Endpoint-via-analytics)
