Javascript
Examples for dynamic interactions
You will interact with the authenticators through an HTML page and Javascript using the Webauthn API.
A package is available at https://github.com/web-auth/webauthn-helper. It contains functions that will ease the interaction with the login or the registration endpoints.
It is mandatory to use the HTTPS scheme to use Webauthn otherwise it will not work.
Installation
You can use npm or yarn to install the package:
npm i @web-auth/webauthn-helper
#or
yarn add @web-auth/webauthn-helperRegistration
// Import the registration hook
import {useRegistration} from 'webauthn-helper';
// Create your register function.
// By default the urls are "/register" and "/register/options"
// but you can change those urls if needed.
const register = useRegistration({
actionUrl: '/api/register',
optionsUrl: '/api/register/options'
});
// We can call this register function whenever we need (e.g. form submission)
register({
username: 'john.doe',
displayName: 'JD'
})
.then((response) => console.log('Registration success'))
.catch((error) => console.log('Registration failure'))
;Additional options can be set during the registration process. See the section “Deep into the framework” to know more. Hereafter another example:
Authentication
As done during the registration, additional options are available. See the section “Deep into the framework” to know more. Hereafter another example:
Last updated
Was this helpful?