Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated May 3, 2024

Enable sign-in with web UI

Prerequisites

When configuring social sign-in, 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 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 <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 );