Skip to content

Secure Communication⚓︎

It is possible to set up secure communication with a backend data service. The communication will pass through the nextAuth secure channel and hence be authenticated as coming from either the mobile device or nextAuth server. For this to work, one needs to set up a data service that implements the nextAuth data service interface. Please contact us for more details.

One can request data from the data service by calling the getData() method for a given payload. This call results in either the data from the data service or an error.

byte[] payLoad = new byte[];
RequestCompletionHandler requestCompletionHandler = new RequestCompletionHandler();
DataServiceManager.CancellationInterface cancellationInterface;
try {
    cancellationInterface = NextAuth.getNextAuth().getDataServiceManager()
                .getData(payLoad, requestCompletionHandler);
} catch (Exception e) {
    // TODO: Handle exception
}

// class to handle the response from the data service
class RequestCompletionHandler implements DataServiceManager.CompletionHandler {
    @Override
    public void onData(byte[] data) {
        // TODO: Handle data coming back data service
    }

    @Override
    public void onError(NextAuthException nextAuthExceptionException) {
        // TODO: Handle errors
    }
}

// call this method to cancel the ongoing request
cancellationInterface.cancel()
do {
    let result = try await NextAuth.default.getData(payload)
} catch {
    // TODO: Handle error
}

Headless Accounts⚓︎

If the app has no accounts registered, the app will generate a headless account when calling the getData() method. The headless account just identifies the mobile device and has no second factor of the user attached to it.

Warning

Headless upgrade requires the second factor server to support v1_2 and the configuration of the NextAuth Mobile SDK to explicitly allow this version in the allowedProtocolVersions.secondFactorServer.

One can upgrade a headless account by calling the upgrade() method on the account, which will start a flow of type HEADLESS_UPGRADE.

// select first and only account
List<Account> accounts = NextAuth.getNextAuth().getAccountManager().getAccounts();
Account account = accounts.get(0);

// start the headless upgrade flow
try {
    NextAuth.getNextAuth().getAccountManager().upgrade(account)
} catch (NextAuthException e){
    // TODO: Handle exception
}
// select first and only account
guard let account = NextAuth.default.accounts.first else {
    return
}

do {
    try NextAuth.default.upgradeAccount(account)
} catch {
    // TODO: Handle error
}

The expected sequence of FlowUpdate callbacks to be handled is as follows:

  1. WAIT_FOR_INPUT as its State. The CurrentUserInteraction.Type is SET_SECOND_FACTOR -- asking the user to set their second factor. See here for more information.
  2. PROCESSING as its State -- the nextAuth Mobile SDK is setting up the user's second factor.
  3. DONE as its State -- the flow successfully finished, the account is upgraded.