OpenID Connect Authentication
Implementation
Platform
Library
Minimum OS
Installation
https://github.com/openid/AppAuth-iOSpod 'AppAuth'Redirect URI — Info.plist
Info.plist<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>com.example.app</string>
</array>
</dict>
</array>Login
import AppAuth
class AuthManager {
// Retain the session to keep ASWebAuthenticationSession alive
var currentAuthFlow: OIDExternalUserAgentSession?
func login(presenting viewController: UIViewController) {
// Get the Authentication URL from the SDK
guard let openIDBaseUrl = URL(string:kapeSDK?.manager.getConfiguration().domains().getOpenidApiDomain() ?? "") else { return }
// 1. Discover AS endpoints
OIDAuthorizationService.discoverConfiguration(forIssuer: openIDBaseUrl) { configuration, error in
guard let configuration else {
print("Discovery failed: \(error!)")
return
}
// 2. Build authorization request — PKCE is handled automatically
let request = OIDAuthorizationRequest(
configuration: configuration,
clientId: "my-mobile-app",
// use offline_access to request long-living Refresh Tokens
scopes: [OIDScopeOpenID, OIDScopeProfile, OIDScopeEmail, "offline_access"],
redirectURL: URL(string: "com.example.app:/callback")!,
responseType: OIDResponseTypeCode,
additionalParameters: nil
)
// 3. Open ASWebAuthenticationSession and exchange code for tokens
self.currentAuthFlow = OIDAuthState.authState(
byPresenting: request,
presenting: viewController
) { authState, error in
guard let authState else {
print("Auth failed: \(error!)")
return
}
let credentials = AuthCredentials(
accessToken: authState.lastTokenResponse?.accessToken ?? "",
refreshToken: authState.lastTokenResponse?.refreshToken ?? "",
idToken: authState.lastTokenResponse?.idToken ?? ""
)
try kapeSDK!.manager.identity().openidAuthenticateWithAuthCredentials(authCredentials: credentials)
}
}
}
}Terminating an OpenID SSO Session
Login Hint (Cross-App SSO)
Generating a Login Token
How It Works
Last updated