From 940ce45ebf9085c6304fd792a726daf0853120eb Mon Sep 17 00:00:00 2001 From: Vladimir Leonidovich Date: Thu, 1 Jan 2026 10:56:00 +0500 Subject: [PATCH 1/2] allow older versions of operating systems --- Package.swift | 10 +++--- Sources/OAuthKit/OAuth.swift | 59 ++++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/Package.swift b/Package.swift index fc4f96c..7e4c119 100644 --- a/Package.swift +++ b/Package.swift @@ -6,11 +6,11 @@ import PackageDescription let package = Package( name: "OAuthKit", platforms: [ - .iOS(.v26), - .macOS(.v26), - .tvOS(.v26), - .visionOS(.v26), - .watchOS(.v26) + .iOS(.v17), + .macOS(.v14), + .tvOS(.v17), + .visionOS(.v1), + .watchOS(.v10) ], products: [ .library( diff --git a/Sources/OAuthKit/OAuth.swift b/Sources/OAuthKit/OAuth.swift index 6fd3339..6b09b7b 100644 --- a/Sources/OAuthKit/OAuth.swift +++ b/Sources/OAuthKit/OAuth.swift @@ -117,16 +117,31 @@ public extension OAuth { state = .authorizing(provider, grantType) case .deviceCode: state = .requestingDeviceCode(provider) - Task.immediate { - await requestDeviceCode(provider: provider) + let operation = { @Sendable in + await self.requestDeviceCode(provider: provider) + } + if #available(macOS 26, iOS 26, watchOS 26, tvOS 26, visionOS 26, *) { + Task.immediate(operation: operation) + } else { + Task(priority: .high, operation: operation) } case .clientCredentials: - Task.immediate { - await requestClientCredentials(provider: provider) + let operation = { @Sendable in + await self.requestClientCredentials(provider: provider) + } + if #available(macOS 26, iOS 26, watchOS 26, tvOS 26, visionOS 26, *) { + Task.immediate(operation: operation) + } else { + Task(priority: .high, operation: operation) } case .refreshToken: - Task.immediate { - await refreshToken(provider: provider) + let operation = { @Sendable in + await self.refreshToken(provider: provider) + } + if #available(macOS 26, iOS 26, watchOS 26, tvOS 26, visionOS 26, *) { + Task.immediate(operation: operation) + } else { + Task(priority: .high, operation: operation) } } } @@ -138,8 +153,13 @@ public extension OAuth { /// - code: the code to exchange /// - pkce: the pkce data func token(provider: Provider, code: String, pkce: PKCE? = nil) { - Task.immediate { - await requestToken(provider: provider, code: code, pkce: pkce) + let operation = { @Sendable in + await self.requestToken(provider: provider, code: code, pkce: pkce) + } + if #available(macOS 26, iOS 26, watchOS 26, tvOS 26, visionOS 26, *) { + Task.immediate(operation: operation) + } else { + Task(priority: .high, operation: operation) } } @@ -234,7 +254,12 @@ private extension OAuth { #if os(macOS) || os(iOS) || os(visionOS) let localizedReason = context.localizedReason.isNotEmpty ? context.localizedReason: defaultAuthenticationWithBiometricsOrCompanionReason #if os(macOS) || os(iOS) - let policy: LAPolicy = .deviceOwnerAuthenticationWithBiometricsOrCompanion + let policy: LAPolicy = + if #available(iOS 18, macOS 15, *) { + .deviceOwnerAuthenticationWithBiometricsOrCompanion + } else { + .deviceOwnerAuthenticationWithBiometricsOrWatch + } #else let policy: LAPolicy = .deviceOwnerAuthenticationWithBiometrics #endif @@ -242,11 +267,16 @@ private extension OAuth { if context.canEvaluatePolicy(policy, error: &error) { context.evaluatePolicy(policy, localizedReason: localizedReason) { [weak self] success, error in guard let self else { return } - Task.immediate { @MainActor in + let operation = { @MainActor in if success { self.loadAuthorizations() } } + if #available(macOS 26, iOS 26, watchOS 26, tvOS 26, visionOS 26, *) { + Task.immediate(operation: operation) + } else { + Task(priority: .high, operation: operation) + } } } #else @@ -308,9 +338,14 @@ private extension OAuth { } tasks.append(task) } else { + let operation = { @Sendable in + await self.refreshToken(provider: provider) + } // Execute the task immediately - Task.immediate { - await refreshToken(provider: provider) + if #available(macOS 26, iOS 26, watchOS 26, tvOS 26, visionOS 26, *) { + Task.immediate(operation: operation) + } else { + Task(priority: .high, operation: operation) } } } From 97a28ce2ca6786178cb9307ac06cbb166203e037 Mon Sep 17 00:00:00 2001 From: Vladimir Leonidovich Date: Thu, 1 Jan 2026 11:32:26 +0500 Subject: [PATCH 2/2] fix: fix "`.deviceOwnerAuthenticationWithBiometricsOrWatch` is unavailable in iOS" --- Sources/OAuthKit/OAuth.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/OAuthKit/OAuth.swift b/Sources/OAuthKit/OAuth.swift index 6b09b7b..95d31f6 100644 --- a/Sources/OAuthKit/OAuth.swift +++ b/Sources/OAuthKit/OAuth.swift @@ -258,7 +258,11 @@ private extension OAuth { if #available(iOS 18, macOS 15, *) { .deviceOwnerAuthenticationWithBiometricsOrCompanion } else { + #if os(macOS) .deviceOwnerAuthenticationWithBiometricsOrWatch + #else + .deviceOwnerAuthenticationWithBiometrics + #endif } #else let policy: LAPolicy = .deviceOwnerAuthenticationWithBiometrics