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
export const auth = defineAuth({ loginWith: { email: true, externalProviders: { callbackUrls: ["myapp://callback/"], logoutUrls: ["myapp://signout/"], }, },});
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:
<application ...> ... <activity android:name="com.amplifyframework.auth.cognito.activities.HostedUIRedirectActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="myapp" /> </intent-filter> </activity> ...</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:
Amplify.Auth.signInWithWebUI( this, result -> Log.i("AuthQuickStart", result.toString()), error -> Log.e("AuthQuickStart", error.toString()));
Amplify.Auth.signInWithWebUI( this, { Log.i("AuthQuickStart", "Signin OK = $it") }, { Log.e("AuthQuickStart", "Signin failed", it) })
try { val result = Amplify.Auth.signInWithWebUI(this) Log.i("AuthQuickStart", "Signin OK: $result")} catch (error: AuthException) { Log.e("AuthQuickStart", "Signin failed", error)}
RxAmplify.Auth.signInWithWebUI(this) .subscribe( result -> Log.i("AuthQuickStart", result.toString()), error -> Log.e("AuthQuickStart", error.toString()) );