mirror of
https://github.com/wu736139669/hapi.git
synced 2026-12-04 06:57:55 +00:00
Hub discovery required two authenticator prompts plus a confirm step:
a local locator-only ceremony to read the Hub from the user handle, then a
Hub-issued login challenge. Native apps now sign their own fresh challenge
{v:2, operation:"login", channel:"native", iat, nonce}, read the Hub from
the selected credential's v2 user handle, and post the assertion straight to
POST /api/passkey/login/verify.
- hub: accept native self-issued challenges only within
[now-5min, now+1min] and only once (replay guard keyed on the challenge,
claimed synchronously after verification); remove
/api/passkey/login/options. Browser ceremonies keep Hub-issued challenges.
- shared: createPasskeyNativeLoginChallenge / parsePasskeyNativeLoginChallenge;
drop discovery helpers.
- ios/android: one system sheet from the pairing screen; manual Hub entry
for long-address handles or an explicit Hub, which must match the
credential before anything is sent. Assertions are only posted to the Hub
named by the credential.
- web: revert address-free discovery; the web app signs in to its own Hub.
- docs: native single-ceremony contract and its security trade-off.
55 lines
1.8 KiB
Swift
55 lines
1.8 KiB
Swift
import HapiClient
|
|
import Observation
|
|
|
|
/// Inline pairing progress/error state shared by manual entry (token or
|
|
/// passkey), QR scan, and the deep-link confirm step.
|
|
@Observable @MainActor
|
|
final class PairingAttempt {
|
|
private(set) var isPairing = false
|
|
var failure: PairingFailure?
|
|
|
|
init(failure: PairingFailure? = nil) {
|
|
self.failure = failure
|
|
}
|
|
|
|
func pair(_ model: AppModel, hubUrl: String, accessToken: String) {
|
|
guard !isPairing else { return }
|
|
isPairing = true
|
|
failure = nil
|
|
Task {
|
|
do {
|
|
try await model.pair(hubUrl: hubUrl, accessToken: accessToken)
|
|
// Success: AppModel flips to .paired and tears down the
|
|
// presenting hierarchy; nothing to do here.
|
|
} catch let pairingFailure as PairingFailure {
|
|
failure = pairingFailure
|
|
} catch {
|
|
failure = .unreachable
|
|
}
|
|
isPairing = false
|
|
}
|
|
}
|
|
|
|
/// Single-ceremony passkey sign-in. Without `hubUrl` the hub comes from
|
|
/// the selected passkey (``PairingFailure/passkeyHubAddressRequired`` when
|
|
/// it cannot); with one, the passkey must belong to that hub. Dismissing
|
|
/// the system sheet is not an error: the form returns to its idle state.
|
|
func signInWithPasskey(_ model: AppModel, hubUrl: String? = nil) {
|
|
guard !isPairing else { return }
|
|
isPairing = true
|
|
failure = nil
|
|
Task {
|
|
do {
|
|
try await model.signInWithPasskey(hubUrl: hubUrl)
|
|
} catch PasskeyError.canceled {
|
|
// Silent.
|
|
} catch let pairingFailure as PairingFailure {
|
|
failure = pairingFailure
|
|
} catch {
|
|
failure = .unreachable
|
|
}
|
|
isPairing = false
|
|
}
|
|
}
|
|
}
|