Skip to content

Commit

Permalink
Swift 6 Upgrade (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
codefiesta authored Oct 3, 2024
1 parent 874b70b commit 64e5d1d
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.10
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![Build](https://github.com/codefiesta/OAuthKit/actions/workflows/swift.yml/badge.svg)
![Xcode 16.0+](https://img.shields.io/badge/Xcode-16.0%2B-gold.svg)
![Swift 5.10+](https://img.shields.io/badge/Swift-5.10%2B-tomato.svg)
![Swift 6.0+](https://img.shields.io/badge/Swift-6.0%2B-tomato.svg)
![iOS 17.0+](https://img.shields.io/badge/iOS-17.0%2B-crimson.svg)
![macOS 15.0+](https://img.shields.io/badge/macOS-15.0%2B-skyblue.svg)
![visionOS 1.0+](https://img.shields.io/badge/visionOS-1.0%2B-magenta.svg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ public extension EnvironmentValues {
struct OAuthKey: EnvironmentKey {

/// The default OAuth instance that is loaded into the environment.
static var defaultValue: OAuth = .init(.main)
static let defaultValue: OAuth = .init(.main)
}
2 changes: 1 addition & 1 deletion Sources/OAuthKit/Keychain/Keychain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private let defaultApplicationTag = "oauthkit"
private let tokenIdentifier = "oauth-token"

/// A helper class used to interact with Keychain access.
class Keychain {
class Keychain: @unchecked Sendable {

static let `default`: Keychain = Keychain()
private let lock = NSLock()
Expand Down
2 changes: 1 addition & 1 deletion Sources/OAuthKit/Network/NetworkMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Network
private let queueLabel = "oauthkit.NetworkMonitor"

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

/// The private pass through publisher.
private var publisher = PassthroughSubject<Bool, Never>()
Expand Down
6 changes: 3 additions & 3 deletions Sources/OAuthKit/OAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum OAError: Error {

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

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

let accessToken: String
let refreshToken: String?
Expand Down Expand Up @@ -163,7 +163,7 @@ public class OAuth: NSObject, ObservableObject {
}

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

/// The state is empty and no authorizations or tokens have been issued.
case empty
Expand Down
1 change: 1 addition & 0 deletions Sources/OAuthKit/Views/OAWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import WebKit

/// A UIViewRepresentable / NSViewRepresentable wrapper type that coordinates
/// oauth authorization flows inside a WKWebView.
@MainActor
public struct OAWebView {

@EnvironmentObject
Expand Down
34 changes: 19 additions & 15 deletions Sources/OAuthKit/Views/OAWebViewCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import Combine
import SwiftUI
import WebKit

public class OAWebViewCoordinator: NSObject, WKNavigationDelegate {
@MainActor
public class OAWebViewCoordinator: NSObject {

var webView: OAWebView

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

public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
guard let url = navigationAction.request.url else {
decisionHandler(.cancel)
return
}
switch oauth.state {
case .empty, .requestingAccessToken, .authorized:
break
case .authorizing(let provider):
handle(url: url, provider: provider)
}
decisionHandler(.allow)
}

/// Handles the authorization url for the specified provider.
/// - Parameters:
/// - url: the url to handle
Expand Down Expand Up @@ -74,4 +61,21 @@ public class OAWebViewCoordinator: NSObject, WKNavigationDelegate {
}
}
}

extension OAWebViewCoordinator: WKNavigationDelegate {

public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction) async -> WKNavigationActionPolicy {
guard let url = navigationAction.request.url else {
return .cancel
}
switch oauth.state {
case .empty, .requestingAccessToken, .authorized:
break
case .authorizing(let provider):
handle(url: url, provider: provider)
}
return .allow
}
}

#endif

0 comments on commit 64e5d1d

Please sign in to comment.