Class: PatreonOauthClient
Defined in: rest/v2/oauth2/client.ts:101
Constructors
Constructor
new PatreonOauthClient(
options,rest):PatreonOauthClient
Defined in: rest/v2/oauth2/client.ts:115
Parameters
| Parameter | Type |
|---|---|
options | PatreonOauthClientOptions |
rest | RestClient |
Returns
PatreonOauthClient
Properties
| Property | Modifier | Type | Default value | Description |
|---|---|---|---|---|
cachedToken | public | undefined | Oauth2CreatorToken | Oauth2StoredToken | undefined | The last (updated) token that is stored |
onTokenRefreshed? | public | (token) => Promise<void> | undefined | Called when the token is refreshed Default <Client>.putStoredToken(token, true) |
options | public | Required<Omit<OauthClientOptions, "token">> & Partial<Oauth2RedirectOptions> | undefined | - |
Accessors
oauthUri
Get Signature
get oauthUri():
string
Defined in: rest/v2/oauth2/client.ts:339
The uri to redirect users to in the first step of the Oauth flow
Throws
if the redirectUri is not defined or an empty string
Returns
string
the url to use for redirecting the user to
userAgent
Get Signature
get userAgent():
string
Defined in: rest/v2/oauth2/client.ts:153
The user agent header for requests
Returns
string
the (readonly) user agent that is sent on API requests
Methods
createOauthUri()
createOauthUri(
options?):string
Defined in: rest/v2/oauth2/client.ts:352
Create a Oauth2 Authorization uri. This is the first step in the Oauth2 process.
Parameters
| Parameter | Type | Description |
|---|---|---|
options? | Partial<Oauth2RedirectOptions> | The Oauth2 client options |
Returns
string
the uri to redirect the user to in order to authorize this client.
Throws
if the redirectUri is not defined or an empty string, in both the options and client options
fetch()
fetch<
Query>(path,query,options?):Promise<GetResponsePayload<Query>>
Defined in: rest/v2/oauth2/client.ts:218
Make a request to the Patreon API
Type Parameters
| Type Parameter |
|---|
Query extends BasePatreonQuery |
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | the path of the resource |
query | Query | The query wrapper to include more fields |
options? | Oauth2FetchOptions | additional request options |
Returns
Promise<GetResponsePayload<Query>>
the response body, parsed.
getOauthTokenFromCode()
getOauthTokenFromCode(
url):Promise<undefined|Oauth2StoredToken>
Defined in: rest/v2/oauth2/client.ts:294
Get an Oauth token from an redirect request. This request has a code parameter
Parameters
| Parameter | Type | Description |
|---|---|---|
url | string | { code: string; } | The request url, or the code, to use for fetching the access token |
Returns
Promise<undefined | Oauth2StoredToken>
Returns the token on success. Returns undefined for missing code missing redirect uri.
Throws
on a failed request: can be e.g. because of missing permissions or invalid code
paginate()
paginate<
Query>(path,query,options?):AsyncGenerator<GetResponsePayload<Query>,number,unknown>
Defined in: rest/v2/oauth2/client.ts:240
Make a paginated request to the Patreon API. Abort the loop if either condition is met:
- no next cursor
- the previous last item is the same as current last item
- the total amount of items is equal to the fetched amount
Type Parameters
| Type Parameter |
|---|
Query extends BasePatreonQuery |
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | the resource path |
query | Query | the wrapped query to include fields |
options? | Oauth2FetchOptions | additional request options |
Returns
AsyncGenerator<GetResponsePayload<Query>, number, unknown>
the async generator to paginate through the response.
Yields
a page of the request resource
refreshToken()
refreshToken(
token):Promise<Oauth2StoredToken>
Defined in: rest/v2/oauth2/client.ts:321
Update an access token with the refresh token
Parameters
| Parameter | Type | Description |
|---|---|---|
token | string | Oauth2CreatorToken | Oauth2Token | Oauth2StoredToken | The refresh token, or the token with a refresh_token, to use |
Returns
Promise<Oauth2StoredToken>
the updated access token
Throws
on a failed request