Page updated Nov 8, 2023

Enable sign-in with web UI

Prerequisites

When configuring social sign-in through the Amplify CLI, it's important to exercise caution when designating attributes as "required." Different social identity providers have varied scopes in terms of the information they respond back to Cognito with. User pool attributes that are initially set up as "required" cannot be changed later, and may require you to migrate the users or create a new user pool.

Configure Auth Category

This library's Cognito plugin currently supports the Authorization Code Grant OAuth Flow.

In terminal, navigate to your project, run amplify add auth (or if you've already added it, run amplify update auth), and choose the following options:

1? Do you want to use the default authentication and security configuration?
2 `Default configuration with Social Provider (Federation)`
3? How do you want users to be able to sign in?
4 `Username`
5? Do you want to configure advanced settings?
6 `No, I am done.`
7? What domain name prefix you want us to create for you?
8 `(default)`
9? Enter your redirect signin URI:
10 `myapp://callback/`
11? Do you want to add another redirect signin URI
12 `No`
13? Enter your redirect signout URI:
14 `myapp://signout/`
15? Do you want to add another redirect signout URI
16 `No`
17? Select the social providers you want to configure for your user pool:
18 `<hit enter>`

Once finished, run amplify push to publish your changes.

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 <activity
4 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 );