SPB Git

Repository Public

AuthDTO.swift 17.6 KB 461 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : Claude Remote / Codex Remote9// File             : Packages/ClaudeRemoteKit/Sources/ClaudeRemoteModels/AuthDTO.swift10// Module           : ClaudeRemoteModels11// Repository       : https://git.spboucher.ai/claude-remote-apple12// Project Website  : https://claude.spboucher.ai13// Created          : 2026-11-2914// Last Modified    : 2026-11-2915//16// =============================================================================17// AUTHOR & PROFESSIONAL AFFILIATION18// =============================================================================19//20// Author           : Simon-Pierre Boucher21// Position         : Professor of Finance22// Institution      : Université du Québec en Outaouais (UQO)23// Department       : Département des sciences administratives24// Organization     : SP Boucher25//26// Website          : https://spboucher.ai27// Git              : https://git.spboucher.ai28//29// =============================================================================30// OFFICIAL CONTACT DIRECTORY31// =============================================================================32//33// General          : info@spboucher.ai34// Professional     : contact@spboucher.ai35// Direct           : simon@spboucher.ai36// Research         : research@spboucher.ai37// Development      : dev@spboucher.ai38// Support          : support@spboucher.ai39// Security/Admin   : admin@spboucher.ai40// Notifications    : notifications@spboucher.ai41//42// Preferred Contact: support@spboucher.ai43//44// =============================================================================45// COPYRIGHT & INTELLECTUAL PROPERTY46// =============================================================================47//48// Copyright (c) 202649// Simon-Pierre Boucher50//51// All rights reserved where applicable.52//53// This file is governed by the applicable project license,54// copyright notices, institutional agreements and relevant law.55//56// Unless expressly authorized by the applicable license or57// rights holder, copying, redistribution, sublicensing,58// publication and commercial exploitation are not permitted.59//60// Existing third-party rights and notices remain unaffected.61//62// =============================================================================63// CONFIDENTIALITY & SECURITY64// =============================================================================65//66// Classification   : Public67// Distribution     : Public repository; use is governed by the project license68// Security Contact : admin@spboucher.ai69//70// Access to this source does not independently grant permission71// to redistribute or disclose confidential materials.72//73// Do not embed credentials, private keys, access tokens,74// certificates or confidential personal information.75//76// =============================================================================77// LICENSE & MAINTENANCE78// =============================================================================79//80// License          : None specified (no license file in this repository)81// Maintainer       : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import Foundation8990// MARK: Browser-compatible auth DTOs (dto.ts)9192public struct AuthStatus: Codable, Hashable, Sendable {93    public struct User: Codable, Hashable, Sendable {94        public var id: String95        public var username: String96    }97    public struct Methods: Codable, Hashable, Sendable {98        public var password: Bool99        public var passkeys: Int100        public var totp: Bool101    }102    public var setupRequired: Bool103    /// True only once the second factor is complete.104    public var authenticated: Bool105    public var user: User?106    public var methods: Methods107    /// Browser sessions only; a bearer session needs no CSRF token.108    public var csrfToken: String?109    public var sessionExpiresAt: Date?110    /// Optional: older servers omit it.111    public var branding: Branding?112}113114/// Next step of a sign-in.115public enum LoginNext: OpenStringEnum {116    case done, totp, passkey, enrollSecondFactor117    case unknown(String)118    public static var known: [(LoginNext, String)] {119        [(.done, "done"), (.totp, "totp"), (.passkey, "passkey"), (.enrollSecondFactor, "enroll_second_factor")]120    }121    public var unknownRawValue: String? { if case .unknown(let r) = self { r } else { nil } }122}123124/// Answer of the browser-style auth steps that also work with a bearer (`/auth/totp/enroll/finish`,125/// `/auth/passkey/register/verify`).126public struct LoginStep: Codable, Hashable, Sendable {127    public var ok: Bool128    public var next: LoginNext129    public var retryAfterSec: Double?130    /// Only for a native session that this step just upgraded (first-run enrolment): the rotated,131    /// now full session. Store it; the previous token is dead.132    public var session: NativeSession?133}134135public struct TotpEnrollStart: Codable, Hashable, Sendable {136    public var secret: String137    public var otpauthUrl: String138}139140public enum DeviceKind: OpenStringEnum {141    case passkey, session, native142    case unknown(String)143    public static var known: [(DeviceKind, String)] { [(.passkey, "passkey"), (.session, "session"), (.native, "native")] }144    public var unknownRawValue: String? { if case .unknown(let r) = self { r } else { nil } }145}146147public enum NativePlatform: OpenStringEnum {148    case macos, ios, ipados149    case unknown(String)150    public static var known: [(NativePlatform, String)] { [(.macos, "macos"), (.ios, "ios"), (.ipados, "ipados")] }151    public var unknownRawValue: String? { if case .unknown(let r) = self { r } else { nil } }152}153154/// A passkey, a browser session or a native app session of the account (`GET /auth/devices`).155public struct Device: Codable, Hashable, Sendable, Identifiable {156    public var id: String157    public var kind: DeviceKind158    public var label: String159    public var createdAt: Date160    public var lastUsedAt: Date?161    public var current: Bool162    public var userAgent: String?163    public var ip: String?164    // Additive, `kind == .native` only.165    public var platform: NativePlatform?166    public var model: String?167    public var appVersion: String?168    public var pushEnabled: Bool?169}170171public struct OKResponse: Codable, Hashable, Sendable {172    public var ok: Bool173}174175// MARK: Native sessions (docs/NATIVE-API-CONTRACT.md §2)176177/// Bearer session of a native app. `token` is a secret: never log it, keep it in the Keychain.178public struct NativeSession: Codable, Hashable, Sendable {179    public var id: String180    public var token: String181    public var tokenExpiresAt: Date182    public var expiresAt: Date183    /// False while a second factor is pending ("restricted" session, 15 minutes).184    public var secondFactor: Bool185186    public init(id: String, token: String, tokenExpiresAt: Date, expiresAt: Date, secondFactor: Bool) {187        self.id = id188        self.token = token189        self.tokenExpiresAt = tokenExpiresAt190        self.expiresAt = expiresAt191        self.secondFactor = secondFactor192    }193}194195/// This installation, declared at sign-in. `publicKey` = base64 of the P-256 device public key196/// (X9.63 uncompressed, 65 bytes).197public struct NativeDevice: Codable, Hashable, Sendable {198    public var installId: String199    public var name: String200    public var platform: NativePlatform201    public var model: String202    public var appVersion: String203    public var publicKey: String204205    public init(installId: String, name: String, platform: NativePlatform, model: String, appVersion: String, publicKey: String) {206        self.installId = installId207        self.name = String(name.prefix(80)).isEmpty ? "Apple device" : String(name.prefix(80))208        self.platform = platform209        self.model = String(model.prefix(80))210        self.appVersion = String(appVersion.prefix(40))211        self.publicKey = publicKey212    }213}214215public struct NativeLoginRequest: Codable, Hashable, Sendable {216    public var username: String217    public var password: String218    public var totp: String?219    public var device: NativeDevice220221    public init(username: String, password: String, totp: String? = nil, device: NativeDevice) {222        self.username = username223        self.password = password224        self.totp = totp225        self.device = device226    }227}228229public struct SecondFactorMethods: Codable, Hashable, Sendable {230    public var totp: Bool231    public var passkeys: Int232    public init(totp: Bool, passkeys: Int) {233        self.totp = totp234        self.passkeys = passkeys235    }236}237238/// Answer of `POST /native/auth/login`, `…/totp` and `…/passkey/verify`.239public struct NativeLoginResponse: Codable, Hashable, Sendable {240    public var next: LoginNext241    /// Only sent by `login`.242    public var methods: SecondFactorMethods?243    public var session: NativeSession244}245246public struct NativeRefreshChallenge: Codable, Hashable, Sendable {247    public var challenge: String248    public var expiresAt: Date249}250251public struct NativeRefreshResponse: Codable, Hashable, Sendable {252    public var session: NativeSession253}254255// MARK: WebAuthn JSON (as produced by @simplewebauthn/server)256257public struct PublicKeyCredentialDescriptorJSON: Codable, Hashable, Sendable {258    public var id: String259    public var type: String?260    public var transports: [String]?261}262263/// `PublicKeyCredentialRequestOptionsJSON` (assertion).264public struct PasskeyRequestOptions: Codable, Hashable, Sendable {265    public var challenge: String266    public var rpId: String?267    public var timeout: Double?268    public var allowCredentials: [PublicKeyCredentialDescriptorJSON]?269    public var userVerification: String?270}271272public struct NativePasskeyOptionsResponse: Codable, Hashable, Sendable {273    public var options: PasskeyRequestOptions274    /// Opaque, 5 minutes, single use; `null` for the second-step (bearer) flavour.275    public var challengeToken: String?276}277278/// `PublicKeyCredentialCreationOptionsJSON` (registration).279public struct PasskeyCreationOptions: Codable, Hashable, Sendable {280    public struct RelyingParty: Codable, Hashable, Sendable {281        public var id: String?282        public var name: String283    }284    public struct User: Codable, Hashable, Sendable {285        public var id: String286        public var name: String287        public var displayName: String?288    }289    public var challenge: String290    public var rp: RelyingParty291    public var user: User292    public var timeout: Double?293    public var excludeCredentials: [PublicKeyCredentialDescriptorJSON]?294}295296/// `AuthenticationResponseJSON`: every binary member is base64url without padding.297public struct PasskeyAssertionCredential: Codable, Hashable, Sendable {298    public struct Response: Codable, Hashable, Sendable {299        public var clientDataJSON: String300        public var authenticatorData: String301        public var signature: String302        public var userHandle: String?303        public init(clientDataJSON: String, authenticatorData: String, signature: String, userHandle: String?) {304            self.clientDataJSON = clientDataJSON305            self.authenticatorData = authenticatorData306            self.signature = signature307            self.userHandle = userHandle308        }309    }310    public var id: String311    public var rawId: String312    public var type: String313    public var response: Response314    public var clientExtensionResults: [String: JSONValue]315    public var authenticatorAttachment: String?316317    public init(credentialID: Data, clientDataJSON: Data, authenticatorData: Data, signature: Data, userHandle: Data?,318                authenticatorAttachment: String? = "platform") {319        id = Base64URL.encode(credentialID)320        rawId = id321        type = "public-key"322        response = Response(clientDataJSON: Base64URL.encode(clientDataJSON), authenticatorData: Base64URL.encode(authenticatorData),323                            signature: Base64URL.encode(signature), userHandle: userHandle.map(Base64URL.encode))324        clientExtensionResults = [:]325        self.authenticatorAttachment = authenticatorAttachment326    }327}328329/// `RegistrationResponseJSON`.330public struct PasskeyRegistrationCredential: Codable, Hashable, Sendable {331    public struct Response: Codable, Hashable, Sendable {332        public var clientDataJSON: String333        public var attestationObject: String334        public var transports: [String]?335    }336    public var id: String337    public var rawId: String338    public var type: String339    public var response: Response340    public var clientExtensionResults: [String: JSONValue]341    public var authenticatorAttachment: String?342343    public init(credentialID: Data, clientDataJSON: Data, attestationObject: Data, transports: [String] = ["internal", "hybrid"],344                authenticatorAttachment: String? = "platform") {345        id = Base64URL.encode(credentialID)346        rawId = id347        type = "public-key"348        response = Response(clientDataJSON: Base64URL.encode(clientDataJSON), attestationObject: Base64URL.encode(attestationObject), transports: transports)349        clientExtensionResults = [:]350        self.authenticatorAttachment = authenticatorAttachment351    }352}353354public struct NativePasskeyVerifyRequest: Codable, Hashable, Sendable {355    public var credential: PasskeyAssertionCredential356    public var challengeToken: String?357    public var device: NativeDevice?358    public init(credential: PasskeyAssertionCredential, challengeToken: String? = nil, device: NativeDevice? = nil) {359        self.credential = credential360        self.challengeToken = challengeToken361        self.device = device362    }363}364365// MARK: Push and summary (contract §3, §4)366367public enum APNsEnvironment: String, Codable, Sendable, CaseIterable {368    case sandbox, production369}370371public struct PushRegistration: Codable, Hashable, Sendable {372    /// Hex-encoded APNs device token.373    public var apnsToken: String374    public var environment: APNsEnvironment375    /// Bundle identifier of the running build (one of the instance's app ids).376    public var topic: String377    public init(apnsToken: String, environment: APNsEnvironment, topic: String) {378        self.apnsToken = apnsToken379        self.environment = environment380        self.topic = topic381    }382    public init(deviceToken: Data, environment: APNsEnvironment, topic: String) {383        self.init(apnsToken: deviceToken.map { String(format: "%02x", $0) }.joined(), environment: environment, topic: topic)384    }385}386387public struct PushRegistrationResult: Codable, Hashable, Sendable {388    public var ok: Bool389    /// False when the server has no APNs key: nothing will be pushed.390    public var configured: Bool391}392393/// `GET /native/info`: where the apps are published, push status, device counts.394public struct NativeInfo: Codable, Hashable, Sendable {395    public struct Release: Codable, Hashable, Sendable {396        public var url: String397        public var version: String?398        public var note: String?399    }400    public struct Apps: Codable, Hashable, Sendable {401        public var macos: Release?402        public var ios: Release?403    }404    public struct Push: Codable, Hashable, Sendable {405        /// The server holds an APNs key. False ⇒ nothing is ever pushed.406        public var configured: Bool407        public var registeredDevices: Int408    }409    public var productName: String410    public var bundleId: String411    public var urlScheme: String412    public var apps: Apps413    public var push: Push414    /// Signed-in native devices of this user.415    public var devices: Int416}417418/// `GET /native/summary`: counters for Home, widgets and the menu bar. Never terminal content.419public struct NativeSummary: Codable, Hashable, Sendable {420    public struct Sessions: Codable, Hashable, Sendable {421        public var live: Int422        public var waiting: Int423        public var running: Int424        public var detached: Int425        public var recoverable: Int426        public init(live: Int, waiting: Int, running: Int, detached: Int, recoverable: Int) {427            self.live = live; self.waiting = waiting; self.running = running; self.detached = detached; self.recoverable = recoverable428        }429    }430    public struct Tasks: Codable, Hashable, Sendable {431        public var running: Int432        public var queued: Int433        public var failed24h: Int434        public var succeeded24h: Int435        public init(running: Int, queued: Int, failed24h: Int, succeeded24h: Int) {436            self.running = running; self.queued = queued; self.failed24h = failed24h; self.succeeded24h = succeeded24h437        }438    }439    public struct Cluster: Codable, Hashable, Sendable {440        public var nodes: Int441        public var online: Int442        public var health: Health443        public var collectedAt: Date?444        public init(nodes: Int, online: Int, health: Health, collectedAt: Date?) {445            self.nodes = nodes; self.online = online; self.health = health; self.collectedAt = collectedAt446        }447    }448    public var serverTime: Date449    public var agent: AgentID450    public var productName: String451    public var sessions: Sessions452    public var tasks: Tasks453    public var cluster: Cluster?454    public var notificationsUnread: Int455456    public init(serverTime: Date, agent: AgentID, productName: String, sessions: Sessions, tasks: Tasks, cluster: Cluster?, notificationsUnread: Int) {457        self.serverTime = serverTime; self.agent = agent; self.productName = productName458        self.sessions = sessions; self.tasks = tasks; self.cluster = cluster; self.notificationsUnread = notificationsUnread459    }460}461
Files main
Menu

Theme