Aller au contenu

iOS SDK

Ce contenu n’est pas encore disponible dans votre langue.

The Prosopo Protect iOS SDK, ProsopoAttestIOS, signs your app’s requests with an Apple App Attest key held in the phone’s Secure Enclave, so the Protect edge can tell a real iPhone from a script. Read Protect for mobile apps first for how the pieces fit together.

In Xcode, choose File → Add Package Dependencies, enter https://github.com/prosopo/protect-ios, choose Up to Next Major Version from the newest release tag (v0.1.9 at the time of writing) and add the ProsopoAttestIOS library to your app target. Or, in Package.swift:

dependencies: [
.package(url: "https://github.com/prosopo/protect-ios", from: "0.1.9"),
],
targets: [
.target(name: "YourApp", dependencies: [
.product(name: "ProsopoAttestIOS", package: "protect-ios"),
]),
]

Then add the App Attest capability to your app target under Signing & Capabilities, and set its environment to production for App Store and TestFlight builds.

Call configure once, as early as you can, for example in your App initialiser or application(_:didFinishLaunchingWithOptions:):

import ProsopoAttestIOS
ProsopoAttestIOS.configure(
siteKey: "your-site-key",
serverURL: "https://protect.example.com",
protectedDomains: ["api.example.com"]
)
ParameterRequiredDescription
siteKeyYesYour Prosopo site key.
serverURLYesYour Protect endpoint, e.g. https://protect.example.com.
protectedDomainsNoThe hosts whose requests are signed. Leave it empty to sign requests to every host; set it so third-party services don’t receive Prosopo headers.
protectedRoutesNoPath prefixes Protect guards, e.g. ["/api/checkout"]. Leave it out to sign every path on protectedDomains. When set, the SDK also learns new protected paths from the edge, so the list doesn’t have to be complete and doesn’t need a new app release when you protect another route.

The SDK attests in the background. Requests made in the first moments after launch wait up to 4 seconds for it, so the first requests your app makes go out signed.

After configure, every request through URLSession.shared, or through a session built from URLSessionConfiguration.default, is signed automatically. Your networking code doesn’t change.

If you build your own session configuration, including through a library such as Alamofire, add the protocol class before you create the session:

import ProsopoAttestIOS
let config = URLSessionConfiguration.default
config.protocolClasses = [ProsopoURLProtocol.self] + (config.protocolClasses ?? [])
let session = Session(configuration: config) // Alamofire

If a protected request goes out unsigned and the edge answers 401 with X-Prosopo-Status: no-session, the SDK attests and sends the request again, the same way the Protect script does in a browser.

WKWebView doesn’t use URLSession, so use the protected WebView:

import ProsopoAttestIOS
let protected = ProsopoProtectWebview()
view.addSubview(protected.webView)
protected.load(URL(string: "https://example.com/account")!)

Or install protection into your own configuration before you create the WebView:

let config = WKWebViewConfiguration()
ProsopoProtectWebview.install(into: config)
let webView = WKWebView(frame: .zero, configuration: config)

Page fetch and XMLHttpRequest calls carry the same App Attest headers as your native requests. From v0.1.9 the SDK also adds the WebView’s prosopo_session cookie to signed native requests, so the WebView and native code are one session. That works with a plain WKWebView on the default data store too.

A blocked request comes back as HTTP 403 with the header x-prosopo-decision: block. Show your own message rather than retrying.

The simulator and a few older devices don’t support App Attest. On those, and in the rare case Apple’s DeviceCheck framework fails, the SDK sends requests unsigned rather than crashing or holding them, and the edge treats them like any other request without a session.

ProsopoAttestIOS.shared exposes read-only state for a debug screen:

  • isSupported: whether this device supports App Attest.
  • isAttested: whether the device has a registered key.
  • attestationState and attestationPhase: where the attestation flow is.
  • lastError: the last attestation or signing error.
  • forceReset(): throw the key away and attest again, for a device stuck in a bad state.

The SDK writes to the unified log under the subsystem io.prosopo.protect, including its version when configure runs. Filter on subsystem == "io.prosopo.protect" in Console.