Skip to content

Commit 64e5d1d

Browse files
authored
Swift 6 Upgrade (#19)
1 parent 874b70b commit 64e5d1d

File tree

8 files changed

+28
-23
lines changed

8 files changed

+28
-23
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.10
1+
// swift-tools-version: 6.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![Build](https://github.com/codefiesta/OAuthKit/actions/workflows/swift.yml/badge.svg)
22
![Xcode 16.0+](https://img.shields.io/badge/Xcode-16.0%2B-gold.svg)
3-
![Swift 5.10+](https://img.shields.io/badge/Swift-5.10%2B-tomato.svg)
3+
![Swift 6.0+](https://img.shields.io/badge/Swift-6.0%2B-tomato.svg)
44
![iOS 17.0+](https://img.shields.io/badge/iOS-17.0%2B-crimson.svg)
55
![macOS 15.0+](https://img.shields.io/badge/macOS-15.0%2B-skyblue.svg)
66
![visionOS 1.0+](https://img.shields.io/badge/visionOS-1.0%2B-magenta.svg)

Sources/OAuthKit/Extensions/EnvironmentValues+Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ public extension EnvironmentValues {
1919
struct OAuthKey: EnvironmentKey {
2020

2121
/// The default OAuth instance that is loaded into the environment.
22-
static var defaultValue: OAuth = .init(.main)
22+
static let defaultValue: OAuth = .init(.main)
2323
}

Sources/OAuthKit/Keychain/Keychain.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ private let defaultApplicationTag = "oauthkit"
1414
private let tokenIdentifier = "oauth-token"
1515

1616
/// A helper class used to interact with Keychain access.
17-
class Keychain {
17+
class Keychain: @unchecked Sendable {
1818

1919
static let `default`: Keychain = Keychain()
2020
private let lock = NSLock()

Sources/OAuthKit/Network/NetworkMonitor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Network
1111
private let queueLabel = "oauthkit.NetworkMonitor"
1212

1313
/// A type that broadcasts network reachability via Combine event publishing.
14-
final class NetworkMonitor {
14+
final class NetworkMonitor: @unchecked Sendable {
1515

1616
/// The private pass through publisher.
1717
private var publisher = PassthroughSubject<Bool, Never>()

Sources/OAuthKit/OAuth.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public enum OAError: Error {
2424

2525
/// Provides an observable OAuth 2.0 implementation.
2626
/// See: https://datatracker.ietf.org/doc/html/rfc6749
27-
public class OAuth: NSObject, ObservableObject {
27+
public class OAuth: NSObject, ObservableObject, @unchecked Sendable {
2828

2929
/// Keys and values used to specify loading or runtime options.
3030
public struct Option: Hashable, Equatable, RawRepresentable, @unchecked Sendable {
@@ -111,7 +111,7 @@ public class OAuth: NSObject, ObservableObject {
111111
/// A codable type that holds oauth token information.
112112
/// See: https://www.oauth.com/oauth2-servers/access-tokens/access-token-response/
113113
/// See: https://datatracker.ietf.org/doc/html/rfc6749#section-5.1
114-
public struct Token: Codable, Equatable {
114+
public struct Token: Codable, Equatable, @unchecked Sendable {
115115

116116
let accessToken: String
117117
let refreshToken: String?
@@ -163,7 +163,7 @@ public class OAuth: NSObject, ObservableObject {
163163
}
164164

165165
/// Holds the OAuth state that is published to subscribers via the `state` property publisher.
166-
public enum State: Equatable {
166+
public enum State: Equatable, @unchecked Sendable {
167167

168168
/// The state is empty and no authorizations or tokens have been issued.
169169
case empty

Sources/OAuthKit/Views/OAWebView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import WebKit
1111

1212
/// A UIViewRepresentable / NSViewRepresentable wrapper type that coordinates
1313
/// oauth authorization flows inside a WKWebView.
14+
@MainActor
1415
public struct OAWebView {
1516

1617
@EnvironmentObject

Sources/OAuthKit/Views/OAWebViewCoordinator.swift

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import Combine
1010
import SwiftUI
1111
import WebKit
1212

13-
public class OAWebViewCoordinator: NSObject, WKNavigationDelegate {
13+
@MainActor
14+
public class OAWebViewCoordinator: NSObject {
1415

1516
var webView: OAWebView
1617

@@ -26,20 +27,6 @@ public class OAWebViewCoordinator: NSObject, WKNavigationDelegate {
2627
super.init()
2728
}
2829

29-
public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
30-
guard let url = navigationAction.request.url else {
31-
decisionHandler(.cancel)
32-
return
33-
}
34-
switch oauth.state {
35-
case .empty, .requestingAccessToken, .authorized:
36-
break
37-
case .authorizing(let provider):
38-
handle(url: url, provider: provider)
39-
}
40-
decisionHandler(.allow)
41-
}
42-
4330
/// Handles the authorization url for the specified provider.
4431
/// - Parameters:
4532
/// - url: the url to handle
@@ -74,4 +61,21 @@ public class OAWebViewCoordinator: NSObject, WKNavigationDelegate {
7461
}
7562
}
7663
}
64+
65+
extension OAWebViewCoordinator: WKNavigationDelegate {
66+
67+
public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction) async -> WKNavigationActionPolicy {
68+
guard let url = navigationAction.request.url else {
69+
return .cancel
70+
}
71+
switch oauth.state {
72+
case .empty, .requestingAccessToken, .authorized:
73+
break
74+
case .authorizing(let provider):
75+
handle(url: url, provider: provider)
76+
}
77+
return .allow
78+
}
79+
}
80+
7781
#endif

0 commit comments

Comments
 (0)