NMARegistration

@objc
public protocol NMARegistration : NMAHttpOperation

The object that can be used to trigger a registration operation.

Usage example:

@interface NMAAuthenticatorSelectorImpl : NSObject <NMAAuthenticatorSelector>

@end

@implementation NMAAuthenticatorSelectorImpl

- (void)selectAuthenticatorWithContext:(id<NMAAuthenticatorSelectionContext> _Nonnull)context handler:(id<NMAAuthenticatorSelectionHandler> _Nonnull)handler {
    [handler aaid:aaid];
}

@end

@interface NMABiometricUserVerifierImpl : NSObject <NMABiometricUserVerifier>

@end

@implementation NMABiometricUserVerifierImpl

- (void)verifyBiometricWithContext:(id<NMABiometricUserVerificationContext> _Nonnull)context handler:(id<NMABiometricUserVerificationHandler> _Nonnull)handler {
    [handler verify];
}

@end

@interface NMADevicePasscodeUserVerifierImpl : NSObject <NMADevicePasscodeUserVerifier>

@end

@implementation NMADevicePasscodeUserVerifierImpl

- (void)verifyDevicePasscodeWithContext:(id<NMADevicePasscodeUserVerificationContext> _Nonnull)context handler:(id<NMADevicePasscodeUserVerificationHandler> _Nonnull)handler {
    [handler verify];
}

@end

NSURL *serverURL = [[NSURL alloc] initWithString:@"https://server/path"];
id<NMARegistration> registration = [[client operations] registration];

[registration username:username];
[registration serverUrl:serverURL];
[registration authorizationProvider:authorizationProvider];
[registration deviceInformation:[[NMADeviceInformation alloc] initWithName:@"<Device name>" fcmRegistrationToken:@"<FCM token>"]];
[registration authenticatorSelector:[[NMAAuthenticatorSelectorImpl alloc] init]];
[registration biometricUserVerifier:[[NMABiometricUserVerifierImpl alloc] init]];
[registration devicePasscodeUserVerifier:[[NMADevicePasscodeUserVerifierImpl alloc] init]];
[registration onSuccess:^{...}];
[registration onError:^(NMAOperationError * _Nonnull error) {...}];
[registration execute];

