TwurpleAuthenticationGetting dataExamplesFAQMigration

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. RefreshingAuthProvider can make use of refresh tokens to refresh your tokens on expiry or failure.

{
The type of Authorization header to send. Defaults to "Bearer".
The client ID.
clientId: string
Fetches a token for a user identified by the given intent defined by the provider.
getAccessTokenForIntent?: (intent: string, scopeSets: (?string[])[]) => Promise<AccessTokenWithUserId | null>
Fetches a token for the given user.
getAccessTokenForUser: (user:
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

, scopeSets: (?string[])[]) => Promise<AccessTokenWithUserId | null>
Fetches any token to use with a request that supports both user and app tokens, i.e. public data relating to a user.
getAnyAccessToken: (user:
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

) => Promise<AccessTokenMaybeWithUserId>
Fetches an app token.
getAppAccessToken?: (forceNew: boolean) => Promise<AccessToken>
Gets the scopes that are currently available using the access token for a user.
getCurrentScopesForUser: (user:
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

) => string[]
Requests that the provider fetches a new token from Twitch for the given intent.
refreshAccessTokenForIntent?: (intent: string) => Promise<AccessTokenWithUserId>
Requests that the provider fetches a new token from Twitch for the given user.
refreshAccessTokenForUser?: (user:
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

) => Promise<AccessTokenWithUserId>
}

Properties

authorizationType

Type: ?string

The type of Authorization header to send. Defaults to "Bearer".

clientId

Type: string

The client ID.

getAccessTokenForIntent

Type: ?(intent: string, scopeSets: (?string[])[]) => Promise<AccessTokenWithUserId | null>

Fetches a token for a user identified by the given intent defined by the provider.

An intent is an arbitrary string that denotes a responsibility of a user's access token. For example, having the "chat" intent means that the token will be used to connect to chat by default.

Intents are uniquely given to a single user, i.e. one intent can only be set to one user, but one user can be used for multiple intents.

This is optional to implement, but required if you want to use the ChatClient, as it accesses its connection credentials using an intent.

getAccessTokenForUser

Type: (user:
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

, scopeSets: (?string[])[]) => Promise<AccessTokenWithUserId | null>

Fetches a token for the given user.

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.

getAnyAccessToken

Type: (user:
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

) => Promise<AccessTokenMaybeWithUserId>

Fetches any token to use with a request that supports both user and app tokens, i.e. public data relating to a user.

Useful for resources that are public, but where you app needs to access the data in the context of the different users in order to not reach the rate limits for your app token.

If there is no user, this should probably return an app token, but it can also return a user token in case you don't have access to app tokens.

getAppAccessToken

Type: ?(forceNew: boolean) => Promise<AccessToken>

Fetches an app token.

Optional, for cases where you can't get a client secret in any way.

getCurrentScopesForUser

Type: (user:
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

) => string[]

Gets the scopes that are currently available using the access token for a user.

refreshAccessTokenForIntent

Type: ?(intent: string) => Promise<AccessTokenWithUserId>

Requests that the provider fetches a new token from Twitch for the given intent.

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, or you don't want to support intents.

refreshAccessTokenForUser

Type: ?(user:
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

) => Promise<AccessTokenWithUserId>

Requests that the provider fetches a new token from Twitch for the given user.

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.