AuthCallback
AuthCallback is used to take care of the core the authentication flow between the Nuclei SDK and the partner application
Implement AuthCallback
interface in the application class.
Please refer to the below code:
class Application extends MultiDexApplication implements AuthCallback {
private NucleiSDK nucleiSDK;
@Override
public void onCreate() {
super.onCreate();
initNuclei();
}
public NucleiSDK getNucleiSDK() {
return nucleiSDK;
}
private void initNuclei() {
nucleiSDK = NucleiSDK.bind(this)
...
.init();
nucleiSDK.setAuthCallback(this);
}
/**
* This method is called when authentication fails for the user
*
* @param authError is of type com.nuclei.provider_sdk.provider.enums.AuthError
*/
@Override
public void onAuthenticationError(@AuthError int authError) {
switch (authError) {
case AuthError.INVALID_TOKEN:
Toast.makeText(getApplicationContext(), "Token sent to validate token is invalid.", Toast.LENGTH_LONG).show();
break;
case AuthError.NETWORK_ISSUE:
Toast.makeText(getApplicationContext(), "Something went wrong. Please contact us.", Toast.LENGTH_LONG).show();
break;
case AuthError.ALREADY_LOGGED_IN:
Toast.makeText(getApplicationContext(), "User is already logged in.", Toast.LENGTH_LONG).show();
break;
}
}
/**
* This method is called when authentication is successful
*/
@Override
public void onAuthenticationSuccess() {
//Handle successful authentication if required.
// For example start nuclei flow. This will open the Nuclei grid screen.
getNucleiSDK().startNucleiFlow();
}
/**
* This method is called when SDK is logged out.
*/
@Override
public void onSdkLoggedOut() {
// Handle Nuclei SDK logout event if needed
}
/**
* This method is called when isParentAppLoggedIn() returns true
* and user is not logged in into the SDK
*/
@Override
public void onSdkLoginRequest() {
/**
* Bank needs to implement the generate token API on their server
* Use AndroidUtilities.getDeviceId(); to get the device Id while calling generate token api
* Call this generate token api to get a token
* Use the response from above API to call the below validateToken method
* NucleiSDK.validateToken(tokenResponse.tempToken, mobileNumber, 91);
*/
}
/**
* This method is called when isParentAppLoggedIn() returns false
* Save the deepLink in local storage like shared preference,
* on completion of login into the bank, use method nucleiSdk.openDeepLink(deepLink) to open the deepLink
* and clear stored deeplink from local storage
*/
@Override
public void onUserLoginRequest(String deepLink) {
// Save this deepLink
// Start the Bank Login Flow
// Once login complete open this deepLink again
// Clear stored deeplink
}
}