Sign users in to Keycloak with your app's own screens. Keycloak keeps running the login flow, with its passwords, passkeys, one-time codes, push approvals, required actions and brute-force protection. These extensions hand each step to your app as JSON, and the SDKs for iOS, Android, React Native and Flutter turn it into native screens.
- No browser sheet. Browser-based login (AppAuth) shows a "wants to use β¦ to sign in" prompt and Keycloak's web pages. Here every step is a screen in your app.
- The flow lives in Keycloak. Change the flow, add a second factor or require an action in the admin console, and every app follows without a release.
- Unlike the password grant, it supports MFA, passkeys, required actions and brute-force rules, and tokens can be bound to the device with DPoP.
Some things stay on Keycloak's own pages: registration, password reset, TOTP enrollment, and social or enterprise identity providers. When a login reaches one of those, the SDK finishes it in the system browser and the user comes back signed in.
sequenceDiagram
participant App as Your app (SDK)
participant KC as Keycloak + extensions
App->>KC: start login
KC-->>App: challenge: username β shown as a native screen
App->>KC: answer, then the next challenge⦠(one per step of your flow)
KC-->>App: authorization code
App->>KC: token request with PKCE and DPoP
KC-->>App: tokens bound to the device key
The protocol follows the IETF draft OAuth 2.0 for First-Party Applications. Details: protocol and flows.
| π Passwords | with the platform password manager: AutoFill on iOS, Credential Manager on Android |
| πͺͺ Passkeys | sign in, enroll after a password login, or register one later in the app |
| π’ One-time codes | TOTP, email and SMS codes, recovery codes |
| π PIN codes | a short numeric PIN as a second factor, with the optional PIN extension |
| π² Push approval | number matching, through APNs or Firebase Cloud Messaging |
| β¬οΈ Step-up | ask for a stronger factor before a sensitive action |
| π Required actions | update password, verify email, accept terms, set a PIN, register a passkey or push device |
| βοΈ Actions from your app | "Change password", "Change PIN", "Verify email" or "Add a passkey" buttons in your settings: the user proves who they are first, can sign out other devices, and your app learns the outcome (Keycloak's kc_action) |
Every SDK has default screens for all of these. Use them as they are, or replace them one at a time.
You need Docker, Java 21 and Maven, plus the toolchain for the platform you pick (Xcode, Android Studio, Node with Yarn, or Flutter). Start Keycloak with the demo realm:
git clone https://github.com/p2-inc/native-apps && cd native-apps/keycloak-native-auth
mvn -DskipTests -DskipITs package
cd demo && docker compose up --wait # Keycloak on :8080, mailpit on :8025The iOS demo app expects Keycloak on port 8089, so for iOS start it with KC_PORT=8089 docker compose up --wait instead.
Then run a demo app from the repository root and sign in as alice / alice-password. For the second factor, ./scripts/walkthrough.sh in the demo directory prints the current TOTP code (it needs curl, jq and openssl), or set up any authenticator app with the key alice-totp-secret-20261014.
| From the repository root | |
|---|---|
| π± iOS | Open ios/KeycloakNativeDemo/KeycloakNativeDemo.xcodeproj and run it on a simulator (details) |
| π€ Android | cd android && ./gradlew :demo:installDebug with an emulator running (details) |
| βοΈ React Native | cd react-native/keycloak-native-react-native && yarn && yarn example ios (or android) |
| π¦ Flutter | cd flutter/keycloak_native_flutter/example && flutter run |
Every demo app has a Server screen to point it at another Keycloak: the server URL, realm and client IDs, saved on the device, with "Reset to defaults". Anything other than a local development host must use https. See Server settings.
Other demo users show other parts of the flow: bob gets an email code (read it in mailpit), hank has to accept terms, and carol has to update her password. All of them.
Keycloak 26.4 or later.
- Download
keycloak-native-auth-providers-<version>.zipfrom the latest release and put all its jars in Keycloak'sproviders/directory; they depend on each other. The zip also carries the optional factors' extensions (push MFA, and keycloak-pin for PIN codes); they do nothing until a flow uses them. - Create an authentication flow named
nativefrom the native steps (native-username,native-password,native-totp,native-passkeyand so on). Don't bind it as the browser flow: the native endpoint finds it by name, and a client or realm can choose another with thenative-auth.flow-aliasattribute. The demo realm is a working example to import or copy from. - Create a public OpenID Connect client with PKCE S256 and the attribute
native-auth.enabledset totrue, and register a redirect URI such asmyapp://auth/callbackfor logins that finish in the browser.
The server guide covers every setting, passkey domains and push. On Phase Two hosted Keycloak, contact us and we'll install the extensions on your cluster.
A Swift package for iOS 17+. In Xcode, add https://github.com/p2-inc/native-apps and link KeycloakNativeCore and KeycloakNativeUI.
import KeycloakNativeCore
import KeycloakNativeUI
let kc = KeycloakNative.configure(
issuer: URL(string: "https://idp.example.com/realms/demo")!,
clientId: "my-app"
)
let flow = kc.authentication().startLogin(LoginParameters(scope: "openid profile"))
// In a SwiftUI view:
NativeLoginView(kc: kc, flow: flow) { result in
if case .authorized(let credentials) = result {
Task { try await kc.credentialsManager().store(credentials) }
}
}π iOS guide, including passkeys (Associated Domains) and push.
Kotlin and Jetpack Compose for Android 9+ (API 28), from Maven Central.
implementation("io.phasetwo.keycloak.nativeauth:keycloak-native-android:0.3.0")
implementation("io.phasetwo.keycloak.nativeauth:keycloak-native-ui:0.3.0")val kc = KeycloakNative.configure(
URI("https://idp.example.com/realms/demo"),
"my-app",
KeycloakNative.Options(
hardwareKeys = KeystoreDPoPKeys(context), // DPoP key in the Android Keystore
secureStore = KeystoreSecureStore(context, namespace = "my-app"), // tokens sealed by the Keystore
),
)
val flow = kc.authentication().startLogin(LoginParameters(scope = "openid profile"))
// In a composable:
NativeLoginScreen(kc, flow, onResult = { result ->
if (result is NativeLoginResult.Authorized) scope.launch { kc.credentialsManager().store(result.credentials) }
})π Android guide, including the activity setup for passkeys, saved passwords and the browser fallback.
A TurboModule for React Native 0.84+ (New Architecture), with an Expo config plugin.
npm install @p2-inc/keycloak-native-react-nativeimport { KeycloakNative, NativeLoginScreen } from '@p2-inc/keycloak-native-react-native';
const kc = KeycloakNative.configure({ issuer: 'https://idp.example.com/realms/demo', clientId: 'my-app' });
const flow = await kc.authentication.startLogin({ scope: 'openid profile' });
<NativeLoginScreen
kc={kc}
flow={flow}
onResult={async (result) => {
if (result.kind === 'authorized') await kc.credentialsManager.store(result.credentials);
}}
/>π React Native guide, including the Android activity and Expo setup.
A plugin for Flutter 3.35+ on iOS and Android.
flutter pub add keycloak_native_flutterimport 'package:keycloak_native_flutter/keycloak_native_flutter.dart';
final kc = await KeycloakNative.configure(
issuer: Uri.parse('https://idp.example.com/realms/demo'),
clientId: 'my-app',
);
final flow = await kc.authentication.startLogin(const LoginParameters(scope: 'openid profile'));
NativeLoginView(
kc: kc,
flow: flow,
onResult: (result) async {
if (result is NativeLoginAuthorized) await kc.credentialsManager.store(result.credentials);
},
);π Flutter guide, including the Android activity setup.
- PKCE on every login. DPoP binds the code, access token and refresh token to a key in the Secure Enclave or Android Keystore. We recommend DPoP for every app; your APIs then need to accept
Authorization: DPoPand check the proof (details). - Tokens are stored in the Keychain or Keystore. In React Native and Flutter, the refresh token never reaches JavaScript or Dart.
- Keycloak enforces the flow, MFA, brute-force rules and required actions, not the app.
Read the security model. To report a vulnerability, see SECURITY.md.
Pre-1.0: any release can change the protocol or the API, so pin exact versions. The Maven Central, npm and pub.dev packages above start with 0.3.0.
The Keycloak extensions are integration-tested against Keycloak 26.4, 26.6 and 26.8. Each SDK is tested in CI by replaying recorded server exchanges, and the demo apps run on simulators and emulators. Passkeys and push delivery on real devices are being verified now. See the roadmap.
- Documentation: setup, protocol, flow examples, troubleshooting, and the repository layout
- Native apps on phasetwo.io and the launch post
- Contributing and issues
The SDKs, the React Native and Flutter wrappers and the demo setup are Apache 2.0. The Keycloak extensions are under the Elastic License 2.0, like Phase Two's other extensions: free to use and self-host, but not to offer as a hosted service.
Which license covers which files
| Path | License |
|---|---|
Package.swift, ios/, android/, flutter/, react-native/, spec/, docs/ |
Apache-2.0 (LICENSE, NOTICE) |
keycloak-native-auth/demo/ except src/: compose files, realm export, resource server, scripts and recorded transcripts |
Apache-2.0 (LICENSE) |
keycloak-native-auth/push-mfa-extension-java21/: ba-itsys' push MFA extension, rebuilt for Java 21 |
Apache-2.0 (LICENSE, NOTICE) |
Everything else in keycloak-native-auth/, including the integration tests in demo/src/ |
ELv2 (COPYING) |
keycloak-pin.jar in the providers zip: Phase Two's PIN extension, built from p2-inc/keycloak-pin |
ELv2 (COPYING) |
Copyright 2026 Phase Two, Inc.