Android Quickstart
Use this guide to add ThunderID authentication to an Android application using the ThunderID Android SDK for Jetpack Compose.
What You Will Learn
- Create a new Android Studio project
- Install the
dev.thunderid:composeGradle dependency
- Add working sign-in and sign-out using Jetpack Compose components
- Display the signed-in user's name
Prerequisites
- About 15 minutes
- Android Studio, installed and up to date
- API 24 (Android 7.0) deployment target
Check out the complete Android Quickstart Sample in the ThunderID repository.
Run ThunderID
Start a local ThunderID instance. Pick the method that works best for you:
Requires Node.js 18+
Full install guide →Once it's running, the console is available at https://localhost:8090/console.
Create an Application
-
Sign in to the Console.
Test UserIf you used the default setup, sign in to the Console as
adminwith the password generated during setup and printed to the setup output (unless you supplied your own). -
Navigate to Applications, and click Add Application.
-
Under Application Type, select Mobile App.
-
Enter a name (e.g.
My Android App) and create an application. The rest of the settings can stay at their defaults. -
Copy the Client ID from the General tab. You'll add the redirect URI in the next step after configuring your URL scheme.
Create an Android App
In Android Studio, create a new project using the Empty Activity template with Kotlin as the language and Jetpack Compose enabled.
If you already have an existing Android project, skip this step.
Install the ThunderID Compose SDK
Add the ThunderID Maven repository to your settings.gradle.kts:
dependencyResolutionManagement {
repositories {
maven("https://maven.thunderid.dev/releases")
}
}
Then add the dev.thunderid:compose dependency to your app's build.gradle.kts. This includes the core dev.thunderid:android client as a dependency.
dependencies {
implementation("dev.thunderid:compose:0.1.0")
}
If you use Groovy-based Gradle scripts (build.gradle) instead of the Kotlin DSL, add the dependency as:
implementation 'dev.thunderid:compose:0.1.0'
Configure a Callback URL Scheme
ThunderID redirects back to your app after sign-in and sign-out using a custom URL scheme. You need to register this scheme in two places.
1. Register the scheme in your app
Open AndroidManifest.xml and add an intent filter with your scheme to your launcher activity. Use singleTask launch mode so the redirect reuses the existing activity instance instead of creating a new one.
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="dev.thunderid.quickstart" />
</intent-filter>
</activity>
2. Register the redirect URI in the ThunderID console
In the console, open your registered application and add the following as an Allowed Redirect URI:
dev.thunderid.quickstart://callback
Add the same value as an Allowed Post-Logout Redirect URI:
dev.thunderid.quickstart://logout
Initialize the SDK
Open your MainActivity and wrap the content you pass to setContent with the ThunderIDProvider composable. This provides ThunderIDState to all child composables through LocalThunderID.
package dev.thunderid.quickstart
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.MaterialTheme
import dev.thunderid.android.ThunderIDConfig
import dev.thunderid.compose.ThunderIDProvider
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MaterialTheme {
ThunderIDProvider(
config = ThunderIDConfig(
baseUrl = "https://localhost:8090",
clientId = "<your-client-id>",
scopes = listOf("openid", "profile", "email"),
afterSignInUrl = "dev.thunderid.quickstart://callback",
afterSignOutUrl = "dev.thunderid.quickstart://logout",
applicationId = "<your-application-id>"
)
) {
ContentView()
}
}
}
}
}
Replace <your-client-id> with the Client ID and <your-application-id> with the Application ID from your ThunderID application settings.
Configuration Parameters
| Parameter | Description |
|---|---|
baseUrl | Your ThunderID instance URL. Must use HTTPS. |
clientId | The Client ID from your ThunderID application |
scopes | OAuth 2.0 scopes to request. Include "openid" at minimum. |
afterSignInUrl | The redirect URI to return to after sign-in |
afterSignOutUrl | The redirect URI to return to after sign-out |
applicationId | The Application ID used for embedded (app-native) sign-in flows |
Add Sign-In and Sign-Out
The ThunderID Android SDK provides SignedIn and SignedOut guard composables for conditional rendering, a SignIn composable for the embedded sign-in flow, and a SignOutButton for sign-out.
Create ContentView.kt:
package dev.thunderid.quickstart
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import dev.thunderid.compose.LocalThunderID
import dev.thunderid.compose.components.guards.SignedIn
@Composable
fun ContentView() {
val thunder = LocalThunderID.current
if (!thunder.isInitialized) {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
CircularProgressIndicator()
}
} else {
SignedIn(fallback = { AuthView() }) {
HomeView()
}
}
}
Create AuthView.kt to display the sign-in form:
package dev.thunderid.quickstart
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import dev.thunderid.compose.components.presentation.auth.SignIn
@Composable
fun AuthView() {
Column(
modifier = Modifier
.fillMaxSize()
.padding(24.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
Text(text = "Welcome", style = MaterialTheme.typography.headlineMedium)
SignIn(
applicationId = "<your-application-id>",
modifier = Modifier.padding(top = 24.dp),
)
}
}
Display User Profile Information
Create HomeView.kt to show the authenticated user's name and a sign-out button:
package dev.thunderid.quickstart
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import dev.thunderid.compose.LocalThunderID
import dev.thunderid.compose.components.actions.SignOutButton
@Composable
fun HomeView() {
val thunder = LocalThunderID.current
val user = thunder.user
Column(
modifier = Modifier
.fillMaxSize()
.padding(24.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
Text(
text = "Welcome, ${user?.displayName ?: user?.email ?: "User"}!",
style = MaterialTheme.typography.headlineSmall,
)
user?.email?.let {
Text(text = it, style = MaterialTheme.typography.bodyMedium)
}
SignOutButton(modifier = Modifier.padding(top = 24.dp))
}
}
Run the App
In Android Studio, select an API 24+ emulator or device and press Run (▶).
You'll need a user to sign in with. If you haven't created one yet, open https://localhost:8090/console, navigate to Users, and add a test user with an email and password.
You should see the sign-in form. Enter your test user credentials and tap Submit. After successful authentication, the home screen displays the user's name and a Sign Out button.