> ## Documentation Index > Fetch the complete documentation index at: https://www.canva.dev/docs/apps/llms.txt > Use this file to discover all available pages before exploring further. # auth.initOauth API reference for the auth.initOauth method. NOTE: **This API is a preview**. Preview APIs are unstable and may change without warning. You can't release public apps using this API until it's stable. Creates a client for authenticating users with OAuth. To learn more, see [https://www.canva.dev/docs/apps/authenticating-users/oauth](https://www.canva.dev/docs/apps/authenticating-users/oauth). ## Usage: Initialize an OAuth client ```typescript import { auth } from '@canva/user'; const oauth = auth.initOauth(); ``` ## Returns A client for authorizing users with OAuth. Starts an OAuth authorization flow. **Parameters** Options for configuring the authorization flow. Properties of request}> Query parameters to append to the URL of the request. The following keys are not allowed in this object: * `"client_id"` * `"redirect_uri"` * `"scope"` * `"state"` * `"response_type"` * `"code_challenge"` * `"code_challenge_method"` * `"client_secret"` The list of scopes to request access to. **Returns** The result of the authorization flow. This is a `Promise` that resolves with the following object: The result when a user successfully completes an OAuth authorization flow. The status of the authorization flow. The only valid value is `"completed"`. The scopes associated with the user. The result when a user fails to complete an OAuth authorization flow. The status of the authorization flow. The only valid value is `"aborted"`. **Examples** **Start an authorization flow** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth(); // Start an authorization flow const response = await oauth.requestAuthorization(); ``` **Start an authorization flow with specific scopes** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth(); // Define the scopes to request const scope = new Set(['PLACEHOLDER_SCOPE_1', 'PLACEHOLDER_SCOPE_2']); // Start an authorization flow with specific scopes const response = await oauth.requestAuthorization({ scope }); ``` **Start an authorization flow with custom query parameters** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth(); // Define the query parameters to append to the URL of the request const queryParams = new Map([['custom_param', 'custom_value']]); // Start an authorization flow with custom query parameters const response = await oauth.requestAuthorization({ queryParams }); ``` **Handle the result of a authorization flow** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth(); // Start an authorization flow const response = await oauth.requestAuthorization(); if (response.status === 'completed') { // The user completed the authorization flow } if(response.status === 'aborted') { // The user did not complete the authorization flow } ``` Gets the access token and scopes for the current user. * When a token expires, it's automatically refreshed by Canva. * The token is cached by Canva, so the app's frontend shouldn't store the token. **Parameters** Options for requesting an access token for the current user. Properties of request}> If `true`, the access token will be refreshed, even if it hasn't expired. By default, access tokens are automatically refreshed after expiry. The scopes associated with the access token. **Returns** The access token and scopes for the current user, or `null` if the user isn't authorized. This is a `Promise` that resolves with either `undefined` or the following object: The access token for the current user. The scopes associated with the current user's access token. The subdomain associated with the access token. **Examples** **Get the access token of the current user** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth(); // Get an access token for the user const token = await oauth.getAccessToken(); ``` **Check if the user is authorized** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth(); // Get an access token for the user const token = await oauth.getAccessToken(); if (token) { // The user is authorized } else { // The user is not authorized } ``` **Forcefully refresh an access token** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth(); // Forcefully refresh an access token const token = await oauth.getAccessToken({ forceRefresh: true }); ``` Disconnects the user from the identity provider (IdP). If token revocation is supported by the OAuth provider, the refresh and access tokens will be revoked. **Returns** An empty `Promise` that resolves once the user is disconnected from the IdP. `Promise` **Example: Disconnect an authorized user from the identity provider (IdP)** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth(); // Disconnect the user from the IdP await oauth.deauthorize(); ``` Initializes an OAuth client for a single account. ## Parameters Options for initializing the oauth client Properties of options}> The provider to initialize the oauth client for The type of oauth client to initialize The only valid value is `"single_account"`. ## Returns A client for authorizing users with OAuth. Starts an OAuth authorization flow. **Parameters** Options for configuring the authorization flow. Properties of request}> Query parameters to append to the URL of the request. The following keys are not allowed in this object: * `"client_id"` * `"redirect_uri"` * `"scope"` * `"state"` * `"response_type"` * `"code_challenge"` * `"code_challenge_method"` * `"client_secret"` The list of scopes to request access to. **Returns** The result of the authorization flow. This is a `Promise` that resolves with the following object: The result when a user successfully completes an OAuth authorization flow. The status of the authorization flow. The only valid value is `"completed"`. The scopes associated with the user. The result when a user fails to complete an OAuth authorization flow. The status of the authorization flow. The only valid value is `"aborted"`. **Examples** **Start an authorization flow** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth(); // Start an authorization flow const response = await oauth.requestAuthorization(); ``` **Start an authorization flow with specific scopes** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth(); // Define the scopes to request const scope = new Set(['PLACEHOLDER_SCOPE_1', 'PLACEHOLDER_SCOPE_2']); // Start an authorization flow with specific scopes const response = await oauth.requestAuthorization({ scope }); ``` **Start an authorization flow with custom query parameters** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth(); // Define the query parameters to append to the URL of the request const queryParams = new Map([['custom_param', 'custom_value']]); // Start an authorization flow with custom query parameters const response = await oauth.requestAuthorization({ queryParams }); ``` **Handle the result of a authorization flow** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth(); // Start an authorization flow const response = await oauth.requestAuthorization(); if (response.status === 'completed') { // The user completed the authorization flow } if(response.status === 'aborted') { // The user did not complete the authorization flow } ``` Gets the access token and scopes for the current user. * When a token expires, it's automatically refreshed by Canva. * The token is cached by Canva, so the app's frontend shouldn't store the token. **Parameters** Options for requesting an access token for the current user. Properties of request}> If `true`, the access token will be refreshed, even if it hasn't expired. By default, access tokens are automatically refreshed after expiry. The scopes associated with the access token. **Returns** The access token and scopes for the current user, or `null` if the user isn't authorized. This is a `Promise` that resolves with either `undefined` or the following object: The access token for the current user. The scopes associated with the current user's access token. The subdomain associated with the access token. **Examples** **Get the access token of the current user** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth(); // Get an access token for the user const token = await oauth.getAccessToken(); ``` **Check if the user is authorized** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth(); // Get an access token for the user const token = await oauth.getAccessToken(); if (token) { // The user is authorized } else { // The user is not authorized } ``` **Forcefully refresh an access token** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth(); // Forcefully refresh an access token const token = await oauth.getAccessToken({ forceRefresh: true }); ``` Disconnects the user from the identity provider (IdP). If token revocation is supported by the OAuth provider, the refresh and access tokens will be revoked. **Returns** An empty `Promise` that resolves once the user is disconnected from the IdP. `Promise` **Example: Disconnect an authorized user from the identity provider (IdP)** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth(); // Disconnect the user from the IdP await oauth.deauthorize(); ``` Initializes an OAuth client for a multi account. ## Parameters Options for initializing the oauth client Properties of options}> The provider to initialize the oauth client for The type of oauth client to initialize The only valid value is `"multi_account"`. ## Returns A client for authorizing users with OAuth. **Parameters** Options for configuring the authorization flow. Properties of request}> Query parameters to append to the URL of the request. The following keys are not allowed in this object: * `"client_id"` * `"redirect_uri"` * `"scope"` * `"state"` * `"response_type"` * `"code_challenge"` * `"code_challenge_method"` * `"client_secret"` The list of scopes to request access to. **Returns** The result of the authorization flow. This is a `Promise` that resolves with the following object: The result when a user successfully completes an OAuth authorization flow. The status of the authorization flow. The only valid value is `"completed"`. The scopes associated with the user. The result when a user fails to complete an OAuth authorization flow. The status of the authorization flow. The only valid value is `"aborted"`. **Examples** **Start an authorization flow** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth({ type: 'multi_account' }); // Start an authorization flow const response = await oauth.requestAuthorization(); ``` **Start an authorization flow with specific scopes** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth({ type: 'multi_account' }); // Define the scopes to request const scope = new Set(['PLACEHOLDER_SCOPE_1', 'PLACEHOLDER_SCOPE_2']); // Start an authorization flow with specific scopes const response = await oauth.requestAuthorization({ scope }); ``` **Start an authorization flow with custom query parameters** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth(); // Define the query parameters to append to the URL of the request const queryParams = new Map([['custom_param', 'custom_value']]); // Start an authorization flow with custom query parameters const response = await oauth.requestAuthorization({ queryParams }); ``` **Handle the result of a authorization flow** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth(); // Start an authorization flow const response = await oauth.requestAuthorization(); if (response.status === 'completed') { // The user completed the authorization flow } if(response.status === 'aborted') { // The user did not complete the authorization flow } ``` **Returns** The result of requesting a list of accounts. This is a `Promise` that resolves with the following object: A client for managing a single OAuth account. Properties of accounts}> The ID of the account. The display name of the account. Whether the access token for the account has expired and there is no associated refresh token. Gets the access token and scopes for the current OAuth account. * When a token expires, it's automatically refreshed by Canva. * The token is cached by Canva, so the app's frontend shouldn't store the token. **Parameters** Options for requesting an access token for the current OAuth account. Properties of request}> If `true`, the access token will be refreshed, even if it hasn't expired. By default, access tokens are automatically refreshed after expiry. The scopes associated with the access token. **Returns** The access token and scopes for the current OAuth account, or `null` if the account isn't authorized. This is a `Promise` that resolves with either `undefined` or the following object: The access token for the current user. The scopes associated with the current user's access token. The subdomain associated with the access token. **Examples** **Get the access token of the current OAuth account** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth({ type: 'multi_account' }); // Get the account const account = await oauth.getAccount({ accountId: '123' }); // Get an access token for the account const token = await oauth.getAccessToken(); ``` **Check if the account is authorized** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth({ type: 'multi_account' }); // Get an access token for the account const account = await oauth.getAccount({ accountId: '123' }); const token = await account.getAccessToken(); if (token) { // The account is authorized } else { // The account is not authorized } ``` **Forcefully refresh an access token** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth({ type: 'multi_account' }); // Get the account const account = await oauth.getAccount({ accountId: '123' }); // Forcefully refresh an access token const token = await account.getAccessToken({ forceRefresh: true }); ``` Deauthorizes the account. **Returns** An empty `Promise` that resolves once the account is deauthorized. `Promise` **Example: Deauthorize an authorized account** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth({ type: 'multi_account' }); // Get the account const account = await oauth.getAccount({ accountId: '123' }); // Deauthorize the account await account.deauthorize(); ``` The principal of the account (e.g., email, username). The avatar URL of the account. The subdomain associated with the OAuth account. **Parameters** Options for requesting a single OAuth account. Properties of request}> **Returns** The result of requesting a single account. This is a `Promise` that resolves with the following object: A client for managing a single OAuth account. Properties of account}> The ID of the account. The display name of the account. Whether the access token for the account has expired and there is no associated refresh token. Gets the access token and scopes for the current OAuth account. * When a token expires, it's automatically refreshed by Canva. * The token is cached by Canva, so the app's frontend shouldn't store the token. **Parameters** Options for requesting an access token for the current OAuth account. Properties of request}> If `true`, the access token will be refreshed, even if it hasn't expired. By default, access tokens are automatically refreshed after expiry. The scopes associated with the access token. **Returns** The access token and scopes for the current OAuth account, or `null` if the account isn't authorized. This is a `Promise` that resolves with either `undefined` or the following object: The access token for the current user. The scopes associated with the current user's access token. The subdomain associated with the access token. **Examples** **Get the access token of the current OAuth account** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth({ type: 'multi_account' }); // Get the account const account = await oauth.getAccount({ accountId: '123' }); // Get an access token for the account const token = await oauth.getAccessToken(); ``` **Check if the account is authorized** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth({ type: 'multi_account' }); // Get an access token for the account const account = await oauth.getAccount({ accountId: '123' }); const token = await account.getAccessToken(); if (token) { // The account is authorized } else { // The account is not authorized } ``` **Forcefully refresh an access token** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth({ type: 'multi_account' }); // Get the account const account = await oauth.getAccount({ accountId: '123' }); // Forcefully refresh an access token const token = await account.getAccessToken({ forceRefresh: true }); ``` Deauthorizes the account. **Returns** An empty `Promise` that resolves once the account is deauthorized. `Promise` **Example: Deauthorize an authorized account** ```ts import { auth } from "@canva/user"; // Initialize an OAuth client const oauth = auth.initOauth({ type: 'multi_account' }); // Get the account const account = await oauth.getAccount({ accountId: '123' }); // Deauthorize the account await account.deauthorize(); ``` The principal of the account (e.g., email, username). The avatar URL of the account. The subdomain associated with the OAuth account. ## Rate limit This method has a rate limit of 10 requests every 10 seconds.