The biometric and device Passcode authenticators are enrolled at the OS level. That is why, if one of them must be registered, the user must authenticate through NMABiometricUserVerifier or NMADevicePasscodeUserVerifier. In the case of the PIN, the PIN is enrolled during registration, so no verification is needed.

  • Specifies the username that must be used to register.

    Important

    Providing the username is required.

    Declaration

    Swift

    @discardableResult
    func username(_ username: String) -> NMARegistration

    Parameters

    username

    the username.

    Return Value

    the NMARegistration builder.

  • Specifies the base URL of the server where the registration should be made.

    Note

    If no server URL is provided, then the base URL defined in `baseUrl will be used.

    Important

    It is assumed that all the servers have the same endpoints, thus only the scheme, hostname and port of the URL of the provided URL will be taken into account.

    • Example #1:

      • baseUrl: https://server/path
      • Provided server URL in NMARegistration/serverUrl(_:): https://other.server
      • Resulting Server URL: https://other.server/path///
    • Example #2:

      • baseUrl: https://server:443/path
      • Provided server URL in NMARegistration/serverUrl(_:): https://other.server/path
      • Resulting Server URL: https://other.server/path
    • Example #3:

      • baseUrl: https://server/path
      • Provided server URL in NMARegistration/serverUrl(_:): http://other.server:80/otherpath
      • Resulting Server URL: http://other.server:80/path

    Declaration

    Swift

    @discardableResult
    func serverUrl(_ serverUrl: URL) -> NMARegistration

    Parameters

    serverUrl

    the URL of the server where the registration should be made.

    Return Value

    the NMARegistration builder.

  • Specifies the authorization provider that must be used to register the authenticator.

    Declaration

    Swift

    @discardableResult
    func authorizationProvider(_ authorizationProvider: NMAAuthorizationProvider) -> NMARegistration

    Parameters

    authorizationProvider

    Return Value

    the NMARegistration builder.

  • Specifies the device information to be used. The NMADeviceInformation is required only if you require support for encrypted out-of-band payloads or push notifications. If a NMADeviceInformation was already provided in an existing registration, the provided value will be ignored.

    Declaration

    Swift

    @discardableResult
    func deviceInformation(_ deviceInformation: NMADeviceInformation) -> NMARegistration

    Parameters

    deviceInformation

    the device information.

    Return Value

    the NMARegistration builder.

  • Specifies whether the OS device passcode can be used as fallback during biometric authentication. If not specified, the device passcode cannot be used as fallback.

    Declaration

    Swift

    @discardableResult
    func allowDevicePasscodeAsFallback(_ allowDevicePasscodeAsFallback: Bool) -> NMARegistration

    Parameters

    allowDevicePasscodeAsFallback

    indicates whether the device passcode can be used as fallback.

    Return Value

    the NMARegistration builder.

  • Specifies whether the authenticator must be invalidated if the user adds new biometric credentials in the OS settings. If the authenticator has been invalidated, and you try to authenticate with it, an error with code FidoErrorCode.keyDisappearedPermanently will be returned by the authentication operation.

    This setting only applies to faceRecognition (NMAAuthenticatorAaid.faceRecognition) and fingerprint (NMAAuthenticatorAaid.fingerprint) authenticators. By setting this parameter to true, you increase the security but there is a loss of convenience: adding a new OS biometric credential does not imply necessarily that there is a security risk, but if the end-user does it, a new registration will be required, because an invalidated authenticator cannot be recovered. If not specified, the authenticator will be invalidated when the user adds a new biometric credential in the OS settings.

    Declaration

    Swift

    @discardableResult
    func invalidateOnNewOsBiometrics(_ invalidateOnNewOsBiometrics: Bool) -> NMARegistration

    Parameters

    invalidateOnNewOsBiometrics

    indicates whether an addition of biometric credentials in the OS should invalidate this authenticator (if the authenticator is Face ID or Touch ID)

    Return Value

    the NMARegistration builder.

  • Specifies the object that will take care of the selection of the authenticator to be used.

    Important

    Providing the authenticator selector is required.

    Declaration

    Swift

    @discardableResult
    func authenticatorSelector(_ authenticatorSelector: NMAAuthenticatorSelector) -> NMARegistration

    Parameters

    authenticatorSelector

    Return Value

    the NMARegistration builder.

  • Specifies the object that will take care of the biometric user verification. It must be provided only if a biometric authenticator must be registered.

    Important

    Providing at least one of the NMABiometricUserVerifier, NMADevicePasscodeUserVerifier or NMAPinEnroller is required.

    Declaration

    Swift

    @discardableResult
    func biometricUserVerifier(_ biometricUserVerifier: NMABiometricUserVerifier) -> NMARegistration

    Parameters

    biometricUserVerifier

    Return Value

    the NMARegistration builder.

  • Specifies the object that will take care of the device passcode user verification.

    Important

    Providing at least one of the NMABiometricUserVerifier, NMADevicePasscodeUserVerifier or NMAPinEnroller is required.

    Declaration

    Swift

    @discardableResult
    func devicePasscodeUserVerifier(_ devicePasscodeUserVerifier: NMADevicePasscodeUserVerifier) -> NMARegistration

    Parameters

    devicePasscodeUserVerifier

    Return Value

    the NMARegistration builder.

  • Specifies the object that will take care of enrolling the PIN of the authenticator. It must be provided only if a PIN authenticator must be registered.

    Important

    Providing at least one of the NMABiometricUserVerifier, NMADevicePasscodeUserVerifier or NMAPinEnroller is required.

    Declaration

    Swift

    @discardableResult
    func pinEnroller(_ pinEnroller: NMAPinEnroller) -> NMARegistration

    Parameters

    pinEnroller

    Return Value

    the NMARegistration builder.

  • Specifies the block to execute if the registration was successful.

    Important

    Providing the onSuccess block is required.

    Declaration

    Swift

    @discardableResult
    func onSuccess(_ onSuccess: @escaping () -> ()) -> NMARegistration

    Parameters

    onSuccess

    the block to execute on successful registration.

    Return Value

    the NMARegistration builder.

  • Specifies the block to execute if the registration failed.

    Important

    Providing the onError block is required.

    Declaration

    Swift

    @discardableResult
    func onError(_ onError: @escaping (NMAOperationError) -> ()) -> NMARegistration

    Parameters

    onError

    the block to execute on failed registration, receives an NMAOperationError.

    Return Value

    the NMARegistration builder.