Get Started
1
Create a new Flutter project
Create a new Flutter project for this quickstart.In your terminal:
- Navigate to your workspace directory
- Run:
flutter create auth0_flutter_sample - Navigate into the project:
cd auth0_flutter_sample - Open in your IDE:
- VS Code:
code . - Android Studio:
open -a "Android Studio" .
- VS Code:
2
Install the Auth0 Flutter SDK
Add the Auth0 Flutter SDK to your project using the Flutter CLI.This will add
auth0_flutter to your pubspec.yaml dependencies:pubspec.yaml
3
Setup your Auth0 App
Next up, you need to create a new app on your Auth0 tenant and configure the callback URLs.Allowed Logout URLs:Add the same URLs from the callback configuration above to the Allowed Logout URLs field.Allowed Web Origins (Web Only):If targeting the web platform, add your application URL:
- Head to the Auth0 Dashboard
- Click on Applications > Applications > Create Application
- In the popup, enter a name for your app, select
Nativeas the app type (orSingle Page Applicationfor web-only) and click Create - Switch to the Settings tab on the Application Details page
- Note down the Domain and Client ID values - you’ll need these later
- Android
- iOS
- macOS
- Web
Allowed Callback URLs are a critical security measure to ensure users are safely returned to your application after authentication. Without a matching URL, the login process will fail.Allowed Logout URLs are essential for providing a seamless user experience upon signing out. Without a matching URL, users will not be redirected back to your application after logout.For example, if your Auth0 domain is
example.us.auth0.com and your Android package name is com.example.myapp, your Android callback URL would be: https://example.us.auth0.com/android/com.example.myapp/callback4
Configure Your Application
Platform-specific configuration is required to enable the authentication flow. Follow the instructions for each platform you’re targeting.
- Android
- iOS
- macOS
- Web
Open the Replace
android/app/build.gradle file and add the following manifest placeholders inside android > defaultConfig:android/app/build.gradle
{yourDomain} with your Auth0 domain (e.g., example.us.auth0.com).https schemeTo use https scheme for your callback url, set up Android app links for your application.For Biometric Authentication (Optional):If you plan to use biometric authentication, update your MainActivity.kt to extend FlutterFragmentActivity:android/app/src/main/kotlin/.../MainActivity.kt
5
Implement Login and Logout
Universal Login is the easiest way to set up authentication in your application. We recommend using it for the best experience, best security, and the fullest array of features.Implement Login:Implement Logout:
- Mobile/macOS
- Web
Import the Auth0 Flutter SDK and create an
Auth0 instance:lib/auth_service.dart
- Mobile/macOS
- Web
lib/auth_service.dart
iOS/macOS: The Web: You must call
useHTTPS: true parameter enables Universal Links on iOS 17.4+ and macOS 14.4+ for enhanced security.Android: if you are using a custom scheme, pass this scheme to the login method so that the SDK can route to the login page and back again correctly:lib/auth_service.dart
onLoad() when your application starts. This handles the redirect callback from Auth0 and restores the user’s session if they’re already authenticated.6
Show User Profile Information
The user profile is automatically retrieved when the user logs in. The
Credentials object contains a user property with all the user profile information, populated by decoding the ID token.lib/profile_screen.dart
7
Run your app
Build and run your Flutter application.In your terminal:Expected flow:
- App launches with your login UI
- User taps Log In → Browser/Custom Tab opens with Auth0 Universal Login
- User completes authentication
- Browser redirects back to your app
- User is now authenticated and credentials are stored
CheckpointYou should now have a fully functional Auth0 login experience in your Flutter application. The app uses secure browser-based authentication and automatically stores credentials for session persistence.
Troubleshooting & Advanced Usage
Common Issues & Solutions
Common Issues & Solutions
Callback URL Mismatch
Symptom: Error “redirect_uri_mismatch” or authentication fails silently.Solutions:- Check Allowed Callback URLs in Auth0 Dashboard match your app configuration exactly
- Verify the scheme (
https://vshttp://) - Ensure the package name (Android) or bundle identifier (iOS/macOS) is correct
- Check for trailing slashes
Android: Chrome Custom Tab Doesn’t Open
Symptom: Nothing happens when callinglogin().Fix:- Verify
manifestPlaceholdersare correctly set inbuild.gradle - Ensure internet permission is in
AndroidManifest.xml: - Check that Chrome or another browser is installed on the device
iOS: “Open in App” Alert
Symptom: Alert box appears asking to open in your app.Fix: This is expected behavior withASWebAuthenticationSession. To remove it:- Use Universal Links (requires iOS 17.4+ and paid Apple Developer account)
- Or set
useEphemeralSession: true(disables SSO):
Web: User Logged Out on Page Refresh
Symptom: User appears logged out after refreshing the page.Fix:- Ensure
onLoad()is called during app initialization - Try using
localStoragefor cache location: - Ensure your domain is added to Allowed Web Origins in Auth0 Dashboard
Web: “Must run on a secure origin” Error
Symptom: Error about secure origin in browser console.Fix: The Auth0 SPA SDK requires a secure context. Uselocalhost (which is treated as secure) or deploy to an HTTPS domain.Authentication cancelled by user
Handle gracefully in your error handling:Handling Credentials
Handling Credentials
The Auth0 Flutter SDK includes a built-in Credentials Manager that securely stores user credentials. On mobile platforms, credentials are encrypted and stored in the platform’s secure storage (Keychain on iOS/macOS, encrypted SharedPreferences on Android).
Check for Stored Credentials
Before prompting the user to log in, check if valid credentials already exist:lib/auth_service.dart
Retrieve Stored Credentials
Retrieve credentials to access tokens or user information. The Credentials Manager automatically refreshes expired tokens when possible:lib/auth_service.dart
Error Handling
Error Handling
Advanced Flutter Integration
Advanced Flutter Integration
Enhanced Credential Security with Biometrics
Implement biometric authentication for credential access on mobile:lib/secure_auth_service.dart
Android: Requires
MainActivity to extend FlutterFragmentActivity as configured in Step 4.iOS/macOS: Requires adding NSFaceIDUsageDescription to your Info.plist.Custom Scopes and Audience
Request specific scopes and audience for your API:lib/auth_service.dart
Organizations (B2B/Enterprise)
Authenticate users within a specific organization:lib/auth_service.dart
Production Deployment
Production Deployment
App Store Preparation
- Configure Universal Links (iOS) and App Links (Android) for seamless authentication
- Test on multiple device sizes and OS versions
- Implement proper error handling for network failures
- Add ProGuard rules for Android if using code obfuscation
- Follow platform-specific App Store/Play Store policies
Security Considerations
- Use the built-in Credentials Manager for production credential storage
- Enable biometric authentication for sensitive operations
- Consider certificate pinning for additional API security
- Implement proper token refresh handling
- Use
useHTTPS: truefor Universal Links on supported platforms