twitcheasy-twitch-bottwitch-authtwitch-auth-tmitwitch-chat-clienttwitch-eventsubtwitch-pubsub-clienttwitch-webhooks

AuthProvider

Describes a class that manages and supplies access tokens.

Ideally, it should be able to request a new access token via user input when previously unauthorized scopes are requested.

As a starting point, StaticAuthProvider takes an access token, but can't do anything to upgrade it by itself. RefreshableAuthProvider is used as a wrapper around another AuthProvider and can make use of refresh tokens.

{
The client ID.
clientId: string
The scopes that are currently available using the access token.
currentScopes: Array<string>
Retrieves an access token from the provider.
getAccessToken: (scopes: string | Array<string>) => Promise<AccessToken | null>
Requests that the provider fetches a new token from Twitch.
refresh?: () => Promise<AccessToken | null>
The type of the tokens generated by the provider, i.e. whether this is a user or app token.
tokenType?:
AuthProviderTokenType

The type of token an auth provider can return - user tokens and app tokens are supported.

Aliased type: "user" | "app"

}

Properties

clientId

Type: string

The client ID.

currentScopes

Type: Array<string>

The scopes that are currently available using the access token.

getAccessToken

Type: (scopes: string | Array<string>) => Promise<AccessToken | null>

Retrieves an access token from the provider.

This should automatically request a new token when the current token is not authorized to use the requested scope(s).

When implementing this, you should not do anything major when no scopes are requested - the cached token should be valid for that - unless you know exactly what you're doing.

refresh

Type: ?() => Promise<AccessToken | null>

Requests that the provider fetches a new token from Twitch.

This method is optional to implement. For some use cases, it might not be desirable to e.g. ask the user to log in again at just any time.

tokenType

Type:
AuthProviderTokenType

The type of token an auth provider can return - user tokens and app tokens are supported.

Aliased type: "user" | "app"

The type of the tokens generated by the provider, i.e. whether this is a user or app token.

If you don't give this information, it's assumed that the provider generates user tokens.