Skip to content
Draft
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
49 changes: 36 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-15'

env:
DEVELOPER_DIR: ${{ matrix.xcode-path }}
Expand Down Expand Up @@ -78,7 +75,7 @@ jobs:
strategy:
fail-fast: false
matrix:
macos: [ 'macos-14' ]
macos: [ 'macos-15' ]
platform: [ 'macOS', 'iOS', 'tvOS' ]
include:
- platform: 'macOS'
Expand All @@ -89,7 +86,7 @@ jobs:
scheme: 'OAuth2tvOS'

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 }}
Expand All @@ -106,12 +103,38 @@ jobs:
- name: swift version
run: swift --version

- name: select destination
id: destination
run: |
if [[ '${{ matrix.platform }}' == 'macOS' ]]; then
echo 'value=platform=macOS' >> "$GITHUB_OUTPUT"
exit 0
fi

simulator_id="$(
xcrun simctl list devices available --json |
jq -r --arg platform '${{ matrix.platform }}' '
[.devices
| to_entries[]
| select(.key | contains("SimRuntime.\($platform)-"))
| .value[]
| .udid][0] // empty
'
)"

if [[ -z "$simulator_id" ]]; then
echo 'No available ${{ matrix.platform }} simulator found.' >&2
exit 1
fi

echo "value=platform=${{ matrix.platform }} Simulator,id=$simulator_id" >> "$GITHUB_OUTPUT"

- name: build
run: >
xcodebuild
-scheme '${{ matrix.scheme }}'
-configuration Debug
-destination 'platform=${{ matrix.platform }}'
-destination '${{ steps.destination.outputs.value }}'
-showBuildTimingSummary
build

Expand All @@ -122,13 +145,13 @@ jobs:
xcodebuild
-scheme '${{ matrix.scheme }}'
-configuration Debug
-destination 'platform=${{ matrix.platform }}'
-destination '${{ steps.destination.outputs.value }}'
-resultBundlePath ${{ env.TEST_RESULTS_PATH }}
test

- name: run xcresulttool
uses: slidoapp/xcresulttool@v2.0.0
if: always()
uses: slidoapp/xcresulttool@v3.1.1
if: ${{ always() && steps.test.outcome != 'skipped' }}
with:
title: 'results-xcode-tests-${{ matrix.platform }}'
path: ${{ env.TEST_RESULTS_PATH }}
Expand Down
4 changes: 2 additions & 2 deletions OAuth2.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 13.0;
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -1065,7 +1065,7 @@
METAL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 13.0;
VALIDATE_PRODUCT = YES;
Expand Down
52 changes: 30 additions & 22 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.5
// swift-tools-version:6.2
//
// Package.swift
// OAuth2
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ OAuth2
[![Build Status](https://travis-ci.org/p2/OAuth2.svg?branch=main)](https://travis-ci.org/p2/OAuth2)
[![License](https://img.shields.io/:license-apache-blue.svg)](LICENSE.txt)

OAuth2 frameworks for **macOS**, **iOS** and **tvOS** written in Swift 5.
OAuth2 frameworks for **macOS**, **iOS** and **tvOS** written in Swift 6.2.

- [⤵️ Installation](#installation)
- [🛠 Usage](#usage)
- [🖥 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, 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
Expand Down
48 changes: 25 additions & 23 deletions Sources/DataLoader/OAuth2DataLoaderSessionTaskDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ import Base
Simple implementation of a session task delegate, which looks at HTTP redirecting, approving redirects in the same domain and re-signing the
redirected request.
*/
@OAuth2Actor
final class OAuth2DataLoaderSessionTaskDelegate: NSObject, URLSessionTaskDelegate {
final class OAuth2DataLoaderSessionTaskDelegate: NSObject, URLSessionTaskDelegate, @unchecked Sendable {

/// The loader to which the delegate belongs, needed for request signing.
public internal(set) weak var loader: OAuth2DataLoader?
private let redirectHandler: @OAuth2Actor @Sendable (URLRequest) -> URLRequest?

/// Only redirects against this host will be approved.
public let host: String
Expand All @@ -44,32 +42,36 @@ final class OAuth2DataLoaderSessionTaskDelegate: NSObject, URLSessionTaskDelegat
- parameter loader: The data loader for which the receiver is delegating
- parameter host: The host on which HTTP redirecting will be approved; will be run through `URLComponents` to satisfy formatting
*/
@OAuth2Actor
public init(loader: OAuth2DataLoader, host: String) {
self.loader = loader
self.host = URLComponents(string: host)?.host ?? host
let normalizedHost = URLComponents(string: host)?.host ?? host
self.host = normalizedHost
redirectHandler = { [weak loader] request in
guard request.url?.host == normalizedHost else {
loader?.logger?.warning("Redirected to «\(request.url?.host ?? "nil")» but only approving HTTP redirection on «\(normalizedHost)», not following redirect: \(request)")
return nil
}
do {
guard let 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")»")
return newRequest
} catch {
loader?.logger?.warning("Failed to re-sign request after HTTP redirection: \(error)")
return request
}
}
}


// 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")
}
let newRequest = try request.signed(with: loader.oauth2)
loader.logger?.debug("Following HTTP redirection to «\(request.url?.description ?? "nil")»")
func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping @Sendable (URLRequest?) -> Void) {
Task {
let newRequest = await redirectHandler(request)
completionHandler(newRequest)
}
catch {
loader?.logger?.warning("Failed to re-sign request after HTTP redirection: \(error)")
completionHandler(request)
}
}
}

Loading
Loading