iOS SDK
Questi contenuti non sono ancora disponibili nella tua lingua.
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.
- Package:
github.com/prosopo/protect-ios, a Swift package - Requires: iOS 17 or later
Install
Section titled InstallIn 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.
Configure
Section titled ConfigureCall 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"])| Parameter | Required | Description |
|---|---|---|
siteKey | Yes | Your Prosopo site key. |
serverURL | Yes | Your Protect endpoint, e.g. https://protect.example.com. |
protectedDomains | No | The 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. |
protectedRoutes | No | Path 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.
Sign your requests
Section titled Sign your requestsURLSession
Section titled URLSessionAfter 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.defaultconfig.protocolClasses = [ProsopoURLProtocol.self] + (config.protocolClasses ?? [])let session = Session(configuration: config) // AlamofireIf 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
Section titled WKWebViewWKWebView 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.
Handle a block
Section titled Handle a blockA blocked request comes back as HTTP 403 with the header x-prosopo-decision: block. Show your own message rather than retrying.
Devices without App Attest
Section titled Devices without App AttestThe 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.
Debugging
Section titled DebuggingProsopoAttestIOS.shared exposes read-only state for a debug screen:
isSupported: whether this device supports App Attest.isAttested: whether the device has a registered key.attestationStateandattestationPhase: 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.