Use AI to integrate Auth0
Use AI to integrate Auth0
Get Started
Use this quickstart to configure your Kotlin Multiplatform app for end users to log in and out through Auth0 Universal Login, persist tokens securely, and display user profiles — all from shared Kotlin code running on both Android and iOS.Create a new Kotlin Multiplatform project
com.example.app as the application ID / bundle identifier. Replace this placeholder with your own since it becomes part of your Auth0 callback URLs.Add the Auth0 SDK via Gradle
commonMain source set of your shared module. The library is published to Maven Central, so no extra repository configuration is required.Update composeApp/build.gradle.kts:Setup your Auth0 App
- Navigate to the Auth0 Dashboard.
- Select Applications > Applications > Create Application.
- In the popup, enter a name for your app, select Native as the app type, and choose Create.
- Switch to the Settings tab on the Application Details page and copy the Domain and Client ID. You need to add them to your code in a later step.
{yourDomain} with your actual Auth0 domain (e.g., dev-abc123.us.auth0.com) and com.example.app with your application ID / bundle identifier.SCHEME://YOUR_DOMAIN/android/APPLICATION_ID/callback for Android and SCHEME://YOUR_DOMAIN/ios/BUNDLE_ID/callback for iOS. By default the scheme equals your application ID / bundle identifier.applicationId (Android) and bundle identifier (iOS) exactly. If authentication fails, verify these values are identical.Register the callback scheme on each platform
RedirectActivity (Android, merged automatically) and uses ASWebAuthenticationSession (iOS) to catch the callback. You only need to declare the URL scheme on each platform.Android: Add the manifest placeholders to your Android build file. The SDK’s RedirectActivity reads these values:AndroidManifest.xml requests the Internet permission:iosApp/iosApp/Info.plist (or via Xcode → target → Info → URL Types):Initialize the Auth0 SDK
commonMain source set, create the Auth0 client once and reuse it. It holds the transport shared by web auth, the Authentication API, and the credentials manager.Create composeApp/src/commonMain/kotlin/Auth0Config.kt:auth0.domain and auth0.clientId from local.properties and exposes them via generated config. The Domain and Client ID both come from Application Settings in the Auth0 Dashboard. The domain must not include the https:// scheme.Implement Login and Logout
suspend function that returns a Result<Success, Error> — no exceptions are thrown for domain errors. Wrap the calls in a ViewModel so your Compose UI can observe the state.Create composeApp/src/commonMain/kotlin/AuthViewModel.kt:Show the user profile
userInfo with the access token to retrieve the authenticated user’s profile.credentialsManager.hasValidCredentials() returns true when a stored, non-expired session is available. Use credentialsManager.getCredentials() to retrieve a valid access token, and renew the access token with the refresh token automatically when needed.Run your app
- App launches with a “Log In” button.
- Tap “Log In” → the system browser opens the Auth0 Universal Login page → complete login.
- Control returns to the app automatically and the button switches to “Log Out”.
- Success!
Troubleshooting & Advanced
Callback URL mismatch error
Callback URL mismatch error
SCHEME://YOUR_DOMAIN/android/APPLICATION_ID/callback for Android and SCHEME://YOUR_DOMAIN/ios/BUNDLE_ID/callback for iOS. The SCHEME (default: your application ID) and package/bundle must be identical to your project’s values. URLs are case-sensitive and the scheme must be lowercase.The browser opens but never returns to the app
The browser opens but never returns to the app
manifestPlaceholders["auth0Scheme"] and ["auth0Domain"] are set in composeApp/build.gradle.kts and run a clean build. On iOS, verify the CFBundleURLSchemes entry in Info.plist matches your bundle identifier.Login returns Result.Failure with a network or timeout error
Login returns Result.Failure with a network or timeout error
domain in Auth0Account is your tenant domain without the https:// scheme (e.g., your-tenant.us.auth0.com). On a physical device, ensure it has network access. You can raise the timeouts via the NetworkingConfiguration passed to Auth0Account.getCredentials fails after login
getCredentials fails after login
offline_access scope by default (which returns a refresh token). If you override scope in LoginOptions, include offline_access, and enable Refresh Token Rotation for the application in the Auth0 Dashboard.Android build fails to merge the RedirectActivity
Android build fails to merge the RedirectActivity
auth0Domain / auth0Scheme manifest placeholders are missing, so the SDK’s merged RedirectActivity has no value to bind to.Fix: Ensure both placeholders are defined in the defaultConfig block of composeApp/build.gradle.kts. If you use multiple build flavors, define them in each flavor.Restore a session on startup
Restore a session on startup
Call your own API with an access token
Call your own API with an access token
Federated logout
Federated logout
Next steps
- Explore the full Auth0 Kotlin Multiplatform SDK and its
EXAMPLES.mdfor organizations, DPoP, passkeys, and custom storage. - Run the complete Android + iOS sample app.
- Learn more about Auth0 Universal Login and refresh tokens.