@nevis-security/nevis-mobile-authentication-sdk-react
Version:
React Native plugin for Nevis Mobile Authentication SDK. Supports only mobile.
101 lines (99 loc) • 4.16 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.OutOfBandOperationImpl = exports.OutOfBandOperation = void 0;
var _reactNativeUuid = _interopRequireDefault(require("react-native-uuid"));
var _OutOfBandPlatformOperation = require("../../cache/operation/OutOfBandPlatformOperation");
var _PlatformOperationCache = require("../../cache/PlatformOperationCache");
var _OutOfBandOperationErrorConverter = require("../../error/outOfBand/operation/OutOfBandOperationErrorConverter");
var _MobileAuthenticationSdk = _interopRequireDefault(require("../../MobileAuthenticationSdk"));
var _OperationTypeMessage = require("../../model/messages/in/OperationTypeMessage");
var _OutOfBandOperationMessage = require("../../model/messages/out/OutOfBandOperationMessage");
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 managing an {@link OutOfBandPayload}.
*
* An {@link OutOfBandPayload} can be provided through different means:
* - a push notification,
* - a QR code or
* - an application link.
*
* This operation will process the payload, decrypt it if needed and send it to the server. If the
* payload is successfully handled by the server, then the SDK will identify whether the operation
* associated with the payload is a registration or an authentication. Depending on that the
* {@link onRegistration} or the {@link onAuthentication} will be invoked.
*
* Usage example:
* ```ts
* [...]
* async authenticateUsingOutOfBandPayload(
* client: MobileAuthenticationClient,
* payload: OutOfBandPayload
* ): Promise<void> {
* await client.operations.outOfBandOperation
* .payload(payload)
* .onRegistration((registration) => {
* // handle registration
* })
* .onAuthentication((authentication) => {
* // handle authentication
* })
* .onError((_error) => {
* // handle out-of-band error
* })
* .execute();
* }
* [...]
* ```
*
* @see
* - {@link OutOfBandPayload}
* - {@link OutOfBandRegistration}
* - {@link OutOfBandAuthentication}
*/
class OutOfBandOperation extends _HttpOperation.HttpOperation {}
exports.OutOfBandOperation = OutOfBandOperation;
class OutOfBandOperationImpl extends _HttpOperation.HttpOperationImpl {
payload(payload) {
this._payload = payload;
return this;
}
onRegistration(onRegistration) {
this._onRegistration = onRegistration;
return this;
}
onAuthentication(onAuthentication) {
this._onAuthentication = onAuthentication;
return this;
}
onError(onError) {
this._onError = onError;
return this;
}
async execute() {
const operationId = _reactNativeUuid.default.v4();
const subOperationId = _reactNativeUuid.default.v4();
const operation = new _OutOfBandPlatformOperation.OutOfBandPlatformOperation(operationId, subOperationId, this._onRegistration, this._onAuthentication);
_PlatformOperationCache.PlatformOperationCache.getInstance().put(operation);
const message = new _OutOfBandOperationMessage.OutOfBandOperationMessage(operationId, subOperationId, false, this.onError !== undefined, this.httpRequestHeaders, this._payload, this._onRegistration !== undefined, this._onAuthentication !== undefined);
function finish() {
_PlatformOperationCache.PlatformOperationCache.getInstance().delete(operationId);
}
return _MobileAuthenticationSdk.default.oobOperation(message).then(json => {
const message = _OperationTypeMessage.OperationTypeMessage.fromJson(json);
operation.selectOperation(message.operationType);
finish();
}).catch(error => {
finish();
const operationError = new _OutOfBandOperationErrorConverter.OutOfBandOperationErrorConverter(error).convert();
this._onError?.(operationError);
});
}
}
exports.OutOfBandOperationImpl = OutOfBandOperationImpl;
//# sourceMappingURL=OutOfBandOperation.js.map
;