TwurpleAuthenticationGetting dataExamplesFAQMigration

RefreshingAuthProvider

An auth provider with the ability to make use of refresh tokens, automatically refreshing the access token whenever necessary.

Overview

Constructor

new RefreshingAuthProvider(refreshConfig)

Creates a new auth provider based on the given one that can automatically refresh access tokens.

ParameterTypeRequiredDefaultDescription
refreshConfigRefreshingAuthProviderConfignone

The information necessary to automatically refresh an access token.

Properties

clientId

Type: string

The client ID.

onRefresh

Type: EventBinder<[userId: string, token: AccessToken]>

Fires when a user token is refreshed.

onRefreshFailure

Type: EventBinder<[userId: string]>

Fires when a user token fails to refresh.

Methods

addIntentsToUser(user, intents)

Adds intents to a user.

Any intents that were already set before will be overwritten to point to this user instead.

ParameterTypeRequiredDefaultDescription
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

none

The user to add intents to.

intentsstring[]none

The intents to add to the user.

Return type: void

addUser(user, initialToken, intents)

Adds the given user with their corresponding token to the provider.

ParameterTypeRequiredDefaultDescription
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

none

The user to add.

initialTokenMakeOptional<AccessToken, "accessToken" | "scope">none

The token for the user.

intentsstring[]none

The intents to add to the user.

Any intents that were already set before will be overwritten to point to this user instead.

Return type: void

addUserForCode(code, intents)

async

Gets an OAuth token from the given authorization code and adds the user to the provider.

An authorization code can be obtained using the OAuth Authorization Code flow.

ParameterTypeRequiredDefaultDescription
codestringnone

The authorization code.

intentsstring[]none

The intents to add to the user.

Any intents that were already set before will be overwritten to point to the associated user instead.

Return type: string

addUserForToken(initialToken, intents)

async

Figures out the user associated to the given token and adds them to the provider.

If you already know the ID of the user you're adding, consider using RefreshingAuthProvider#addUser instead.

ParameterTypeRequiredDefaultDescription
initialTokenMakeOptional<AccessToken, "accessToken" | "scope">none

The token for the user.

intentsstring[]none

The intents to add to the user.

Any intents that were already set before will be overwritten to point to the associated user instead.

Return type: string

getAccessTokenForIntent(intent, scopeSets)

async

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

ParameterTypeRequiredDefaultDescription
intentstringnone

The intent to fetch a token for.

scopeSets(?string[])[]none

The requested scopes.

Return type: AccessTokenWithUserId | null

getAccessTokenForUser(user, scopeSets)

async

Gets an access token for the given user.

ParameterTypeRequiredDefaultDescription
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

none

The user to get an access token for.

scopeSets(?string[])[]none

The requested scopes.

Return type: AccessTokenWithUserId | null

getAnyAccessToken(user)

async

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

ParameterTypeRequiredDefaultDescription
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

none

The user.

getAppAccessToken(forceNew)

async

Fetches an app access token.

ParameterTypeRequiredDefaultDescription
forceNewbooleanfalse

Whether to always get a new token, even if the old one is still deemed valid internally.

Return type: AccessToken

getCurrentScopesForUser(user)

Gets the scopes that are currently available using the access token.

ParameterTypeRequiredDefaultDescription
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

none

The user to get the current scopes for.

Return type: string[]

getIntentsForUser(user)

Gets all intents assigned to the given user.

ParameterTypeRequiredDefaultDescription
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

none

The user to get intents of.

Return type: string[]

hasUser(user)

Checks whether a user was added to the provider.

ParameterTypeRequiredDefaultDescription
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

none

The user to check.

Return type: boolean

refreshAccessTokenForIntent(intent)

async

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

ParameterTypeRequiredDefaultDescription
intentstringnone

The intent to refresh the token for.

refreshAccessTokenForUser(user)

async

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

ParameterTypeRequiredDefaultDescription
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

none

The user to refresh the token for.

removeIntents(intents)

Removes all given intents from any user who they might be assigned to.

Intents that have not been assigned are silently ignored.

ParameterTypeRequiredDefaultDescription
intentsstring[]none

The intents to remove.

Return type: void

removeUser(user)

Removes a user from the provider.

This also makes all intents this user was assigned to unusable.

ParameterTypeRequiredDefaultDescription
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

none

The user to remove.

Return type: void