auth.ts configuration


info

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

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 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

info

This should be used when the service uses auth tokens of some kind (e.g. JWT, Bearer).

You need to use TokenOperationHandlerAuth for services of this kind.

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

Copy
Copied
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 What is OAuth2 and how it works.

You need to use Oauth2OperationHandlerAuth for services of this kind.

Here is an example of auth.ts file for Spotify API's custom service:

Copy
Copied
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 here.

You need to use Oauth2ClientCredentialsOperationHandlerAuth for services of this kind.

2.2 Password grant flow

info

You can read more about this grant type here.

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 OAuth1 and how does it works.

You need to use Oauth1OperationHandlerAuth for services of this kind.