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 { Passlock } from '@passlock/server';
const tenancyId = "myTenancyId";
const apiKey = "myApiKey";
const passlock = new Passlock({ tenancyId, apiKey });
const result = await passlock.exchangeCode({ code });
if (result.success) {
console.log(result.value);
} else {
console.error(result.error.message);
}
Choose your code style

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}