use of com.amazonaws.services.cognitoidentityprovider.model.VerifySoftwareTokenResult in project aws-sdk-android by aws-amplify.
the class CognitoUser method verifySoftwareToken.
/**
* Verify the Time-based One-time Password based MFA tpo complete registration, in current thread.
* @param sessionToken Optional: If a session token has to be used to register the MFA.
* @param totpCode Required: The TOTP code.
* @param friendlyName Required: Friendly name to be associated with this MFA.
* @param callback Required: Callback handler {@link VerifyMfaContinuation}.
*/
public void verifySoftwareToken(final String sessionToken, final String totpCode, final String friendlyName, final RegisterMfaHandler callback) {
if (callback == null) {
throw new CognitoParameterInvalidException("callback is null");
}
final CognitoUser user = this;
boolean useSessionToken;
try {
final CognitoUserSession cognitoTokens = user.getCachedSession();
VerifySoftwareTokenResult result;
if (!StringUtils.isBlank(sessionToken)) {
result = verifyTotpAssociationWithSession(sessionToken, totpCode, friendlyName);
useSessionToken = true;
} else {
result = verifyTotpAssociationWithTokens(cognitoTokens, totpCode, friendlyName);
useSessionToken = false;
}
final String newSessionToken = result.getSession();
if (VerifySoftwareTokenResponseType.ERROR.equals(result.getStatus())) {
throw new CognitoInternalErrorException("verification failed");
}
if (useSessionToken) {
callback.onSuccess(newSessionToken);
} else {
callback.onSuccess(null);
}
} catch (Exception e) {
callback.onFailure(e);
}
}
use of com.amazonaws.services.cognitoidentityprovider.model.VerifySoftwareTokenResult in project aws-sdk-android by aws-amplify.
the class CognitoUser method verifySoftwareTokenInBackground.
/**
* Verify the Time-based One-time Password based MFA tpo complete registration.
* @param sessionToken Optional: If a session token has to be used to register the MFA.
* @param totpCode Required: The TOTP code.
* @param friendlyName Required: Friendly name to be associated with this MFA.
* @param callback Required: Callback handler {@link VerifyMfaContinuation}.
*/
public void verifySoftwareTokenInBackground(final String sessionToken, final String totpCode, final String friendlyName, final RegisterMfaHandler callback) {
if (callback == null) {
throw new CognitoParameterInvalidException("callback is null");
}
final CognitoUser user = this;
new Thread(new Runnable() {
@Override
public void run() {
final Handler handler = new Handler(context.getMainLooper());
Runnable returnCallback;
try {
final CognitoUserSession cognitoTokens = user.getCachedSession();
VerifySoftwareTokenResult result;
boolean useSessionToken;
if (!StringUtils.isBlank(sessionToken)) {
result = verifyTotpAssociationWithSession(sessionToken, totpCode, friendlyName);
useSessionToken = true;
} else {
result = verifyTotpAssociationWithTokens(cognitoTokens, totpCode, friendlyName);
useSessionToken = false;
}
final String newSessionToken = result.getSession();
if (VerifySoftwareTokenResponseType.ERROR.equals(result.getStatus())) {
throw new CognitoInternalErrorException("verification failed");
}
if (useSessionToken) {
returnCallback = new Runnable() {
@Override
public void run() {
callback.onSuccess(newSessionToken);
}
};
} else {
returnCallback = new Runnable() {
@Override
public void run() {
callback.onSuccess(null);
}
};
}
} catch (final Exception e) {
returnCallback = new Runnable() {
@Override
public void run() {
callback.onFailure(e);
}
};
}
handler.post(returnCallback);
}
}).start();
}
Aggregations