UNPKG

@passageidentity/passage-flex-react-native

Version:

Passkey Flex for React Native - Add native passkey authentication to your own React Native authentication flows with Passage by 1Password

90 lines (86 loc) 3.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PassageFlexPasskey = void 0; var _reactNative = require("react-native"); var _index = require("../PassageFlex/index.js"); var _index2 = require("./index.js"); /** * The base class for utilizing Apple's native passkey APIs and Passage Flex APIs together. */ class PassageFlexPasskey { constructor(appId) { this.appId = appId; } /** * Checks if the user's device supports passkeys. */ isSupported = () => { if (_reactNative.Platform.OS === 'ios') { const iosVersion = parseFloat(_reactNative.Platform.Version); return iosVersion >= 16; } else if (_reactNative.Platform.OS === 'android') { const androidVersion = _reactNative.Platform.Version; return androidVersion >= 28; } else { return false; // Unsupported platform } }; /** * Registers a new passkey. * * Prompts the user associated with the provided Passage `transactionId` to create and register a new * passkey for use with your app. * * - Parameters: * - transactionId: The Passage transaction id provided by your app's server. * - authenticatorAttachment: (Optional) The type of authentication that will be used in this * WebAuthN flow request. Defaults to `.platform`. Use `.cross-platform` for physical security * key registration. * * - Returns: A single-use "nonce" from Passage server to be exchanged for an authentication token on * your app's server. * * - Throws: `PassageFlexPasskeyError` when passkey authorization fails. */ register = async transactionId => { this.checkForPasskeySupport(); try { const nonce = await _index.PassageFlexReactNative.register(transactionId); return nonce; } catch (error) { throw new _index2.PassageFlexPasskeyError(error.code, error.message); } }; /** * Authenticates with a passkey. * * Prompts the user to select a passkey for authentication for your app. If a Passage `transactionId` is provided, * this method will attempt to show only passkeys associated with that user account. * * - Parameters: * - transactionId: (Optional) The Passage transaction id provided by your app's server. * * - Returns: A single-use "nonce" from Passage server to be exchanged for an authentication token on * your app's server. * * - Throws: `PassageFlexPasskeyError` when passkey authorization fails. */ authenticate = async (transactionId = null) => { this.checkForPasskeySupport(); try { const nonce = await _index.PassageFlexReactNative.authenticate(transactionId); return nonce; } catch (error) { throw new _index2.PassageFlexPasskeyError(error.code, error.message); } }; checkForPasskeySupport = () => { if (!this.isSupported) { throw new _index2.PassageFlexPasskeyError(_index2.PasskeyErrorCode.PasskeysNotSupported, 'device does not support passkeys'); } }; } exports.PassageFlexPasskey = PassageFlexPasskey; //# sourceMappingURL=PassageFlexPasskey.js.map