diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d6270e5..777616b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,14 +14,11 @@ jobs: strategy: fail-fast: false matrix: - swift: ['swift6', 'swift5'] + swift: ['swift6.2'] include: - - swift: 'swift6' - xcode-path: '/Applications/Xcode_16.2.app' - macos: 'macos-14' - - swift: 'swift5' - xcode-path: '/Applications/Xcode_15.4.app' - macos: 'macos-14' + - swift: 'swift6.2' + xcode-path: '/Applications/Xcode_26.2.app' + macos: 'macos-26' env: DEVELOPER_DIR: ${{ matrix.xcode-path }} @@ -30,7 +27,7 @@ jobs: steps: - name: checkout - uses: actions/checkout@v4 + uses: actions/checkout@v7.0.1 with: submodules: true @@ -47,7 +44,7 @@ jobs: swift test --parallel --xunit-output 'reports/TestReport.xml' - name: report unit test results - uses: dorny/test-reporter@eaa763f6ffc21c7a37837f56cd5f9737f27fc6c8 + uses: dorny/test-reporter@a43b3a5f7366b97d083190328d2c652e1a8b6aa2 if: always() id: results-swift-tests with: @@ -78,25 +75,28 @@ jobs: strategy: fail-fast: false matrix: - macos: [ 'macos-14' ] + macos: [ 'macos-26' ] platform: [ 'macOS', 'iOS', 'tvOS' ] include: - platform: 'macOS' scheme: 'OAuth2macOS' + destination: 'platform=macOS' - platform: 'iOS' scheme: 'OAuth2iOS' + destination: 'generic/platform=iOS Simulator' - platform: 'tvOS' scheme: 'OAuth2tvOS' + destination: 'generic/platform=tvOS Simulator' env: - DEVELOPER_DIR: '/Applications/Xcode_15.4.0.app' + DEVELOPER_DIR: '/Applications/Xcode_26.2.app' TEST_RESULTS_PATH: 'OAuth2Tests_${{ matrix.platform }}_run${{ github.run_number }}.xcresult' runs-on: ${{ matrix.macos }} steps: - name: checkout - uses: actions/checkout@v4 + uses: actions/checkout@v7.0.1 with: submodules: true @@ -111,25 +111,25 @@ jobs: xcodebuild -scheme '${{ matrix.scheme }}' -configuration Debug - -destination 'platform=${{ matrix.platform }}' + -destination '${{ matrix.destination }}' -showBuildTimingSummary build - name: test - if: success() + if: success() && matrix.platform == 'macOS' continue-on-error: true run: > xcodebuild -scheme '${{ matrix.scheme }}' -configuration Debug - -destination 'platform=${{ matrix.platform }}' + -destination '${{ matrix.destination }}' -resultBundlePath ${{ env.TEST_RESULTS_PATH }} test - name: run xcresulttool - uses: slidoapp/xcresulttool@v2.0.0 - if: always() + uses: slidoapp/xcresulttool@v3.1.2 + if: always() && matrix.platform == 'macOS' with: title: 'results-xcode-tests-${{ matrix.platform }}' path: ${{ env.TEST_RESULTS_PATH }} - upload-bundles: true + upload-bundles: always diff --git a/.swift-version b/.swift-version index d2ff458..bee9433 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -5.5.3 \ No newline at end of file +6.2.3 diff --git a/Package.swift b/Package.swift index 8fee14b..2792b30 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.5 +// swift-tools-version:6.2 // // Package.swift // OAuth2 @@ -49,5 +49,6 @@ let package = Package( .testTarget(name: "BaseTests", dependencies: [.target(name: "TestUtils"), .target(name: "Base"), .target(name: "Flows")]), .testTarget(name: "FlowTests", dependencies: [.target(name: "TestUtils"), .target(name: "Flows")]), // .testTarget(name: "DataLoaderTests", dependencies: [.target(name: "DataLoader")]), - ] + ], + swiftLanguageModes: [.v5] ) diff --git a/README.md b/README.md index 63af889..e7606f1 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,13 @@ OAuth2 frameworks for **macOS**, **iOS** and **tvOS** written in Swift 5. - [🖥 Sample macOS app][sample] (with data loader examples) - [📖 Technical Documentation](https://p2.github.io/OAuth2) -OAuth2 requires Xcode 12.4, the built framework can be used on **OS X 10.15**, **iOS 13**, **tvOS 13**, **watchOS 6** and later. +OAuth2 requires Xcode 26 or a Swift 6.2 toolchain. The built framework can be used on **OS X 10.15**, **iOS 13**, **tvOS 13**, **watchOS 6** and later. Happy to accept pull requests, please see [CONTRIBUTING.md](./Docs/CONTRIBUTING.md) ### Swift Version +Swift Package Manager builds require Swift 6.2 or later and use Swift 5 language mode. + Since the Swift language is constantly evolving I have adopted a versioning scheme mirroring Swift versions: the framework version's **first two digits are always the Swift version** the library is compatible with, see [releases](https://github.com/p2/OAuth2/releases). Code compatible with brand new Swift versions are to be found on a separate feature branch named appropriately. diff --git a/Sources/DataLoader/OAuth2DataLoaderSessionTaskDelegate.swift b/Sources/DataLoader/OAuth2DataLoaderSessionTaskDelegate.swift index 5b1cd48..da4402a 100644 --- a/Sources/DataLoader/OAuth2DataLoaderSessionTaskDelegate.swift +++ b/Sources/DataLoader/OAuth2DataLoaderSessionTaskDelegate.swift @@ -52,24 +52,25 @@ final class OAuth2DataLoaderSessionTaskDelegate: NSObject, URLSessionTaskDelegat // MARK: - URLSessionTaskDelegate - func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping (URLRequest?) -> Void) { - guard request.url?.host == host else { - loader?.logger?.warning("Redirected to «\(request.url?.host ?? "nil")» but only approving HTTP redirection on «\(host)», not following redirect: \(request)") - completionHandler(nil) - return - } - do { - guard let loader = loader else { - throw OAuth2Error.generic("no loader instance, cannot re-sign") + nonisolated func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping @Sendable (URLRequest?) -> Void) { + Task { @OAuth2Actor in + guard request.url?.host == host else { + loader?.logger?.warning("Redirected to «\(request.url?.host ?? "nil")» but only approving HTTP redirection on «\(host)», not following redirect: \(request)") + completionHandler(nil) + return + } + do { + guard let loader = loader else { + throw OAuth2Error.generic("no loader instance, cannot re-sign") + } + let newRequest = try request.signed(with: loader.oauth2) + loader.logger?.debug("Following HTTP redirection to «\(request.url?.description ?? "nil")»") + completionHandler(newRequest) + } + catch { + loader?.logger?.warning("Failed to re-sign request after HTTP redirection: \(error)") + completionHandler(request) } - let newRequest = try request.signed(with: loader.oauth2) - loader.logger?.debug("Following HTTP redirection to «\(request.url?.description ?? "nil")»") - completionHandler(newRequest) - } - catch { - loader?.logger?.warning("Failed to re-sign request after HTTP redirection: \(error)") - completionHandler(request) } } } - diff --git a/Sources/iOS/OAuth2Authorizer+iOS.swift b/Sources/iOS/OAuth2Authorizer+iOS.swift index 476bbb2..34e45ed 100644 --- a/Sources/iOS/OAuth2Authorizer+iOS.swift +++ b/Sources/iOS/OAuth2Authorizer+iOS.swift @@ -180,7 +180,9 @@ open class OAuth2Authorizer: OAuth2AuthorizerUI { authenticationSession = ASWebAuthenticationSession(url: url, callbackURLScheme: redirectURL.scheme, completionHandler: completionHandler) if #available(iOS 13.0, macCatalyst 13.1, *) { - webAuthenticationPresentationContextProvider = OAuth2ASWebAuthenticationPresentationContextProvider(authorizer: self) + webAuthenticationPresentationContextProvider = OAuth2ASWebAuthenticationPresentationContextProvider( + authorizeContext: oauth2.authConfig.authorizeContext + ) if let session = authenticationSession as? ASWebAuthenticationSession { session.presentationContextProvider = webAuthenticationPresentationContextProvider as! OAuth2ASWebAuthenticationPresentationContextProvider session.prefersEphemeralWebBrowserSession = prefersEphemeralWebBrowserSession @@ -283,26 +285,25 @@ class OAuth2SFViewControllerDelegate: NSObject, SFSafariViewControllerDelegate, #endif @available(iOS 13.0, *) -@OAuth2Actor +@MainActor class OAuth2ASWebAuthenticationPresentationContextProvider: NSObject, ASWebAuthenticationPresentationContextProviding { - private let authorizer: OAuth2Authorizer + nonisolated(unsafe) private weak var authorizeContext: AnyObject? - init(authorizer: OAuth2Authorizer) { - self.authorizer = authorizer + nonisolated init(authorizeContext: AnyObject?) { + self.authorizeContext = authorizeContext } - @OAuth2Actor public func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor { - if let context = authorizer.oauth2.authConfig.authorizeContext as? ASPresentationAnchor { + if let context = authorizeContext as? ASPresentationAnchor { return context } - if let context = authorizer.oauth2.authConfig.authorizeContext as? UIViewController { + if let context = authorizeContext as? UIViewController { return context.view.window! } - fatalError("Invalid authConfig.authorizeContext, must be an ASPresentationAnchor or UIViewController but is \(type(of: authorizer.oauth2.authConfig.authorizeContext))") + fatalError("Invalid authConfig.authorizeContext, must be an ASPresentationAnchor or UIViewController but is \(type(of: authorizeContext))") } } diff --git a/Sources/macOS/OAuth2Authorizer+macOS.swift b/Sources/macOS/OAuth2Authorizer+macOS.swift index 9a394a8..785785b 100644 --- a/Sources/macOS/OAuth2Authorizer+macOS.swift +++ b/Sources/macOS/OAuth2Authorizer+macOS.swift @@ -158,7 +158,9 @@ open class OAuth2Authorizer: OAuth2AuthorizerUI { authenticationSession = ASWebAuthenticationSession(url: url, callbackURLScheme: redirectURL.scheme, completionHandler: completionHandler) - webAuthenticationPresentationContextProvider = await OAuth2ASWebAuthenticationPresentationContextProvider(authorizer: self) + webAuthenticationPresentationContextProvider = OAuth2ASWebAuthenticationPresentationContextProvider( + authorizeContext: oauth2.authConfig.authorizeContext + ) if let session = authenticationSession as? ASWebAuthenticationSession { session.presentationContextProvider = webAuthenticationPresentationContextProvider as! OAuth2ASWebAuthenticationPresentationContextProvider session.prefersEphemeralWebBrowserSession = prefersEphemeralWebBrowserSession @@ -269,20 +271,20 @@ open class OAuth2Authorizer: OAuth2AuthorizerUI { #if canImport(AuthenticationServices) @available(macOS 10.15, *) +@MainActor class OAuth2ASWebAuthenticationPresentationContextProvider: NSObject, ASWebAuthenticationPresentationContextProviding { - private let authorizer: OAuth2Authorizer + nonisolated(unsafe) private weak var authorizeContext: AnyObject? - init(authorizer: OAuth2Authorizer) { - self.authorizer = authorizer + nonisolated init(authorizeContext: AnyObject?) { + self.authorizeContext = authorizeContext } - @OAuth2Actor /// For Xcode 15, we need to specify the `@OAuth2Actor` explicitly, but in Xcode 16 this is no longer necessary. 🤷‍♂️ public func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor { - if let context = authorizer.oauth2.authConfig.authorizeContext as? ASPresentationAnchor { + if let context = authorizeContext as? ASPresentationAnchor { return context } - fatalError("Invalid authConfig.authorizeContext, must be an ASPresentationAnchor but is \(type(of: authorizer.oauth2.authConfig.authorizeContext))") + fatalError("Invalid authConfig.authorizeContext, must be an ASPresentationAnchor but is \(type(of: authorizeContext))") } } #endif diff --git a/Tests/FlowTests/OAuth2DeviceGrantTests.swift b/Tests/FlowTests/OAuth2DeviceGrantTests.swift index d1e58cd..4283bfb 100644 --- a/Tests/FlowTests/OAuth2DeviceGrantTests.swift +++ b/Tests/FlowTests/OAuth2DeviceGrantTests.swift @@ -101,7 +101,7 @@ class OAuth2DeviceGrantTests: XCTestCase { "expires_in": 3600, "refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA", "foo": "bar & hat" - ] as [String: Any] + ] as OAuth2JSON // must throw when "token_type" is missing do { @@ -146,7 +146,7 @@ class OAuth2DeviceGrantTests: XCTestCase { "expires_in": 3600, "refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA", "foo": "bar & hat" - ] as [String : Any] + ] as OAuth2JSON do { _ = try oauth.parseAccessTokenResponse(params: response2) diff --git a/Tests/FlowTests/OAuth2PasswordGrantTests.swift b/Tests/FlowTests/OAuth2PasswordGrantTests.swift index fb9c05b..2bb9507 100644 --- a/Tests/FlowTests/OAuth2PasswordGrantTests.swift +++ b/Tests/FlowTests/OAuth2PasswordGrantTests.swift @@ -82,7 +82,7 @@ class OAuth2PasswordGrantTests: XCTestCase { "expires_in": 3600, "refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA", "foo": "bar" - ] as [String: Any] + ] as OAuth2JSON do { let dict = try oauth.parseAccessTokenResponse(params: response) XCTAssertEqual("bar", dict["foo"] as? String) @@ -114,4 +114,3 @@ class OAuth2PasswordGrantTests: XCTestCase { XCTAssertTrue(body!.contains("foo=bar+%26+hat"), "Must create correct request body") } } -