RefreshingAuthProvider
An auth provider with the ability to make use of refresh tokens, automatically refreshing the access token whenever necessary.
Overview
Properties
Constructor
new RefreshingAuthProvider(refreshConfig)
Creates a new auth provider based on the given one that can automatically refresh access tokens.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
refreshConfig | RefreshingAuthProviderConfig | none | The information necessary to automatically refresh an access token. |
Properties
onRefresh
Type: EventBinder<[userId: string, token: AccessToken]>
Fires when a user token is refreshed.
onRefreshFailure
Type: EventBinder<[userId: string, error: Error]>
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.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
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. | |
intents | string[] | none | The intents to add to the user. |
addUser(user, initialToken, intents)
Adds the given user with their corresponding token to the provider.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
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. | |
initialToken | MakeOptional<AccessToken, "accessToken" | "scope"> | none | The token for the user. | |
intents | string[] | none | The intents to add to the user. Any intents that were already set before will be overwritten to point to this user instead. |
addUserForCode(code, intents)
asyncGets 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.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
code | string | none | The authorization code. | |
intents | string[] | 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. |
addUserForToken(initialToken, intents)
asyncFigures 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.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
initialToken | MakeOptional<AccessToken, "accessToken" | "scope"> | none | The token for the user. | |
intents | string[] | 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. |
getAccessTokenForIntent(intent, scopeSets)
asyncFetches a token for a user identified by the given intent.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
intent | string | none | The intent to fetch a token for. | |
scopeSets | (?string[])[] | none | The requested scopes. |
getAccessTokenForUser(user, scopeSets)
asyncGets an access token for the given user.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
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. |
getAnyAccessToken(user)
asyncFetches any token to use with a request that supports both user and app tokens, i.e. public data relating to a user.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
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)
asyncFetches an app access token.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
forceNew | boolean | false | Whether to always get a new token, even if the old one is still deemed valid internally. |
getCurrentScopesForUser(user)
Gets the scopes that are currently available using the access token.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
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. |
getIntentsForUser(user)
Gets all intents assigned to the given user.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
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. |
hasUser(user)
Checks whether a user was added to the provider.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
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. |
refreshAccessTokenForIntent(intent)
asyncRequests that the provider fetches a new token from Twitch for the given intent.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
intent | string | none | The intent to refresh the token for. |
refreshAccessTokenForUser(user)
asyncRequests that the provider fetches a new token from Twitch for the given user.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
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.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
intents | string[] | none | The intents to remove. |
removeUser(user)
Removes a user from the provider.
This also makes all intents this user was assigned to unusable.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
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. |