mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-26 05:27:06 +00:00
Native apps cannot follow a self-hosted hub's domain (entitlements and
asset links are fixed at build time), so they use one shared RP ID,
hapi.run, and every hub accepts it only from exact app origins.
- hub: `{"client":"native"}` on the passkey option routes selects the
native RP; origins are https://hapi.run (iOS/macOS) and the official
android:apk-key-hash values, extendable via HAPI_PASSKEY_NATIVE_ORIGINS
(HAPI_PASSKEY_NATIVE_RP_ID for forks). Native login options restrict
allowCredentials to this hub's passkeys. Accept a null
authenticatorAttachment.
- website: publish apple-app-site-association (webcredentials for
XJB862F92W.run.hapi.app) and assetlinks.json (get_login_creds for
run.hapi.companion; signing fingerprint still a TODO placeholder).
- iOS: webcredentials:hapi.run, AuthenticationServices ceremonies,
passkey-only sign-in on the pairing screen, Settings → Passkeys, and a
passkey-session credential kind used by silent re-auth.
- Android: Credential Manager 1.6.0, the same flows and credential kind,
and README notes on computing the apk-key-hash origin.
- docs: native passkey contract and user guide.
49 lines
1.6 KiB
Swift
49 lines
1.6 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?
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
/// URL-only passkey sign-in. Dismissing the system sheet is not an
|
|
/// error: the form simply returns to its idle state.
|
|
func signInWithPasskey(_ model: AppModel, hubUrl: String) {
|
|
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
|
|
}
|
|
}
|
|
}
|