Enable sign-in with web UI
Prerequisites
- An app set up according to the getting started walkthrough
Configure Auth Category
In your auth/resource.ts
file, update the
1export const auth = defineAuth({2 loginWith: {3 email: true,4 externalProviders: {5 callbackUrls: ["myapp://callback/"],6 logoutUrls: ["myapp://signout/"],7 },8 },9});
Update AndroidManifest.xml
Add the following activity and queries tag to your app's AndroidManifest.xml
file, replacing myapp
with
your redirect URI prefix if necessary:
1<application ...>2 ...3 <activity4 android:name="com.amplifyframework.auth.cognito.activities.HostedUIRedirectActivity"5 android:exported="true">6 <intent-filter>7 <action android:name="android.intent.action.VIEW" />8 <category android:name="android.intent.category.DEFAULT" />9 <category android:name="android.intent.category.BROWSABLE" />10 <data android:scheme="myapp" />11 </intent-filter>12 </activity>13 ...14</application>
Launch Web UI Sign In
Sweet! You're now ready to launch sign in with web UI. For now, just add this method to the onCreate
method of MainActivity:
1Amplify.Auth.signInWithWebUI(2 this,3 result -> Log.i("AuthQuickStart", result.toString()),4 error -> Log.e("AuthQuickStart", error.toString())5);
1Amplify.Auth.signInWithWebUI(2 this,3 { Log.i("AuthQuickStart", "Signin OK = $it") },4 { Log.e("AuthQuickStart", "Signin failed", it) }5)
1try {2 val result = Amplify.Auth.signInWithWebUI(this)3 Log.i("AuthQuickStart", "Signin OK: $result")4} catch (error: AuthException) {5 Log.e("AuthQuickStart", "Signin failed", error)6}
1RxAmplify.Auth.signInWithWebUI(this)2 .subscribe(3 result -> Log.i("AuthQuickStart", result.toString()),4 error -> Log.e("AuthQuickStart", error.toString())5 );