This quickstart guide serves as an integration example for our trusted partners so that you will be able to test and/or evaluate LoginID’s authentication service for your own needs.
To obtain our client API keys among with other credentials you will need for our AppAuth SDK, please contact [email protected]
​
To configure your Xcode environment using Cocoapods please follow instructions on AppAuth SDK GitHub here.
This integration required Safari FIDO2 WebAuthn available on iOS 14.
target 'MyTestOauthApp' douse_frameworks!#LoginSDK pod installpod AppAuth# your other pods​end
The custom URI scheme = lid-[unique-id] part of your callbackURL
import AppAuth​@UIApplicationMainclass AppDelegate: UIResponder, UIApplicationDelegate {// initialize OIDC Authorization Sessionvar currentAuthorizationFlow: OIDExternalUserAgentSession?​//...//...// handle oauth2 custom uri scheme redirect here​func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {​if let authorizationFlow = self.currentAuthorizationFlow,authorizationFlow.resumeExternalUserAgentFlow(with: url) {self.currentAuthorizationFlow = nilreturn true}// Your additional URL handling (if any)return false}}
import AppAuth
// configure authorization endpointlet authorizationEndpoint = URL(string: "https://oauth2.usw1.loginid.io/oauth2/auth")!// configure token endpointlet tokenEndpoint = URL(string: "https://oauth2.usw1.loginid.io/oauth2/token")!​let configuration = OIDServiceConfiguration(authorizationEndpoint:authorizationEndpoint, tokenEndpoint: tokenEndpoint)
let clientID = ""let clientSecret = ""let redirectURI = URL(string:"://oauth2redirect")!​​let request = OIDAuthorizationRequest(configuration: configuration,clientId: clientID,clientSecret: clientSecret,scopes: [OIDScopeOpenID],redirectURL: redirectURI,responseType: OIDResponseTypeCode,additionalParameters: nil)​let appDelegate = UIApplication.shared.delegate as! AppDelegateappDelegate.currentAuthorizationFlow =OIDAuthState.authState(byPresenting: request, presenting: self) { authState, error inif let authState = authState {// handle success authorization hereprint("Authorization success. Access token: " +"\(authState.lastTokenResponse?.accessToken ?? "nil")")//...//...} else {// handle authorization error hereprint("Authorization error: \(error?.localizedDescription ?? "Unknown error")")//...//...}}