Skip to content

Commit bb04afb

Browse files
haverchuckNoyesdnys1
authored
fix (amplify_auth_cognito): fixes swallowed usercancelled exception with hosted ui android, and updates auth exampl… (#1015)
* fixes swallowed error with hosted ui android, and updates auth example app * Update packages/amplify_auth_cognito/android/src/main/kotlin/com/amazonaws/amplify/amplify_auth_cognito/AuthCognito.kt Co-authored-by: Dillon Nys <[email protected]> Co-authored-by: Noyes <[email protected]> Co-authored-by: Dillon Nys <[email protected]>
1 parent d5a0dd1 commit bb04afb

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

packages/amplify_auth_cognito/android/src/main/kotlin/com/amazonaws/amplify/amplify_auth_cognito/AuthCognito.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.amazonaws.amplify.amplify_auth_cognito
1717

1818
import android.app.Activity
19+
import android.app.Activity.RESULT_CANCELED
1920
import android.content.Context
2021
import android.content.Intent
2122
import android.os.Handler
@@ -131,9 +132,14 @@ public class AuthCognito : FlutterPlugin, ActivityAware, MethodCallHandler, Plug
131132

132133
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean {
133134
var isHostedUIActivity = isRedirectActivityDeclared(context)
134-
if (!isHostedUIActivity && requestCode == AWSCognitoAuthPlugin.WEB_UI_SIGN_IN_ACTIVITY_CODE) {
135-
Amplify.Auth.handleWebUISignInResponse(data)
136-
return true
135+
if (requestCode == AWSCognitoAuthPlugin.WEB_UI_SIGN_IN_ACTIVITY_CODE) {
136+
/// The HostedUI activity in amplify-android handles success case
137+
/// We need a response handler if the HostedUI activity isn't used...
138+
/// ... or if the HostedUI activity is used, but the user cancels
139+
if (!isHostedUIActivity || resultCode == RESULT_CANCELED) {
140+
Amplify.Auth.handleWebUISignInResponse(data)
141+
return true
142+
}
137143
}
138144
return false
139145
}

packages/amplify_auth_cognito/example/android/app/src/main/AndroidManifest.xml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
In most cases you can leave this as-is, but you if you want to provide
66
additional functionality it is fine to subclass or reimplement
77
FlutterApplication and put your custom class here. -->
8+
9+
<queries>
10+
<intent>
11+
<action android:name="android.intent.action.VIEW" />
12+
<data android:scheme="https" />
13+
</intent>
14+
<intent>
15+
<action android:name=
16+
"android.support.customtabs.action.CustomTabsService" />
17+
</intent>
18+
</queries>
819
<application
920
android:name="io.flutter.app.FlutterApplication"
1021
android:label="amplify_auth_cognito_example"
@@ -38,13 +49,15 @@
3849
<category android:name="android.intent.category.LAUNCHER"/>
3950
</intent-filter>
4051
</activity>
41-
<activity android:name="com.amazonaws.mobileconnectors.cognitoauth.activities.CustomTabsRedirectActivity">
42-
<intent-filter>
43-
<action android:name="android.intent.action.VIEW" />
44-
<category android:name="android.intent.category.DEFAULT" />
45-
<category android:name="android.intent.category.BROWSABLE" />
46-
<data android:scheme="myapp" />
47-
</intent-filter>
52+
<activity
53+
android:name="com.amplifyframework.auth.cognito.activities.HostedUIRedirectActivity"
54+
android:exported="true">
55+
<intent-filter>
56+
<action android:name="android.intent.action.VIEW" />
57+
<category android:name="android.intent.category.DEFAULT" />
58+
<category android:name="android.intent.category.BROWSABLE" />
59+
<data android:scheme="myapp" />
60+
</intent-filter>
4861
</activity>
4962
<!-- Don't delete the meta-data below.
5063
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->

0 commit comments

Comments
 (0)