OpenID Connect Authentication
Authentication follows the Authorization Code Flow with PKCE — the recommended flow for mobile apps, as defined in RFC 6749 and RFC 7636. For a detailed protocol reference, see the OpenID Connect Core 1.0 spec.
At a high level, the flow has three steps:
1. Authorization Request The app opens a secure system browser and redirects the user to the Identity Provider (e.g. Keycloak). A PKCE code_challenge is included so the token exchange can later be verified.
2. Callback After the user authenticates, the Identity Provider redirects back to the app via a custom URI scheme or App/Universal Link, carrying a short-lived authorization_code.
3. Token Request The app exchanges the authorization_code — together with the PKCE code_verifier — for an access_token, id_token, and optionally a refresh_token.
Since mobile apps are public clients (no client_secret), PKCE is mandatory.
Implementation
The recommended library for both platforms is AppAuth, a certified OpenID Connect implementation maintained by the OpenID Foundation:
AppAuth handles PKCE, endpoint discovery, and the secure browser session automatically:
iOS uses
ASWebAuthenticationSessionunder the hoodAndroid uses Chrome Custom Tabs
iOS (AppAuth-iOS)
Installation
Swift Package Manager:
CocoaPods:
Redirect URI — Info.plist
Info.plistLogin
Hold a strong reference to currentAuthFlow for the duration of the session. Releasing it cancels the ASWebAuthenticationSession.
Android (AppAuth-Android)
Installation
build.gradle:
Redirect URI — AndroidManifest.xml
AndroidManifest.xmlLogin
Terminating an OpenID SSO Session
The authentication request will usually initiate an SSO Session, which will ensure, that other apps using the same authorization URL can use the session to automatically login the user. If you want to terminate such a session, preventing other apps from getting automatically logged in, you need to create an EndSessionRequest instead of AuthorizationRequest providing the ID Token which you can fetch from the SDK with fetchTokenTypeType .
Legacy XV Token Exchange
Apps can convert their Legacy XV Tokens into OpenID credentials by generating a "magic link." This link functions like a standard authentication link. However, you must create custom AuthorizationRequest for AppAuth, to use this custom URL and to skip the nonce validation.
Last updated