Get Started
Create a new .NET project
Create a new .NET MAUI or .NET Android/iOS project for this quickstart.
- .NET MAUI
- .NET Android
- .NET iOS
In Visual Studio 2022 or later:
- File → New → Project
- Select .NET MAUI App template
- Configure your project:
- Project name:
Auth0MauiSample - Location: Choose your preferred location
- Framework: .NET 8.0 or later
- Project name:
- Click Create
This quickstart focuses on .NET Android and iOS, which are the next generation of Xamarin.Android and Xamarin.iOS. If you’re still using Xamarin, you can follow this guide as the integration is identical and the SDKs are compatible.
Install Auth0 SDK
Add the Auth0 OIDC Client SDK to your project.
- Package Manager Console
- Visual Studio for Mac
- .NET CLI
Open the Package Manager Console (View → Other Windows → Package Manager Console) and install the appropriate package:For .NET Android:For .NET iOS:For .NET MAUI (both platforms):
Package Manager Console
Package Manager Console
Package Manager Console
Setup your Auth0 App
Create a new application in your Auth0 tenant and configure it for mobile.Replace:Allowed Logout URLs:Use the same URLs as your callback URLs.
- Head to the Auth0 Dashboard
- Click on Applications → Applications → Create Application
- Enter a name for your app, select Native as the app type, and click Create
- Switch to the Settings tab on the Application Details page
- Note your Domain and Client ID - you’ll need these in the next step
- Android
- iOS
YOUR_ANDROID_PACKAGE_NAMEwith your app’s package name (e.g.,com.mycompany.myapp){yourDomain}with your Auth0 domain (e.g.,dev-abc123.us.auth0.com)
com.mycompany.myapp://dev-abc123.us.auth0.com/android/com.mycompany.myapp/callbackAllowed Callback URLs are essential for security - they ensure users are safely returned to your application after authentication. Without a matching URL, the login process will fail.Allowed Logout URLs provide a seamless experience when users sign out, redirecting them back to your app instead of leaving them on an Auth0 page.
Initialize the Auth0 Client
Create an
Auth0Client instance to communicate with Auth0.- Android - MainActivity
- iOS - AppDelegate
MainActivity.cs
The
IntentFilter registers your app to handle the callback URL. The LaunchMode.SingleTask ensures Android doesn’t create a new activity instance when the callback is invoked.Implement Login and Logout
Add methods to handle user authentication.Implement Login:Implement Logout:
Authentication.cs
Authentication.cs
The
LoginAsync() method launches the system browser (or Chrome Custom Tabs on Android) to display Auth0’s Universal Login page. After authentication, the user is redirected back to your app via the callback URL.Run your app
Build and run your application.Expected flow:
- Visual Studio (Windows)
- Visual Studio for Mac
- .NET CLI
For Android:
- Select an Android emulator or connected device from the device dropdown
- Press F5 or click the Run button
- The app will build, deploy, and launch
- Connect to your Mac build host
- Select an iOS simulator or device from the device dropdown
- Press F5 or click the Run button
- App launches with Login button
- Tap Log In → Browser/Chrome Custom Tab opens → Complete authentication
- Redirects back to your app automatically
- User is authenticated successfully
CheckpointYou now have a fully functional Auth0 login experience in your .NET Android or iOS application. The app uses the system browser for secure authentication and automatically handles the callback flow.
Access User Information
After successful authentication, you can access user information from the login result.Authentication Result
TheLoginAsync() method returns a LoginResult object containing:
UserInfo.cs
Iterate Through All Claims
To see all available user information:UserClaims.cs
The exact claims returned depend on the scopes requested. For more information, see Using Scopes in the Auth0 OIDC Client documentation.
Request Custom Scopes
To request additional user information, specify scopes when creating the Auth0Client:CustomScopes.cs
Troubleshooting & Advanced
Common Issues & Solutions
Common Issues & Solutions
Browser doesn’t redirect back to app
Solutions:- Verify callback URLs in Auth0 Dashboard exactly match your app’s package name/bundle identifier
- Ensure callback URLs are in lowercase
- Check that
DataScheme,DataHost, andDataPathPrefix(Android) or URL scheme (iOS) match your configuration - Clean and rebuild your project
Authentication fails with “Invalid Callback URL” error
Fix:- Double-check that your callback URL in the Auth0 Dashboard matches the format:
- Android:
packagename://yourdomain/android/packagename/callback - iOS:
bundleidentifier://yourdomain/ios/bundleidentifier/callback
- Android:
- Ensure the URL is in lowercase
- Verify the Domain in your code matches the Domain in the Auth0 Dashboard
LoginAsync() hangs or never completes
Solutions:- Ensure the Intent filter (Android) or URL scheme (iOS) is properly configured
- Check that
OnNewIntent()(Android) orOpenUrl()(iOS) calls theActivityMediator - Verify your app can open the system browser
- Check network connectivity
Error: “Default App must use Token Endpoint Authentication Method ‘None’”
Fix:- Go to your Auth0 Application Settings in the Dashboard
- Scroll to Application Properties
- Set Application Type to Native
- Set Token Endpoint Authentication Method to None
- Click Save Changes
iOS: Browser doesn’t open
Solutions:- Verify
Info.plistcontains the correct URL scheme configuration - Check that
OpenUrl()is implemented inAppDelegate - Ensure iOS deployment target is compatible with your Auth0 SDK version
Production Considerations
Production Considerations
Security Best Practices
- Secure Token Storage: Use platform-specific secure storage (Android Keystore, iOS Keychain) to store tokens
- Token Refresh: Implement refresh token handling to maintain user sessions
- Certificate Pinning: Consider certificate pinning for additional API security
- ProGuard/Code Obfuscation: Add appropriate rules if using code obfuscation on Android
App Store Requirements
- Privacy Policy: Ensure your app has a privacy policy that describes Auth0 usage
- User Data Handling: Follow platform guidelines for handling user authentication data
- Deep Linking: Test callback URL handling thoroughly across different scenarios
- Network Requirements: Handle offline scenarios gracefully
Performance Optimization
- Cache Auth0Client: Create a single instance and reuse it throughout your app
- Lazy Loading: Initialize Auth0Client only when needed
- Background Refresh: Implement background token refresh for long-running sessions
Advanced Configuration
Advanced Configuration
Custom Scopes and Audience
Request specific scopes and set an audience for your API:AdvancedAuth.cs
Additional Parameters
Pass additional parameters to the authorization request:ExtraParams.cs
Refresh Tokens
Use refresh tokens to get new access tokens without user interaction:RefreshToken.cs
To receive a refresh token, include the
offline_access scope in your authentication request.Platform-Specific Browser Configuration
Android - Use Chrome Custom Tabs with custom colors:AndroidBrowser.cs
iOSBrowser.cs
Next Steps
Configure Identity Providers
Add social login providers like Google, Facebook, and GitHub
Enable Multi-Factor Authentication
Add an extra layer of security with MFA
Attack Protection
Learn how to protect against brute force and bot attacks
Customize Login Experience
Customize the Universal Login page to match your brand