UNPKG

@digitalpersona/authentication

Version:
51 lines 2.53 kB
import * as u2fApi from 'u2f-api'; import { User, Credential, Ticket } from '@digitalpersona/core'; import { Authenticator } from '../../private'; import { CustomAction } from './actions'; import { U2FClient } from './client'; /** * Universal Second Factor (U2F) authentication API. * U2F support only authentication. Identification is not supported. */ export class U2FAuth extends Authenticator { /** Constructs a new U2F authentication API object. * @param authService - an {@link AuthService|authentication service client} connected to the server. */ constructor(authService) { super(authService, new U2FClient()); } /** Checks is the U2F supported on this platform. * @returns a promise to return `true` is the platform supports U2F or `false` otherwise. * @remarks * To support U2F the user agent must have required API, the web site must use HTTPS, * and the DigitalPersona Web Components server must have properly configured U2F AppId * for the site. */ static isSupported() { return u2fApi.isSupported(); } /** Reads U2F AppID endpoint URL. * @returns a promise to return a U2F AppID endpoint URL. */ getAppId() { return this.authService.CustomAction(CustomAction.RequestAppId, Ticket.None(), User.Anonymous(), new Credential(Credential.U2F, "")).then(data => JSON.parse(data).AppId); } /** Authenticates the user using a user's registered U2F token (FIDO token). * @param identity - a {@link User |username} or a JSON Web Token. * @returns a promise to return a JSON Web Token containing a claim (`crd`) showing the fact * a U2F was used. To resolve the promise, the user must touch the U2F token when prompted. * Will reject if authentication fails or times out. * @remarks * If the `identity` parameter is a user name, a new token will be created. * If the `identity` parameter is a JSON Web Token, an updated token will be returned. * * The user must have a U2F (FIDO) token enrolled in the DigitalPersona server. * The user should insert the token and activate it using a touch or pressing a device button. * The promise returned by the method will be resolved after the user activates the token, * otherwise it will reject with a timeout error. */ authenticate(identity) { return super._authenticate(identity, Credential.U2F); } } //# sourceMappingURL=auth.js.map