On September 25th, 2024, we released v2 of the Apps SDK. To learn what’s new and how to upgrade, see Migration FAQ and Migration guide.

auth.requestAuthentication

API reference for the auth.requestAuthentication method.
This version of the API is deprecated. This version will soon be unsupported. You should use a stable version of the API in your app.

Starts an authentication flow.

To learn more, see Authenticating users.

Usage

import { auth } from "@canva/user";
const response = await auth.requestAuthentication();
switch (response.status) {
case "COMPLETED":
console.log("The authentication was successful.");
break;
case "ABORTED":
console.log("The user exited the authentication flow.");
break;
case "DENIED":
console.log("The user didn't have the required permissions.");
break;
}
TS

Parameters

optionsobject
OPTIONAL

The options for customizing the authentication flow.

options.contextstring
OPTIONAL

A string that's appended to the app's Redirect URL at the start of an authentication flow.

The value of the context parameter must not:

  • Exceed 32 characters
  • Contain sensitive information, such as user data, tokens, or secrets
  • Contain anything not strictly relevant to the authentication flow

Returns

A Promise that resolves with the following object:

resultobject
REQUIRED

The result of the authentication flow.

result.statusstring
REQUIRED

A value that identifies if the authentication flow was successful or not.

This property may contain any of the following values:

  • "COMPLETED" - The user successfully authenticated.
  • "ABORTED" - The user exited the authentication flow.
  • "DENIED" - The user didn't have the required permissions.
result.detailsarray
SOMETIMES REQUIRED

An array of error codes provided by the app. The app can provide these error codes when redirecting the user back to Canva at the end of an authentication flow.