Skip to content

Instantly share code, notes, and snippets.

@adrianhall
Created September 25, 2018 16:50
Show Gist options
  • Save adrianhall/3970217ceb40be2db098e5c131cc179e to your computer and use it in GitHub Desktop.
Save adrianhall/3970217ceb40be2db098e5c131cc179e to your computer and use it in GitHub Desktop.
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