Class: PatreonOauthClient
Defined in: oauth/v2/client.ts:153
Constructors
Constructor
new PatreonOauthClient(
options,rest):PatreonOauthClient
Defined in: oauth/v2/client.ts:162
Parameters
| Parameter | Type |
|---|---|
options | PatreonOauthClientOptions |
rest | RestClient |
Returns
PatreonOauthClient
Properties
| Property | Modifier | Type | Default value | Description |
|---|---|---|---|---|
cachedToken | public | string | Oauth2CreatorToken | Oauth2StoredToken | undefined | undefined | The last (updated) token that is stored. This is only updated when using token validation and the token is refreshed. |
options | public | Required<Omit<OauthClientOptions, "token">> & Partial<Oauth2RedirectOptions> | undefined | - |
Accessors
oauthUri
Get Signature
get oauthUri():
string
Defined in: oauth/v2/client.ts:357
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
Throws
if the oauth client id and secret are not defined in the client options
Returns
string
the url to use for redirecting the user to
userAgent
Get Signature
get userAgent():
string
Defined in: oauth/v2/client.ts:194
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: oauth/v2/client.ts:371
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
Throws
if the oauth client id and secret are not defined in the client options
fetch()
fetch<
Query>(path,query,options?):Promise<GetResponsePayload<Query>>
Defined in: oauth/v2/client.ts:205
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<Oauth2StoredToken|undefined>
Defined in: oauth/v2/client.ts:297
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<Oauth2StoredToken | undefined>
Returns the token on success. Returns undefined for missing code or missing redirect uri.
Throws
on a failed request: can be e.g. because of missing permissions or invalid code
Throws
if the oauth client id and secret are not defined in the client options
paginate()
paginate<
Query>(path,query,options?):AsyncGenerator<GetResponsePayload<Query>,number,unknown>
Defined in: oauth/v2/client.ts:239
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: oauth/v2/client.ts:331
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
Throws
if the oauth client id and secret are not defined in the client options