Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
63 changes: 51 additions & 12 deletions Sources/OAuthKit/OAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -234,19 +254,33 @@ 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 {
#if os(macOS)
.deviceOwnerAuthenticationWithBiometricsOrWatch
#else
.deviceOwnerAuthenticationWithBiometrics
#endif
}
#else
let policy: LAPolicy = .deviceOwnerAuthenticationWithBiometrics
#endif
var error: NSError?
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
Expand Down Expand Up @@ -308,9 +342,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)
}
}
}
Expand Down