This is a sample Android application demonstrating how to use the oauth2 module along with web-authentication-ui and auth-foundation. It showcases several OAuth 2.0 flows including:
- Browser-based login (Authorization Code Flow via Chrome Custom Tab)
- Resource Owner Password flow
- Device Authorization flow
- Token Exchange flow
- An Okta developer account (free)
- Android Studio
- An Okta Application configured as a Native App
- Sign in to your Okta Admin Console.
- Navigate to Applications → Applications and click Create App Integration.
- Select OIDC - OpenID Connect as the sign-in method and Native Application as the application type, then click Next.
- Configure the application:
- App integration name: Choose a name (e.g.,
Okta Mobile Kotlin Sample) - Grant types: Ensure Authorization Code and Refresh Token are checked. Enable Device Authorization if you want to test the Device Authorization flow.
- Sign-in redirect URIs: Add
com.okta.sample.android:/login - Sign-out redirect URIs: Add
com.okta.sample.android:/logout
- App integration name: Choose a name (e.g.,
- Under Assignments, assign the app to the appropriate users or groups, then click Save.
- Note the Client ID from the application's General tab.
The default authorization server issuer URL follows this pattern:
https://<your_okta_domain>.okta.com/oauth2/default
You can view all available authorization servers at:
https://<your_okta_domain>.okta.com/admin/oauth2/as
Add the following keys to local.properties in the root directory of the project with values from your Okta application:
issuer=https://<your_okta_domain>.okta.com/oauth2/default
clientId=<your_client_id>
signInRedirectUri=com.okta.sample.android:/login
signOutRedirectUri=com.okta.sample.android:/logout
legacySignInRedirectUri=com.okta.sample.android.legacy:/login
legacySignOutRedirectUri=com.okta.sample.android.legacy:/logout| Property | Description |
|---|---|
issuer |
Your authorization server URL. Usually https://<domain>.okta.com/oauth2/default. Custom authorization servers are also supported. |
clientId |
The Client ID of your Native App from the Okta Admin Console. |
signInRedirectUri |
The redirect URI after sign-in. Must match what is registered in the Okta app. Use reverse domain notation, e.g. com.okta.sample.android:/login. |
signOutRedirectUri |
The redirect URI after sign-out. Must match what is registered in the Okta app. If omitted, derived from signInRedirectUri by replacing /callback with /logout. |
legacySignInRedirectUri |
Redirect URI used by the legacy token migration sample. |
legacySignOutRedirectUri |
Redirect URI used by the legacy token migration sample. |
Note:
local.propertiesis read at build time byapp/build.gradle.ktsand injected asBuildConfigfields. It already exists for your Android SDK path and is listed in.gitignore— never commit real credentials to source control.
Open the project in Android Studio and run the app configuration, or build via Gradle:
./gradlew :app:assembleDebug| Package | Description |
|---|---|
browser |
Browser-based login using the Authorization Code flow |
deviceauthorization |
Device Authorization Grant flow |
resourceowner |
Resource Owner Password flow |
tokenexchange |
Token Exchange (Native SSO) flow |
dashboard |
Post-login screen showing token info and available actions |