Skip to main content
iOS

Integrate the Human Token Journey into your iOS app using ASWebAuthenticationSession.

Markdown

ASWebAuthenticationSession launches the Human Token Journey in a system-managed browser. When the journey finishes, the session returns to your app via the registered URL scheme.

Prerequisites​

  • iOS 13 or later
  • Xcode 14+
  • AuthenticationServices framework (built-in)
  • A unique URL scheme for your app (e.g. myapp)

Step 1: Define your URL scheme​

Choose a unique scheme (e.g. myapp). This is used as the callbackUri when creating the process:

callbackUri: myapp://callback

Step 2: Create the presentation context provider​

import AuthenticationServices
import UIKit

class UnicoAuthenticationController: NSObject, ASWebAuthenticationPresentationContextProviding {
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first else {
return ASPresentationAnchor()
}
return window
}
}

Step 3: Create the session manager​

import AuthenticationServices

class AuthenticationSessionManager {
static let shared = AuthenticationSessionManager()
private var session: ASWebAuthenticationSession?
private let contextProvider = UnicoAuthenticationController()

func start(url: URL, completion: @escaping (String?) -> Void) {
let newSession = ASWebAuthenticationSession(
url: url,
callbackURLScheme: "myapp"
) { callbackURL, error in
self.session = nil
if let callbackURL = callbackURL {
let components = URLComponents(url: callbackURL, resolvingAgainstBaseURL: false)
let processId = components?.queryItems?.first(where: { $0.name == "id" })?.value
completion(processId)
} else {
completion(nil)
}
}
newSession.presentationContextProvider = contextProvider
newSession.prefersEphemeralWebBrowserSession = true
newSession.start()
session = newSession
}
}

Step 4: Launch the journey​

guard let url = URL(string: processLink) else { return }

AuthenticationSessionManager.shared.start(url: url) { processId in
if let processId = processId {
// Journey completed — send processId to your backend via Get Process
} else {
// User canceled the session
}
}
info

The callbackURLScheme parameter takes only the scheme name (myapp), without ://.

File summary​

FilePurpose
UnicoAuthenticationController.swiftPresentation context provider
Session manager (your view or service)ASWebAuthenticationSession lifecycle