Example Implementation
Learn how to utilize the Passkey API using raw HTTP requests without any SDK.
This is an example implementation showing how to use the Passkey API with Node.js and Flask. (We’ll be adding more languages and frameworks soon.)
However, if you’re already using JavaScript/TypeScript for your backend, you can use @teamhanko/passkeys-sdk, which handles all of the below for you.
Otherwise, please make sure to always send JSON with Content-Type: application/json
.
As of writing, for the frontend, the Web Authentication API expects you to pass ArrayBuffer
(instead of plain old objects) in a lot of places, which can be inconvenient.
In the examples below, we use @github/webauthn-json, which is a wrapper for the Web Authentication API to make things easier.
Get your tenant ID and API key
Get your tenant ID and API key from your Hanko Cloud project dashboard.
The base URL for the Passkey API depends on your tenant_id
.
If you self-host the Passkey API, there are endpoints that let you create, list, and manage tenants programmatically. See the API reference.
Add endpoints to start and finish passkey registration
Registering passkeys is a two-step process. First, let’s add an endpoint to our backend.
Backend
Frontend
Here’s what the whole flow looks like
As you can see, there are two steps here (“start” and “finalize”), which pass through the frontend, backend, and Passkey API.
The process looks very similar for logging in — it’s also a two-step process where your frontend, backend, and the Passkey API are involved.
Add endpoints to start and finish logging in
Similar to how registering a passkey is a two-step process, so is logging in.
Backend:
Frontend
For logging in, the server can also talk to the Passkey API directly, instead of going through your backend first. Whether you go with the server-first or client-first approach is up to preference. See Client-First Login Flow.
Was this page helpful?