Code exchange
Following a successful registration or authentication operation, your frontend will receive a code. This can be exchanged for an ExtendedPrincipal, representing the outcome of the operation:
import { Passlock } from '@passlock/browser';
const passlock = new Passlock({ tenancyId });
const result = await passlock.authenticatePasskey({ authenticationToken});
if (result.success) { // send this to your backend console.log(result.value.code);}import { Passlock } from '@passlock/server';
const passlock = new Passlock({ tenancyId, apiKey });
const result = await passlock.exchangeCode({ code });
if (result.success) { // will be an ExtendedPrincipal console.log(result.value);}Using the REST API
Section titled “Using the REST API”Behind the scenes, exchangeCode makes a REST call to the Passlock API. If you prefer you can make the call yourself:
GET /v2/{tenancyId}/principal/{code} HTTP/1.1Host: https://api.passlock.devAccept: application/jsonAuthorization: Bearer {apiKey}