Skip to main content

Registering an Authenticator

This snippet demonstrates to register an authenticator instance for your custom mobile application. The snippet registers an instance of CloudQrScan, which is obtained by scanning an IBM Security Verify QR code, generated by the IBM Verify SDK for JavaScript. Note, once registered, the IBM Verify SDK for iOS cannot remove or delete an authenticator, and it is up to the JavaScript SDK to do so.

Prerequisites

  • Set up Xcode with the IBM Verify framework.
  • Scan a cloud QR code to obtain a CloudQrScan instance (see QR code scanning in Samples).

Steps

  1. Add a new Swift file to your project, and copy the following code snippet:
// Register an authenticator, where `result` is an instance of `CloudQrScan`.
AuthenticatorContext.shared.create(from: result)
{
    authenticator, error in

    guard let authenticator = authenticator as? CloudAuthenticator else
    {
        // Authorization code does not exist or is invalid (i.e. QR code expired, or already scanned).
        return
    }

    guard let authenticationMethod = authenticator.enrolledMethods.first as? TOTPAuthenticationMethod else
    {
        // Device already has a registered authenticator with the application scanned (can only have at most one registered authenticator per scanned application).
        return
    }

    // You can now access the secret, and other properties included in the registered `authenticationMethod`, which may be used to initiate a `TOTPGenerator`, etc.
    authenticationMethod
}
    

Next Steps

You have now successfully registered an authenticator with the server from a scanned CloudQrScan instance, by using the IBMVerifyKit framework.

Play around with other samples which demonstrate further functionality of the framework in the Samples section, or have a look at more quick, easy-to-implement code snippets in the Snippets section.