Skip to content

Code exchange

Following a successful registration or authentication operation, you will receive a code. This can be exchanged for an ExtendedPrincipal, representing the outcome of the operation:

import { exchangeCode, isInvalidCodeError } from '@passlock/server';
const tenancyId = "myTenancyId";
const apiKey = "myApiKey";
try {
const result = await exchangeCode({ code, tenancyId, apiKey });
} catch (e) {
if (isInvalidCodeError(e)) {
console.log("Invalid code");
}
}

Behind the scenes, exchangeCode makes a REST call to the Passlock API. If you prefer you can make the call yourself:

GET /{tenancyId}/principal/{code} HTTP/1.1
Host: https://api.passlock.dev
Accept: application/json
Authorization: Bearer {apiKey}