# auth.ts configuration

> **You don't need to configure this file if your conector does not need a user auth e.g. a helper / utility connector.**&#x20;

This file just defines the type of Auth that your service needs, all the authentication logic is handled by Tray in the service layer i.e. you don't need to write the logic to generate / refresh auth tokens.

## Pre-requisite

The auth is tied to a service and hence the content of this file depends on what type of Auth is needed by the service.

Hence you need to create a [Custom Service](https://tray.ai/documentation/platform/connectivity/custom-services/introduction) first. Follow the instructions on main docs to create the service.

## Configuration

Depending on the type of Service, you can configure the file in one of the following ways:

### 1. Token Based service

> **This should be used when the service uses auth tokens of some kind (e.g. JWT, Bearer).**&#x20;

You need to use `TokenOperationHandlerAuth` for services of this kind.

Here is an example of `auth.ts` file for  service:

```typescript auth.ts
import { TokenOperationHandlerAuth } from "@trayio/cdk-dsl/connector/operation/OperationHandler";

export type UserAuth = {
    access_token: string
};

export type AppAuth = {};

export type TmdbAuth = TokenOperationHandlerAuth<UserAuth, AppAuth>;
```

### 2. OAuth2 service

> **Info:** Here is a very good resource about .

You need to use `Oauth2OperationHandlerAuth` for services of this kind.

Here is an example of `auth.ts` file for [Spotify](https://developer.spotify.com/documentation/web-api/tutorials/client-credentials-flow) API's custom service:

```typescript auth.ts
import { Oauth2OperationHandlerAuth } from "@trayio/cdk-dsl/connector/operation/OperationHandler";

export type UserAuth = {
    access_token: string
};

export type AppAuth = \{
    client_id: string,
    client_secret: string,
    auth_url: string,
    token_url: string,
    scopes: string
\};

export type SpotifyAuth = Oauth2OperationHandlerAuth<UserAuth, AppAuth>;
```

You can also use the specific handlers for following grant types of OAuth2 services:

#### 2.1 Client credentials grant flow

> **Info:** You can read more about this grant type .

You need to use `Oauth2ClientCredentialsOperationHandlerAuth` for services of this kind.

#### 2.2 Password grant flow

> **Info:** You can read more about this grant type .

You need to use `Oauth2PasswordOperationHandlerAuth` for services of this kind.

### 3. OAuth1 service

> **Info:** OAuth1 is rarely used by services. Here is a very good resource about .

You need to use `Oauth1OperationHandlerAuth` for services of this kind.
