Code exchange
Following a successful registration or authentication operation, you will receive a code. This can be exchanged for a Principal, representing the outcome of the operation:
import { exchangeCode, isPrincipal } from '@passlock/node/pricipal';
const tenancyId = "myTenancyId";const apiKey = "myApiKey";
// could be a Principal or an errorconst result = await exchangeCode(code, { tenancyId, apiKey });
// use the type guard to ensure we have a Principalif (isPrincipal(result)) { console.log(result);} else { console.error(result.message);}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.1Host: https://api.passlock.devAccept: application/jsonAuthorization: Bearer {apiKey}