AuthTab
is part of the Android Browser library that enables apps to authenticate users via a web service, presenting a secure and user-friendly popup browser for login flows.
Setup
- Add the necessary dependencies to your app’s build.gradle.kts file:
- Define your custom URL scheme in your AndroidManifest.xml:
Full code example
Automatic fallback mechanism
Theandroidx.browser.auth.AuthTabIntent
library automatically handles the fallback to CustomTabs if AuthTab is not supported on the device. You don’t need to implement any custom logic for this fallback – the library takes care of it.
However, there are differences in how the redirect URL is handled:
- When using AuthTab directly, the result comes back through the
handleAuthResult
callback. - When the library falls back to CustomTabs, the result comes back through your activity’s
onNewIntent
method.
Usage example
To use the authentication in your app:Notes
- Replace
CONST_BASE_URL
with your backend authentication URL.
Troubleshooting
- If the callback URL doesn’t trigger your app, ensure the URL scheme in your manifest matches exactly with what you’re using in the code.
- Make sure your Android manifest has the correct intent filter for handling the callback URL.
- If authentication fails, check the logs for detailed error information.