Skip to content

Callbacks⚓︎

The app will receive callbacks from the Mobile SDK for providing feedback to the user or requesting their input.

Android⚓︎

To listen for callbacks from the mobile SDK, implement the NextAuthObserver and register your observer with the mobile SDK. Do not forget to unregister when done.

... implements NextAuthObserver {

    //register observer
    NextAuth.getNextAuth().addObserver(this);

    //unregister observer
    NextAuth.getNextAuth().removeObserver(this);

    @Override
    public void onCallback(Callback callback) {
        //TODO implement logic
    }

}

Optionally you can also extend the AbstractCallbackHandler and directly listen for specific callbacks

... extends AbstractCallbackHandler implements NextAuthObserver {
    //register observer
    NextAuth.getNextAuth().addObserver(this);

    //unregister observer
    NextAuth.getNextAuth().removeObserver(this);

    @Override
    public void onCallback(Callback callback) {
        callback.trigger(this)
    }

    @Override
    public void onSecondFactor(SecondFactor callback) {
         //TODO implement logic
    }

    @Override
    public void onSessionStop(SessionStop callback) {
         //TODO implement logic
    }

    ...
}
Method When Expected Response
SessionReadyForUserInteraction A session enters the state WAIT_FOR_USER_CONFIRMATION. A call for starting the user interaction for a given session.
SessionLogin The session enters the history status LOGGED_IN or LOGGED_IN_ONE_SHOT.
SessionStop A session stops.
ConfirmLogin The started session is part of a login flow, if there are multiple accounts to chose from or when a second factor is not needed (i.e., the user only has to confirm the login). A call to select the account to login with or a call to stop the session if the user does not want to continue.
ConfirmEnrol The started session is part of an enrol flow. A call to confirm the enrol at the given server or a call to stop the session if the user does not want to continue.
SecondFactor The user's second factor is required (e.g., login, enrol, enable/disable biometric). A call to input the pin and/or biometric or a call to cancel this input if the user does not want to continue.
UserErrorMessage An error occurs which should be displayed to the user.
AccountDeleted An account has been deleted.
TokenResult A token as a result of the getToken() call.
OTPAvailable An OTP can be generated for a given session.
RetrievedMessages The list of messages received from the Message Center triggered by a retrieveMessages() call.

iOS⚓︎

On iOS, the Mobile SDK has two mechanisms to notify the application when user interaction is required or when an entity has been updated. The former is implemented through the common delegate pattern1, while the latter broadcasts notifications through NSNotificationCenter2.

Delegate⚓︎

Whenever the Mobile SDK requires some interaction from the user, it will call the relevant method on its configured delegate. It is therefore important that include a class in your app which conforms to the NextAuthDelegate. You should also ensure that you assign an instance of this class to NextAuth.default.delegate. Given that the delegate methods will need to interact with the UI, one possible approach is to build a view controller which will always be present in the view hierarchy and have it conform to this protocol.

Method When Expected Response
willConfirmLoginFor The started session is part of a login flow, if there are multiple accounts to chose from or when a second factor is not needed (i.e., the user only has to confirm the login). A call to select the account to login with or a call to stop the session if the user does not want to continue.
willConfirmEnrolFor The started session is part of an enrol flow. A call to confirm the enrol at the given server or a call to stop the session if the user does not want to continue.
didStartSecondFactorWith The user's second factor is required (e.g., login, enrol, enable/disable biometric). A call to input the pin and/or biometric or a call to cancel this input if the user does not want to continue.
didUpdateSecondFactorWith The Mobile SDK has verified the entered second factor. The view presenting the second factor input should be updated with the given details.
didReceive The Mobile SDK returns the requested upstream token.
didReturn An error occurs which should be displayed to the user.
didThrow The Mobile SDK encounters a fatal exception.
canGenerateOTPFor An OTP can be generated for a given session.

Notifications⚓︎

The following notification will be broadcasted on the listed event. When posting the notification, the updated instance will be included and is therefore accessible through NSNotification.object.

Notification When
NotificationNames.accountUpdate An account has been updated (or deleted, before Mobile SDK v1.8.0).
NotificationNames.accountDelete An account has been deleted (available from Mobile SDK v1.8.0).
NotificationNames.sessionUpdate The status of a session has changed.