SDK
Android SDK (Kotlin)
Native Android authentication with OAuth 2.0 PKCE, encrypted storage, and biometric login.
Key Features
OAuth 2.0 Authorization Code + PKCE
EncryptedSharedPreferences token storage
BiometricPrompt (fingerprint / face)
Automatic token refresh
Chrome Custom Tab login
Jetpack Compose support
Kotlin Coroutines & Flow
Session management
Requirements
- Android API 24+ (Android 7.0)
- Kotlin 1.8+
- Android Studio Hedgehog+
Installation
Add the dependency to your module-level build.gradle.
// build.gradle.kts (Module)
dependencies {
implementation("com.authme:authme-android:1.0.0")
}
// settings.gradle.kts — add repository if needed
dependencyResolutionManagement {
repositories {
mavenCentral()
}
} Configuration
Initialize the AuthMe client using the builder pattern.
import com.authme.sdk.AuthmeClient
val authme = AuthmeClient.Builder()
.serverUrl("https://auth.example.com")
.realm("my-realm")
.clientId("my-android-app")
.redirectUri("myapp://callback")
.build() Login with PKCE
Launch the OAuth 2.0 Authorization Code + PKCE flow using a Chrome Custom Tab.
// Launch login (opens Chrome Custom Tab)
authme.login(activity) { result ->
when (result) {
is AuthResult.Success -> {
val token = result.accessToken
val user = result.userInfo
println("Logged in as ${user.name}")
}
is AuthResult.Error -> {
println("Login failed: ${result.message}")
}
is AuthResult.Cancelled -> {
println("User cancelled login")
}
}
} Biometric Authentication
Use BiometricPrompt for fingerprint / face unlock re-authentication.
// Enable biometric login (stores tokens in EncryptedSharedPreferences)
authme.enableBiometrics(activity)
// Login with biometrics
authme.loginWithBiometrics(activity) { result ->
if (result is AuthResult.Success) {
println("Biometric login successful")
}
}
// Check availability
val available = authme.isBiometricsAvailable(context) User Info
Retrieve the authenticated user profile.
val user = authme.getUserInfo()
println(user.name) // "John Doe"
println(user.email) // "john@example.com"
println(user.roles) // ["admin", "user"]
// Or use Kotlin coroutines
lifecycleScope.launch {
val user = authme.getUserInfoAsync()
} Token Management
Tokens are stored in EncryptedSharedPreferences and refreshed automatically.
// Automatic refresh before expiry
val token = authme.accessToken
// Manual refresh
authme.refreshToken { result ->
if (result is AuthResult.Success) {
val newToken = result.accessToken
}
}
// Check authentication state
if (authme.isAuthenticated) { /* ... */ } Logout
Logout clears stored tokens and revokes the session on the server.
authme.logout { result ->
// Tokens cleared from EncryptedSharedPreferences
// Session revoked on server
println("Logged out successfully")
} Jetpack Compose Integration
Use the SDK with Jetpack Compose.
@Composable
fun AuthScreen(authme: AuthmeClient) {
val isAuthenticated by authme.isAuthenticatedState.collectAsState()
if (isAuthenticated) {
val user by authme.userState.collectAsState()
Column {
Text("Welcome, ${user?.name}")
Button(onClick = { authme.logout {} }) {
Text("Logout")
}
}
} else {
val context = LocalContext.current
Button(onClick = { authme.login(context as Activity) {} }) {
Text("Sign In")
}
}
}