> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.id.me/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.id.me/_mcp/server.

# iOS

> Launch IDMe from iOS apps with ASWebAuthenticationSession and receive the OAuth redirect with a universal link or custom scheme.

Use this guide to open an IDMe OAuth 2.0 flow from an iOS app in the system browser. Read the [native app integrations overview](/guides/o-auth-2-0/native-app-integrations/overview) first.

> **Warning**
>
> Don't load IDMe in a `WKWebView`. Use `ASWebAuthenticationSession` directly or through [AppAuth for iOS](https://github.com/openid/AppAuth-iOS). `SFSafariViewController` isn't designed for sign-in flows and doesn't return the redirect to your app, so use `ASWebAuthenticationSession` instead.

## ASWebAuthenticationSession

`ASWebAuthenticationSession` opens IDMe in a secure Safari-based sheet, shares the member's Safari session, and returns the redirect URL to your completion handler.

### Universal link callback (iOS 17.4 and later)

Use an `https` redirect URI on a domain you own. Only your app can receive it.

**`Launch IDMe with an https callback`**

```swift Launch IDMe with an https callback
import AuthenticationServices

final class IdmeSignIn: NSObject, ASWebAuthenticationPresentationContextProviding {
    private var session: ASWebAuthenticationSession?

    func start(authorizationURL: URL) {
        session = ASWebAuthenticationSession(
            url: authorizationURL,
            callback: .https(host: "example.com", path: "/idme/callback")
        ) { [weak self] callbackURL, error in
            self?.handle(callbackURL: callbackURL, error: error)
        }
        session?.presentationContextProvider = self
        session?.start()
    }

    func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
        UIApplication.shared.connectedScenes
            .compactMap { ($0 as? UIWindowScene)?.keyWindow }
            .first ?? ASPresentationAnchor()
    }
}
```

The `https` callback requires the `webcredentials` associated domain for your redirect host:

* Add `webcredentials:example.com` under **Signing & Capabilities > Associated Domains**.
* Publish an `apple-app-site-association` file at `https://example.com/.well-known/apple-app-site-association` that lists your app ID under `webcredentials`.

### Custom scheme callback

For apps that support earlier iOS versions, use a custom URL scheme such as `com.example.app`. Register the matching redirect URI, such as `com.example.app:/idme/callback`, with IDMe.

**`Launch IDMe with a custom scheme callback`**

```swift Launch IDMe with a custom scheme callback
session = ASWebAuthenticationSession(
    url: authorizationURL,
    callbackURLScheme: "com.example.app"
) { [weak self] callbackURL, error in
    self?.handle(callbackURL: callbackURL, error: error)
}
session?.presentationContextProvider = self
session?.start()
```

### Handle the result

**`Handle the redirect`**

```swift Handle the redirect
func handle(callbackURL: URL?, error: Error?) {
    if let error = error as? ASWebAuthenticationSessionError,
       error.code == .canceledLogin {
        showSignInCanceled()
        return
    }

    guard let callbackURL,
          let items = URLComponents(url: callbackURL, resolvingAgainstBaseURL: false)?.queryItems,
          items.first(where: { $0.name == "state" })?.value == savedState,
          let code = items.first(where: { $0.name == "code" })?.value else {
        showSignInError()
        return
    }

    exchangeCode(code, codeVerifier: savedCodeVerifier)
}
```

> **Info**
>
> Leave `prefersEphemeralWebBrowserSession` set to `false` (the default) so returning members can reuse their existing IDMe sign-in. Set it to `true` only if your use case requires a fresh sign-in every time.

## AppAuth for iOS

AppAuth wraps `ASWebAuthenticationSession` and adds PKCE and `state` handling.

**`Start the IDMe request with AppAuth`**

```swift Start the IDMe request with AppAuth
let configuration = OIDServiceConfiguration(
    authorizationEndpoint: URL(string: "https://api.id.me/oauth/authorize")!,
    tokenEndpoint: URL(string: "https://api.id.me/oauth/token")!
)

let request = OIDAuthorizationRequest(
    configuration: configuration,
    clientId: clientID,
    scopes: ["YOUR_SCOPE"],
    redirectURL: URL(string: "com.example.app:/idme/callback")!,
    responseType: OIDResponseTypeCode,
    additionalParameters: nil
)

currentAuthorizationFlow = OIDAuthorizationService.present(
    request,
    presenting: self
) { response, error in
    // Exchange response?.authorizationCode with your backend,
    // or use OIDAuthState.authState(byPresenting:) to exchange in the app.
}
```

Replace `YOUR_SCOPE` with your policy scope, and use the sandbox endpoints when testing.

## Camera permissions

When IDMe runs in `ASWebAuthenticationSession`, Safari requests camera access for document, selfie, and liveness capture, including in-page capture by the IDMe Legal ID and face verification SDKs. Your app doesn't need an `NSCameraUsageDescription` entry or a `requestMediaCapturePermissionFor` handler for IDMe capture steps. Don't switch to a `WKWebView` for camera steps.

## Testing checklist

* The authorization URL opens in `ASWebAuthenticationSession`, not a `WKWebView` or `SFSafariViewController`.
* A member can sign in with a passkey.
* Document capture, selfie capture, and liveness checks complete on a physical device.
* Tapping **Cancel** returns the member to a recoverable screen.
* A redirect with a mismatched `state` is rejected.
* For `https` callbacks, the `apple-app-site-association` file is reachable and lists your app ID under `webcredentials`.