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
| class AuthenticatorActivity : AppCompatActivity() { | |
| companion object { | |
| private const val REQUEST_PERMISSIONS_FINGERPRINT = 90001 | |
| } | |
| private val model by viewModel<AuthenticatorViewModel>() | |
| private val analyticsService by inject<AnalyticsService>() | |
| // For permissions checks | |
| private var checkedPermissions = false |
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
| private fun handler(identityRequest: IdentityRequest, params: Map<String,String>?, callback: IdentityResponse) { | |
| when(identityRequest) { | |
| IdentityRequest.SUCCESS -> { | |
| Log.d(TAG, "handler: SUCCESS") | |
| this@ConfigureTOTPActivity.finish() | |
| } | |
| IdentityRequest.FAILURE -> { | |
| Log.d(TAG, "handler: FAILURE") | |
| alert(params!!.get("message")!!) { |
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 |
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
| WebAuthProvider.init(auth0Settings) | |
| .withAudience(audience) | |
| .start(this@AuthenticatorActivity, object : AuthCallback { | |
| override fun onSuccess(credentials: Credentials) { | |
| model.federateWithOIDC(credentials.accessToken!!, resources.getString(R.string.com_auth0_domain)) | |
| this@AuthenticatorActivity.finish() | |
| } | |
| override fun onFailure(dialog: Dialog) { | |
| Log.d(TAG, "Auth0 Error displayed in dialog") | |
| runOnUiThread { dialog.show() } |
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
| /** | |
| * Federate with OIDC | |
| */ | |
| override fun federateWithOIDC(token: String, issuer: String) { | |
| Log.d(TAG, "Federating with $issuer") | |
| thread(start = true) { | |
| with(service.identityManager.underlyingProvider) { | |
| clear() | |
| withLogins(mapOf(issuer to token)) | |
| refresh() |
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
| IdentityPool: | |
| # Always created | |
| Type: AWS::Cognito::IdentityPool | |
| Properties: | |
| IdentityPoolName: photos_identitypool_9551db82 | |
| CognitoIdentityProviders: | |
| - ClientId: !Ref UserPoolClient | |
| ProviderName: !Sub | |
| - cognito-idp.${region}.amazonaws.com/${client} |
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
| OpenIdLambdaIAMPolicy: | |
| # Sets policy for the role that executes the OpenId Lambda | |
| # Depends on OpenIdLambda for Arn | |
| # Marked as depending on MFALambda for easier to understand CFN sequencing | |
| Type: 'AWS::IAM::Policy' | |
| Properties: | |
| PolicyName: !Ref openIdLambdaIAMPolicy | |
| Roles: | |
| - !Ref openIdLambdaRoleName | |
| PolicyDocument: |
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
| // Configure the Auth0 requirements | |
| val auth0Settings = Auth0(this).apply { | |
| isOIDCConformant = true | |
| } | |
| val audience = String.format("https://%s/userinfo", resources.getString(R.string.com_auth0_domain)) | |
| loginFormAuth0LoginButton.onClick { | |
| WebAuthProvider.init(auth0Settings) | |
| .withAudience(audience) | |
| .start(this@AuthenticatorActivity, object : AuthCallback { | |
| override fun onSuccess(credentials: Credentials) { |
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
| // Check to see if Google is authenticated - if it is, then federate with Google | |
| val googleAccount = GoogleSignIn.getLastSignedInAccount(context) | |
| if (googleAccount != null) { | |
| Log.d(TAG, "Google Signed In Account found - account=${googleAccount.toJson()} ") | |
| thread(start = true) { | |
| try { | |
| val googleOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) | |
| .requestIdToken(context.getString(R.string.google_client)) | |
| .requestEmail() | |
| .build() |
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
| /** | |
| * Federate with Google authentication | |
| */ | |
| override fun federateWithGoogle(account: GoogleSignInAccount) { | |
| if (account.idToken != null) { | |
| Log.d(TAG, "Federating with Google") | |
| thread(start = true) { | |
| with(service.identityManager.underlyingProvider) { | |
| clear() | |
| withLogins(mapOf("accounts.google.com" to account.idToken)) |