UNPKG

@nevis-security/nevis-mobile-authentication-sdk-react

Version:

React Native plugin for Nevis Mobile Authentication SDK. Supports only mobile.

168 lines (166 loc) 7.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OutOfBandAuthenticationImpl = exports.OutOfBandAuthentication = void 0; var _UserInteractionPlatformOperation = require("../../cache/operation/UserInteractionPlatformOperation"); var _PlatformOperationCache = require("../../cache/PlatformOperationCache"); var _OperationErrorConverter = require("../../error/operation/OperationErrorConverter"); var _NativeEventListener = require("../../event/NativeEventListener"); var _MobileAuthenticationSdk = _interopRequireDefault(require("../../MobileAuthenticationSdk")); var _OnSuccessMessage = require("../../model/messages/in/OnSuccessMessage"); var _OutOfBandAuthenticationMessage = require("../../model/messages/out/OutOfBandAuthenticationMessage"); var _HttpOperation = require("../HttpOperation"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** * Copyright © 2023-2024 Nevis Security AG. All rights reserved. */ /** * The operation handling an out-of-band authentication. * * This is the object returned by the SDK, when an {@link OutOfBandPayload} was processed and the * {@link OutOfBandPayload} corresponds to an authentication operation. * * Usage example: * ```ts * class AccountSelectorImpl extends AccountSelector { * async selectAccount( * context: AccountSelectionContext, * handler: AccountSelectionHandler * ): Promise<void> { * await handler.username(username).catch(console.error); * } * } * * class AuthenticatorSelectorImpl extends AuthenticatorSelector { * async selectAuthenticator( * context: AuthenticatorSelectionContext, * handler: AuthenticatorSelectionHandler * ): Promise<void> { * await handler.aaid(aaid).catch(console.error); * } * } * * class PinUserVerifierImpl extends PinUserVerifier { * async verifyPin( * context: PinVerificationContext, * handler: PinVerificationHandler * ): Promise<void> { * await handler.verifyPin(pin).catch(console.error); * } * } * * class BiometricUserVerifierImpl extends BiometricUserVerifier { * async verifyBiometric( * context: BiometricUserVerificationContext, * handler: BiometricUserVerificationHandler * ): Promise<void> { * await handler * .listenForOsCredentials( * BiometricPromptOptions.create( * 'Biometric authentication required', * 'Cancel', * 'Please identify yourself.' * ) * ) * .catch(console.error); * } * } * * async authenticateWithOutOfBand( * client: MobileAuthenticationClient, * payload: OutOfBandPayload * ): Promise<void> { * await client.operations.outOfBandOperation * .payload(payload) * .onRegistration((registration) => { * // handle registration * }) * .onAuthentication((authentication) => { * authentication * .accountSelector(new AccountSelectorImpl()) * .authenticatorSelector(new AuthenticatorSelectorImpl()) * .pinUserVerifier(new PinUserVerifierImpl()) * .biometricUserVerifier(new BiometricUserVerifierImpl()) * .onSuccess((authorizationProvider) => { * // handle success * }) * .onError((error) => { * // handle error * }) * .execute(); * }) * .onError((_error) => { * // handle out-of-band error * }) * .execute(); * } * ``` * * @see {@link OutOfBandOperation.onAuthentication} */ class OutOfBandAuthentication extends _HttpOperation.HttpOperation {} exports.OutOfBandAuthentication = OutOfBandAuthentication; class OutOfBandAuthenticationImpl extends _HttpOperation.HttpOperationImpl { constructor(operationId) { super(); this.operationId = operationId; } accountSelector(accountSelector) { this._accountSelector = accountSelector; return this; } authenticatorSelector(authenticatorSelector) { this._authenticatorSelector = authenticatorSelector; return this; } pinUserVerifier(pinUserVerifier) { this._pinUserVerifier = pinUserVerifier; return this; } passwordUserVerifier(passwordUserVerifier) { this._passwordUserVerifier = passwordUserVerifier; return this; } biometricUserVerifier(biometricUserVerifier) { this._biometricUserVerifier = biometricUserVerifier; return this; } devicePasscodeUserVerifier(devicePasscodeUserVerifier) { this._devicePasscodeUserVerifier = devicePasscodeUserVerifier; return this; } fingerprintUserVerifier(fingerprintUserVerifier) { this._fingerprintUserVerifier = fingerprintUserVerifier; return this; } onSuccess(onSuccess) { this._onSuccess = onSuccess; return this; } onError(onError) { this._onError = onError; return this; } async execute() { const operation = new _UserInteractionPlatformOperation.UserInteractionPlatformOperationImpl(this.operationId, this._accountSelector, this._authenticatorSelector, undefined, undefined, undefined, undefined, this._pinUserVerifier, this._passwordUserVerifier, this._biometricUserVerifier, this._devicePasscodeUserVerifier, this._fingerprintUserVerifier); _PlatformOperationCache.PlatformOperationCache.getInstance().put(operation); _NativeEventListener.NativeEventListener.getInstance().start(this.operationId); const message = new _OutOfBandAuthenticationMessage.OutOfBandAuthenticationMessage(this.operationId, this._accountSelector !== undefined, this._authenticatorSelector !== undefined, false, false, this._pinUserVerifier !== undefined, this._passwordUserVerifier !== undefined, this._biometricUserVerifier !== undefined, this._devicePasscodeUserVerifier !== undefined, this._fingerprintUserVerifier !== undefined, this._onSuccess !== undefined, this._onError !== undefined, this.httpRequestHeaders); const finish = () => { _NativeEventListener.NativeEventListener.getInstance().stop(this.operationId); _PlatformOperationCache.PlatformOperationCache.getInstance().delete(this.operationId); }; return _MobileAuthenticationSdk.default.oobAuthenticate(message).then(data => { finish(); const successMessage = _OnSuccessMessage.OnSuccessMessage.fromJson(data); this._onSuccess?.(successMessage.authorizationProvider); }).catch(error => { finish(); const operationError = new _OperationErrorConverter.OperationErrorConverter(error).convert(); this._onError?.(operationError); }); } } exports.OutOfBandAuthenticationImpl = OutOfBandAuthenticationImpl; //# sourceMappingURL=OutOfBandAuthentication.js.map