Skip to content

Commit e81b4bc

Browse files
djbep2
authored andcommitted
Swift 4.2 support (p2#273)
* Upgrade codebase to support Swift 4.2 * Fix broken tests (order of query parameters is not guaranteed) * Changelog entries for previous PRs and releases
1 parent 26e6c2b commit e81b4bc

12 files changed

+113
-17
lines changed

.swift-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0
1+
4.2

CHANGELOG.md

+65
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,71 @@ Changelog
44
Version numbering represents the Swift version, plus a running number representing updates, fixes and new features at the same time.
55
You can also refer to commit logs to get details on what was implemented, fixed and improved.
66

7+
### Master
8+
9+
- Swift 4.2 support.
10+
[djbe](https://github.com/djbe)
11+
[#273](https://github.com/p2/OAuth2/pull/273)
12+
- Fix crash due to memory ownership.
13+
[foldericon](https://github.com/foldericon)
14+
[#271](https://github.com/p2/OAuth2/pull/271)
15+
- Added an Auth2 implicit grant variation for requests that return parameters in the query instead of the fragment.
16+
[tschmitz](https://github.com/tschmitz)
17+
[#262](https://github.com/p2/OAuth2/pull/262)
18+
- Fix some Swift 4 warnings.
19+
[everlof](https://github.com/everlof)
20+
[#251](https://github.com/p2/OAuth2/pull/251)
21+
- Pass back a strongly typed `OAuth2Error` when possible (along with `error_description`). Also added an `invalidGrant` error.
22+
[sebskuse](https://github.com/sebskuse)
23+
[#248](https://github.com/p2/OAuth2/pull/248)
24+
- You can now implement your own custom loggers.
25+
[p2](https://github.com/p2)
26+
[#236](https://github.com/p2/OAuth2/pull/236)
27+
- Fixed parsing errors with empty descriptions.
28+
[p2](https://github.com/p2)
29+
[#247](https://github.com/p2/OAuth2/pull/247)
30+
- Fix the appearance and location of the `Cancel` button on macOS.
31+
[kengruven](https://github.com/kengruven)
32+
[#246](https://github.com/p2/OAuth2/pull/246)
33+
34+
### 4.0.1
35+
36+
- Correct the ACL for `updateFromKeychainItems` to `open`.
37+
[JohnTheBastard](https://github.com/JohnTheBastard)
38+
[#239](https://github.com/p2/OAuth2/pull/239)
39+
- Fixed unauthorized error when refreshing a token.
40+
[amaurydavid](https://github.com/amaurydavid)
41+
[#237](https://github.com/p2/OAuth2/pull/237)
42+
- Fixed an exception due to the web policy completion handler being called twice.
43+
[Kashkovsky](https://github.com/Kashkovsky)
44+
[#235](https://github.com/p2/OAuth2/pull/235)
45+
- Bubble errors up from a token fetch to the client.
46+
[dhardiman](https://github.com/dhardiman)
47+
[#232](https://github.com/p2/OAuth2/pull/232)
48+
[#234](https://github.com/p2/OAuth2/pull/234)
49+
50+
### 4.0.0
51+
52+
- Update to Swift 4.
53+
[paulw11](https://github.com/paulw11)
54+
[#228](https://github.com/p2/OAuth2/pull/228)
55+
- Fix an assertion error in Xcode 9.
56+
[markmarkswell](https://github.com/markmarkswell)
57+
[#227](https://github.com/p2/OAuth2/pull/227)
58+
- Remove the dependency on the system `sharedApplication` property to support use in extensions.
59+
[robertbarclay](https://github.com/robertbarclay)
60+
[#212](https://github.com/p2/OAuth2/pull/212)
61+
- Changed the ACL of `customAuthorizer` from `internal` to `open`.
62+
[amaurydavid](https://github.com/amaurydavid)
63+
[#203](https://github.com/p2/OAuth2/pull/203)
64+
- Corrected some typos in the codebase and documentation.
65+
[Lutzifer](https://github.com/Lutzifer)
66+
[#199](https://github.com/p2/OAuth2/pull/199)
67+
- Fixed some warnings with String interpolation.
68+
[paulw11](https://github.com/paulw11)
69+
[jakepetroules](https://github.com/jakepetroules)
70+
[#195](https://github.com/p2/OAuth2/pull/195)
71+
[#204](https://github.com/p2/OAuth2/pull/204)
772

873
### 3.0.3
974

CONTRIBUTORS.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Contributors
33

44
Contributors to the codebase, in reverse chronological order:
55

6+
- David Jennes, @davidjennes
67
- Tim Schmitz, @tschmitz
78
- Seb Skuse, @sebskuse
89
- David Hardiman, @dhardiman

OAuth2.xcodeproj/project.pbxproj

+8-8
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@
830830
PRODUCT_NAME = OAuth2;
831831
SDKROOT = appletvos;
832832
SKIP_INSTALL = YES;
833-
SWIFT_VERSION = 3.0;
833+
SWIFT_VERSION = 4.2;
834834
TARGETED_DEVICE_FAMILY = 3;
835835
TVOS_DEPLOYMENT_TARGET = 9.0;
836836
};
@@ -858,7 +858,7 @@
858858
SDKROOT = appletvos;
859859
SKIP_INSTALL = YES;
860860
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
861-
SWIFT_VERSION = 3.0;
861+
SWIFT_VERSION = 4.2;
862862
TARGETED_DEVICE_FAMILY = 3;
863863
TVOS_DEPLOYMENT_TARGET = 9.0;
864864
};
@@ -990,7 +990,7 @@
990990
PRODUCT_NAME = OAuth2;
991991
SKIP_INSTALL = YES;
992992
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
993-
SWIFT_VERSION = 4.0;
993+
SWIFT_VERSION = 4.2;
994994
};
995995
name = Debug;
996996
};
@@ -1012,7 +1012,7 @@
10121012
PRODUCT_NAME = OAuth2;
10131013
SKIP_INSTALL = YES;
10141014
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
1015-
SWIFT_VERSION = 4.0;
1015+
SWIFT_VERSION = 4.2;
10161016
};
10171017
name = Release;
10181018
};
@@ -1034,7 +1034,7 @@
10341034
PRODUCT_NAME = OAuth2;
10351035
SDKROOT = macosx;
10361036
SKIP_INSTALL = YES;
1037-
SWIFT_VERSION = 4.0;
1037+
SWIFT_VERSION = 4.2;
10381038
};
10391039
name = Debug;
10401040
};
@@ -1058,7 +1058,7 @@
10581058
SDKROOT = macosx;
10591059
SKIP_INSTALL = YES;
10601060
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
1061-
SWIFT_VERSION = 4.0;
1061+
SWIFT_VERSION = 4.2;
10621062
};
10631063
name = Release;
10641064
};
@@ -1077,7 +1077,7 @@
10771077
PRODUCT_BUNDLE_IDENTIFIER = "com.github.p2.${PRODUCT_NAME:rfc1034identifier}";
10781078
PRODUCT_NAME = "$(TARGET_NAME)";
10791079
SDKROOT = macosx;
1080-
SWIFT_VERSION = 3.0;
1080+
SWIFT_VERSION = 4.2;
10811081
};
10821082
name = Debug;
10831083
};
@@ -1098,7 +1098,7 @@
10981098
PRODUCT_NAME = "$(TARGET_NAME)";
10991099
SDKROOT = macosx;
11001100
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
1101-
SWIFT_VERSION = 3.0;
1101+
SWIFT_VERSION = 4.2;
11021102
};
11031103
name = Release;
11041104
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ OAuth2
44
[![Build Status](https://travis-ci.org/p2/OAuth2.svg?branch=master)](https://travis-ci.org/p2/OAuth2)
55
[![License](https://img.shields.io/:license-apache-blue.svg)](LICENSE.txt)
66

7-
OAuth2 frameworks for **macOS**, **iOS** and **tvOS** written in Swift 3.0.
7+
OAuth2 frameworks for **macOS**, **iOS** and **tvOS** written in Swift 4.2.
88

99
- [⤵️ Installation](#installation)
1010
- [🛠 Usage](#usage)

Sources/Base/OAuth2AuthRequest.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ Class representing an OAuth2 authorization request that can be used to create NS
6969
open class OAuth2AuthRequest {
7070

7171
/// The url of the receiver. Queries may by added by parameters specified on `params`.
72-
open let url: URL
72+
public let url: URL
7373

7474
/// The HTTP method.
75-
open let method: OAuth2HTTPMethod
75+
public let method: OAuth2HTTPMethod
7676

7777
/// The content type that will be specified. Defaults to `wwwForm`.
7878
open var contentType = OAuth2HTTPContentType.wwwForm

Sources/Base/OAuth2Base.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ open class OAuth2Base: OAuth2Securable {
3737
}
3838

3939
/// Settings related to the client-server relationship.
40-
open let clientConfig: OAuth2ClientConfig
40+
public let clientConfig: OAuth2ClientConfig
4141

4242
/// Client-side authorization options.
4343
open var authConfig = OAuth2AuthConfig()

Sources/iOS/OAuth2WebViewController.swift

+10-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ open class OAuth2WebViewController: UIViewController, WKNavigationDelegate {
115115
// create a web view
116116
let web = WKWebView()
117117
web.translatesAutoresizingMaskIntoConstraints = false
118-
web.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal
118+
web.scrollView.decelerationRate = UIScrollView.DecelerationRate.normal
119119
web.navigationDelegate = self
120120

121121
view.addSubview(web)
@@ -251,4 +251,13 @@ open class OAuth2WebViewController: UIViewController, WKNavigationDelegate {
251251
}
252252
}
253253

254+
/// Swift < 4.2 support
255+
#if !(swift(>=4.2))
256+
private extension UIScrollView {
257+
enum DecelerationRate {
258+
static let normal = UIScrollViewDecelerationRateNormal
259+
}
260+
}
261+
#endif
262+
254263
#endif

Sources/macOS/OAuth2CustomAuthorizer+macOS.swift

+11-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class OAuth2CustomAuthorizer: OAuth2CustomAuthorizerUI {
5959
expectedType: String(describing: NSViewController.self))
6060
}
6161

62-
parentController.presentViewControllerAsSheet(controller)
62+
parentController.presentAsSheet(controller)
6363
presentedController = controller
6464
}
6565

@@ -79,4 +79,14 @@ public class OAuth2CustomAuthorizer: OAuth2CustomAuthorizerUI {
7979
}
8080
}
8181

82+
/// Swift < 4.2 support
83+
#if !(swift(>=4.2))
84+
private extension NSViewController {
85+
@available(OSXApplicationExtension 10.10, *)
86+
func presentAsSheet(_ viewController: NSViewController) {
87+
presentViewControllerAsSheet(viewController)
88+
}
89+
}
90+
#endif
91+
8292
#endif

Tests/BaseTests/OAuth2AuthRequestTests.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ class OAuth2AuthRequestTests: XCTestCase {
7979
req.params.removeValue(forKey: "b")
8080
XCTAssertTrue(2 == req.params.count)
8181
let str = req.params.percentEncodedQueryString()
82-
XCTAssertEqual("a=AA&c=A+complicated%2Fsurprising+name+%26+character%3Dfun", str)
82+
83+
let parts = Set(str.split(separator: "&"))
84+
XCTAssertEqual(parts, Set(["a=AA", "c=A+complicated%2Fsurprising+name+%26+character%3Dfun"]))
8385
}
8486

8587
func testURLComponents() {

Tests/FlowTests/OAuth2ClientCredentialsTests.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ class OAuth2ClientCredentialsTests: XCTestCase {
7272

7373
let body = String(data: request.httpBody!, encoding: String.Encoding.utf8)
7474
XCTAssertNotNil(body, "Body data must be present")
75-
XCTAssertEqual(body!, "grant_type=client_credentials&scope=login+and+more", "Must create correct request body")
75+
let parts = Set((body ?? "").split(separator: "&"))
76+
XCTAssertEqual(parts, Set(["grant_type=client_credentials", "scope=login+and+more"]), "Must create correct request body")
7677
}
7778

7879
func testFailedTokenRequest() {

0 commit comments

Comments
 (0)