WebAuthn (Web SDK Only)
You can allow your users to sign up and log in to your web app with a FIDO2 device (YubiKey) or with biometrics (Touch ID).
Use a YubiKey or your finger to log in
π Try the demo
π View the demo's code
Installation
WebAuthn works as an extension to Magic SDK. To add WebAuthn to your Magic integration, follow these steps to install the WebAuthn Extension:
In your project, run
npm install magic-sdk @magic-ext/webauthnCreate your Magic SDK instance with the OAuth extension:
import { Magic } from 'magic-sdk';import { WebAuthnExtension } from "@magic-ext/webauthn";const magic = new Magic('YOUR_API_KEY', {extensions: [new WebAuthnExtension()],});
Methods
RegisterNewUser
Arguments
registerNewUser({username, nickname? = ββ})
| Parameter | Type | Definition |
|---|---|---|
username | String | The username to register with. |
nickname? | String | The nickname of the WebAuthn device user wants to set. |
Returns
PromiEvent<string | null>: The promise resolves upon authentication request success and rejects with a specific error code if the request fails. The resolved value is a Decentralized ID token with a default 15-minute lifespan.
Example
Error
Login
Arguments
login({username})
| Parameter | Type | Definition |
|---|---|---|
username | String | The username to log in with. |
Returns
PromiEvent<string | null>: The promise resolves upon authentication request success and rejects with a specific error code if the request fails. The resolved value is a Decentralized ID token with a default 15-minute lifespan.
Example
Error
GetMetadata
Arguments
None
Returns
PromiEvent<{ devicesInfo, username }>: an object containing the WebAuthn devices information and username of the authenticated user.
| Value | Type | Definition |
|---|---|---|
devicesInfo | Array | List of devices info contains device id, device nickname, transport, user agent |
username | String | Username of the authenticated user. |
Example
RegisterNewDevice
Arguments
registerNewDevice(nickname? = ββ)
| Parameter | Type | Definition |
|---|---|---|
nickname | String | The nickname of the WebAuthn device user wants to set. |
Returns
PromiEvent<boolean>: The promise resolves with a true boolean value if register webauthn device is successful and rejects with a specific error code if the request fails.
Example
Error
UpdateInfo
Arguments
updateInfo({id: βwebauthn info idβ,nickname: βubk})
| Parameter | Type | Definition |
|---|---|---|
nickname | String | The nickname of the WebAuthn device user wants to set. |
id | String | The WebAuthn Id returned from getMetaData function's devicesInfo field. |
Returns
PromiEvent<boolean>: The promise resolves with a true boolean value if update webauthn device nickname is successful and rejects with a specific error code if the request fails.
Example
UnregisterWebAuthnDevice
Arguments
unregisterWebAuthnDevice(id: 'webauthn info id')
| Parameter | Type | Definition |
|---|---|---|
id | String | The WebAuthn Id returned from getMetaData function's devicesInfo field. |
Returns
PromiEvent<boolean>: The promise resolves with a true boolean value if unregister webauthn device is successful and rejects with a specific error code if the request fails.