- About
- Documentation
- Requirements
- Installation
- Quickstart
- Building and Running Sample App
- Project Structure
- Code Structure
- Running Tests
Twilio Passkeys Web SDK enables developers to easily add Passkeys into their existing authentication flows within their own web applications. The Verify Passkeys SDK supports passkeys creation and authentication using the FIDO/WebAuthn industry standard.
- Node.js v20.x or higher
- Add the library to your project
npm install @twilio/twilio-verify-passkeys-web
npm install https://github.com/twilio/twilio-verify-passkeys-web.git
<script src="https://unpkg.com/@twilio/twilio-verify-passkeys-web@0.0.1/dist/twilio-verify-passkeys.iife.js"></script>
Use the TwilioPasskeys
instance to create a registration by calling the create(String)
function.
The create
method receive a param that represent a challenge payload, check how to create challenge payload.
You can also call create(CreatePasskeysRequest)
, where the CreatePasskeysRequest
is wrapper object of a creation challenge payload schema.
const createPasskeysResult = twilioPasskeys.create(challengePayload)
if(createPasskeysResult.Error !== null) {
// verify the createPasskeyResult.createPasskeyResponse against your backend and finish sign up
} else {
// handle error
}
Use the TwilioPasskeys
instance to authenticate a user by calling the authenticate(String)
function.
The authenticate
method receive a param that represent an authentication request, it follows the schema of an authentication challenge payload.
You can also call authenticate(AuthenticatePasskeysRequest)
, where the AuthenticatePasskeysRequest
is a wrapper object of an authentication challenge payload.
const authenticatePasskeyResult = twilioPasskeys.authenticate(authenticationRequest)
if(authenticatePasskeyResult.Error !== null) {
// verify the authenticatePasskeyResult.authenticatePasskeyResponse against your backend
} else {
// handle error
}
The challenge payload for creating a registration is a String obtained by requesting your backend a challenge for registering a user, it uses the JSON schema:
{"rp":{"id":"your_backend","name":"PasskeySample"},"user":{"id":"WUV...5Ng","name":"1234567890","displayName":"1234567890"},"challenge":"WUY...jZQ","pubKeyCredParams":[{"type":"public-key","alg":-7}],"timeout":600000,"excludeCredentials":[],"authenticatorSelection":{"authenticatorAttachment":"platform","requireResidentKey":false,"residentKey":"preferred","userVerification":"preferred"},"attestation":"none"}
The challenge payload for authenticating a user is a JSON with the schema:
{"publicKey":{"challenge":"WUM...2Mw","timeout":300000,"rpId":"your_backend","allowCredentials":[],"userVerification":"preferred"}}
- ngrok
- Clone this repository.
- Install the dependencies using
npm install
- Make sure you have setup your backend
- Go to the
config.js
file inside thesample-app
folder and replace the backend url with your backend url - Run the following command to build and run a local server with the sample app
npm run demo
- The previous step will open a browser tap with the localhost server running at port
8080
, run ngrok for that port:
ngrok http http://localhost:8080
- Open the sample app in your browser using the url that ngrok provides:
https://example.ngrok.app/sample-app/
-
Setup a backend throught the function template of passkeys-backend
-
Make sure you already added support for digital asset links, this should be inside a file called
assetlinks.json
in your backend, check whether an entry with the following structure:
{
"relation":[
"delegate_permission/common.get_login_creds",
"delegate_permission/common.handle_all_urls"
],
"target":{
"namespace": "web",
"site": "https://example.ngrok.app"
}
},
- Add the ngrok url to the enviroment variables in the field
RP_DOMAIN
if you are using just this sample app.
RP_DOMAIN=example.ngrok.app
- Add the ngrok url to the enviroment variable called
ORIGINS
, using a full url format.
ORIGINS=https://example.ngrok.app
-
src
: Contains all the main code, including business logic, data models, and utility functions. -
sample-app
: This folder contains a simple demo application code that use html and vanilla javascript.
The src
folder constains all the core code. This includes:
- Data models (
src/models
) - Buisness logic (
src/TwilioPasskeys.js
) - Utility functions (
src/utils
)
The sample-app
folder contains a simple demo app code. This includes:
-
Vanilla javascript code that works as code snippets for integrating with the Twilio Verify Passkeys SDK
-
HTML code that works as UI implementation
npm run test
npm run coverage