Skip to main content
Version: v2

isAuthenticateUrl

Validates that a URL is able to be used by the authenticate function.

Dependencies​

The isAuthenticateUrl function requires the Beyond Identity SDK.

yarn add @beyondidentity/bi-sdk-js

or

npm install @beyondidentity/bi-sdk-js

Prerequisites​

Before making a call to isAuthenticateUrl, you must complete the following prerequisite calls:

  1. Import the required types and functions from the SDK.

    import { Embedded } from '@beyondidentity/bi-sdk-js';
  2. Initialize the SDK.

    // --- Initialize with required arguments
    try {
    const embedded = await Embedded.initialize();
    console.log("Initialization successful", embedded);
    } catch (error) {
    console.error("Initialization failed:", error);
    }

    // --- Initialize with required and optional arguments
    const config = {
    allowedDomains: ["example.com", "another-example.com"],
    logger: function (logType, message) {
    console.log(`[${logType}] ${message}`);
    },
    };

    try {
    const embedded = await Embedded.initialize(config);
    console.log("Initialization successful", embedded);
    } catch (error) {
    console.error("Initialization failed:", error);
    }

Parameters​

ParameterTypeDescription
urlstringRequired. Url to be validated as Beyond Identity passkey authentication url.

Returns​

Returns a boolean.

Examples​

Example: Authenticate only if the provided url is valid​

const url = "authenticate-url";

try {
// Fetch all passkeys for this browser
const passkeys = await embedded.getPasskeys();

// Check if there are any passkeys available
if (passkeys.length > 0) {
// TODO: Instead of automatically selecting the first passkey,
// present a UI to the user to let them select the desired passkey.
// For the purpose of this example, we're using the first passkey.
const passkeyId = passkeys[0].passkeyId;

if (embedded.isAuthenticateUrl(url)) {
// The URL is valid for authenticating against a passkey
const response = await embedded.authenticate(url, passkeyId);
console.log(`Successfully authenticated against passkey bound to this browser. Response: ${JSON.stringify(response)}`);
} else {
console.log("The URL is not a valid Authenticate Passkey URL");
}
} else {
console.log("No passkeys available for this browser");
}
} catch (error) {
console.error(`Error: ${error}`);
}