The OAuth2 class provides a robust interface for managing OAuth 2.0 authorization flows in Scripting. It supports standard authorization code flows, PKCE (Proof Key for Code Exchange), access token renewal, and customizable token handling.
| Name | Type | Required | Description |
|---|---|---|---|
| consumerKey | string | Yes | The application's client ID or consumer key. |
| consumerSecret | string | Yes | The application's client secret. |
| authorizeUrl | string | Yes | The URL where the user will be redirected for authorization. |
| accessTokenUrl | string | No | The endpoint to request the access token. If omitted, authorizeUrl is used. |
| responseType | string | Yes | Typically "code" for the Authorization Code Grant flow. |
| contentType | string | No | Content type for token requests. Defaults to "application/x-www-form-urlencoded". |
accessTokenBasicAuthentification: booleanEnable this to use HTTP Basic authentication when exchanging the authorization code for an access token. Default is false.
allowMissingStateCheck: booleanDisables CSRF protection based on state parameter validation. Use with caution. Default is false.
encodeCallbackURL: booleanEncodes the callback URL when generating the authorization URL. Required by some providers. Default is true.
encodeCallbackURLQuery: booleanControls whether the entire query string is encoded. Some services (e.g., Imgur) require this to be false. Default is true.
authorize(options): Promise<OAuthCredential>Initiates the OAuth2 authorization flow, opening a browser window for the user to log in and grant permissions.
| Name | Type | Required | Description |
|---|---|---|---|
| callbackURL | string | No | Custom redirect URI. Default is scripting://oauth_callback/{current_script_encoded_name}. |
| scope | string | Yes | Space-separated list of requested scopes. |
| state | string | Yes | A unique string used to prevent CSRF attacks. |
| parameters | Record<string, any> | No | Extra query parameters to send in the authorization request. |
| headers | Record<string, string> | No | Extra headers to send in the request. |
| codeVerifier | string | Conditional | Raw random string used in PKCE flow. |
| codeChallenge | string | Conditional | Hashed version of the code verifier. |
| codeChallengeMethod | "plain" | "S256" | Conditional | Hashing method for code challenge. Default is "S256". |
OAuthCredential object containing tokens and metadata.renewAccessToken(options): Promise<OAuthCredential>Exchanges a refresh token for a new access token from the provider.
| Name | Type | Required | Description |
|---|---|---|---|
| refreshToken | string | Yes | The refresh token previously obtained. |
| parameters | Record<string, any> | No | Additional POST body parameters. |
| headers | Record<string, string> | No | Additional headers for the request. |
OAuthCredential object.The OAuthCredential object contains all relevant information from a successful OAuth2 transaction.
| Field | Type | Description |
|---|---|---|
| oauthToken | string | Access token to authorize requests to the API. |
| oauthTokenSecret | string | Token secret for request signing (used in OAuth1.0-like flows). |
| oauthRefreshToken | string | Token used to refresh the access token. |
| oauthTokenExpiresAt | number | null | Expiration time in Unix timestamp (ms). null if no expiration. |
| oauthVerifier | string | Verifier used for PKCE validation. |
| version | string | OAuth version (e.g., "2.0"). |
| signatureMethod | string | Method used to sign requests (e.g., "HMAC-SHA1", "PLAINTEXT"). |
state to protect against CSRF attacks unless explicitly disabled.Script.createOAuthCallbackURLScheme(name) to generate script-specific callback URLs.oauthRefreshToken if long-term access is needed.