Created
September 25, 2018 16:50
-
-
Save adrianhall/3970217ceb40be2db098e5c131cc179e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun initiateTOTPSignup(handler: IdentityHandler) { | |
userPool.currentUser.associateSoftwareTokenInBackground(null, object : RegisterMfaHandler { | |
override fun onSuccess(sessionToken: String?) { | |
val mfaSettings = listOf( | |
CognitoMfaSettings(CognitoMfaSettings.SMS_MFA).apply { | |
isEnabled = true | |
isPreferred = false | |
}, | |
CognitoMfaSettings(CognitoMfaSettings.TOTP_MFA).apply { | |
isEnabled = true | |
isPreferred = true | |
} | |
) | |
userPool.currentUser.setUserMfaSettingsInBackground(mfaSettings, object : GenericHandler { | |
override fun onSuccess() = runOnUiThread { handler(IdentityRequest.SUCCESS, null) { /* Do Nothing */ } } | |
override fun onFailure(exception: Exception?) = handleFailure(handler, exception?.message) | |
}) | |
} | |
override fun onFailure(exception: java.lang.Exception?) = handleFailure(handler, exception?.message) | |
override fun onVerify(continuation: VerifyMfaContinuation?) { | |
runOnUiThread { | |
handler(IdentityRequest.NEED_MULTIFACTORCODE, continuation?.parameters) { response -> run { | |
with (continuation!!) { | |
thread(start = true) { | |
setVerificationResponse(response?.get("mfaCode"), "Android App") | |
continueTask() | |
} | |
} | |
}} | |
} | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment