android-oidc-caep-native-app
An OpenID Connect client library for native Android apps, written in Kotlin. It runs in the app as a public client, with no client secret. It is the Android counterpart of the Swift library swift-oidc-caep-native-app (macOS), itself the native port of the JavaScript library oidc-caep-client. It covers:
- Signing in: Authorization Code with PKCE, PAR, DPoP-bound tokens, RFC 9207 mix-up defence, and full ID token validation. The sign-in page opens in the system browser through a Custom Tab (RFC 8252), never in a
WebView. - Tokens: cached encrypted at rest (AES-256-GCM under an Android Keystore key) and refreshed before they expire.
- DPoP keys: generated in the Android Keystore, in StrongBox when the device has it, else the TEE, so the private key can never be read out.
- Several accounts: several people signed in to one app, with one active account.
- CAEP: subscribing to the identity provider’s Shared Signals stream, with one handler per CAEP event and a hook for your own logic.
CAEPEnableddefaults to true. Set it to false to turn off CAEP and RISC: the receiver is not started, andssf.readandssf.manageare left out of the authorization request, so the app can sign in at an identity provider that does not implement Shared Signals.
Everything is in the package net.rcbj.oidccaep. The library needs Android 9 (API 28) or later; its dependencies are kotlinx.coroutines, kotlinx.serialization-json, OkHttp and androidx.browser. The API follows the Swift library’s, with Kotlin’s conventions; Android and macOS lists every difference.
Install
The library is on Maven Central as com.iyasec:oidc-caep-android; Maven Central is among the repositories every Android project already uses. In the app module’s build.gradle.kts:
android {
defaultConfig {
manifestPlaceholders["oidcRedirectScheme"] = "com.example.myapp" // the redirect URI's scheme
}
}
dependencies {
implementation("com.iyasec:oidc-caep-android:0.1.0")
}
Its dependencies (OkHttp, kotlinx.coroutines, kotlinx.serialization, androidx.browser) come with it. Each release is also a GitHub Release.
Where to read
- Building a native Android app, the walkthrough:
- registering the app at the identity provider, with a private-use redirect URI;
- the
oidc_configuration.jsonfile; - signing in, and where tokens and keys are kept;
- calling your APIs;
- receiving CAEP events;
- signing out, errors, the manifest, backups and troubleshooting.
- API reference: the security features, every option and its default, the methods and events, and the CAEP event table.
- API reference (Dokka), generated from the source for every public declaration.
- Running the demo: a complete Jetpack Compose app built this way, with several accounts, a CAEP event log and an event-type picker, and how to run it on the Android emulator against iya-sts.
- Android and macOS: every difference from the Swift library.
- Development: tests (unit and live), CI, branches and the layout of the repository.
Quick look
import net.rcbj.oidccaep.*
// assets/oidc_configuration.json: MetadataURL, ClientID, Scopes, RedirectURI, …
val configuration = OIDCAppConfiguration.load(context)
val client = configuration.makeClient(dpopKeyStore = preferredDPoPKeyStore(context))
val accounts = AccountManager(client, AccountManagerOptions(store = KeystoreTokenStore(context))).restore()
// Sign in in a Custom Tab.
val signedIn = accounts.signIn(configuration.makeAuthenticator(activity))
val key = signedIn.account.key
val identity = signedIn.account.identity
// React to security events about the signed-in person.
val caep = SSFReceiver(SSFReceiverConfiguration(
transmitterIssuer = client.issuer,
authorization = SSFAuthorization.oidc(client) { accounts.getTokenSet() },
// Runs for every event, before the handlers below. The default, logEventReceived, logs the
// event's name and jti; replace it with your own logic, or pass null to turn it off.
onEventReceived = { event ->
logEventReceived(event)
audit.record(event.name, event.subject)
},
))
// One handler per event type. Register your own to decide what each event does.
caep
.onSessionRevoked { event ->
if (subjectMatches(event.subject, identity)) accounts.end(key, "Your session was ended.")
}
.onTokenClaimsChange { accounts.refresh() }
.onCredentialChange { event ->
if (event.payload.string("change_type") in setOf("revoke", "delete")) accounts.end(key, "Sign in again.")
}
.onAssuranceLevelChange { event ->
if (event.payload.string("change_direction") == "decrease") requireStepUp()
}
.onDeviceComplianceChange { event ->
if (event.payload.string("current_status") == "not-compliant") accounts.end(key, "This device no longer meets policy.")
}
.onRiskLevelChange { event ->
if (event.payload.string("current_level") == "HIGH") accounts.end(key, "Unusual activity was detected.")
}
.onError { error, context -> println("CAEP ${context.phase.value} ${error.code ?: ""} ${error.message}") }
caep.start(catchUp = true)
Every call is a suspend function: run it in a coroutine (viewModelScope.launch { … }). audit and requireStepUp() stand for your app’s own code. Registering a handler for an event type adds to what runs; removeHandlers(CAEP.SESSION_REVOKED) removes them again. onEvent(type, handler) handles any other type, such as the RISC events in RISC. The guide wires a receiver to the active account and suggests a reaction for each event, and the reference lists every handler and its payload fields.
MIT licensed. © 2026 Iya CyberSecurity Solutions, LLC.