Skip to content

Commit e24dbfa

Browse files
committed
Merge branch 'develop'
2 parents aaa6cb2 + e088f8e commit e24dbfa

17 files changed

+186
-70
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ Version numbering represents the Swift version, plus a running number representi
55
You can also refer to commit logs to get details on what was implemented, fixed and improved.
66

77

8+
### 3.0.1
9+
10+
- Add Azure flow (thanks @everlof)
11+
- Add `keychain_account_*` settings (thanks @aidzz)
12+
- Workaround for Safari issue (thanks @everlof)
13+
14+
815
### 3.0.0
916

1017
- Rewrite in Swift 3

Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>3.0.0</string>
18+
<string>3.0.1</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

OAuth2.xcodeproj/project.pbxproj

+13-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
0C2F5E5B1DE2DB8500F621E0 /* OAuth2CodeGrantAzure.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C2F5E5A1DE2DB8500F621E0 /* OAuth2CodeGrantAzure.swift */; };
1011
6598544E1C5B3C9500237D39 /* OAuth2Authorizer+tvOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6598543F1C5B3B4000237D39 /* OAuth2Authorizer+tvOS.swift */; };
1112
6598544F1C5B3C9C00237D39 /* OAuth2Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEDB8640193FAB9200C4EEA1 /* OAuth2Base.swift */; };
1213
659854501C5B3C9C00237D39 /* OAuth2Requestable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF47D2A1B1E3FDD0057D838 /* OAuth2Requestable.swift */; };
@@ -154,6 +155,7 @@
154155
/* End PBXContainerItemProxy section */
155156

156157
/* Begin PBXFileReference section */
158+
0C2F5E5A1DE2DB8500F621E0 /* OAuth2CodeGrantAzure.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OAuth2CodeGrantAzure.swift; sourceTree = "<group>"; };
157159
6598543F1C5B3B4000237D39 /* OAuth2Authorizer+tvOS.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "OAuth2Authorizer+tvOS.swift"; path = "Sources/tvOS/OAuth2Authorizer+tvOS.swift"; sourceTree = SOURCE_ROOT; };
158160
659854461C5B3BEA00237D39 /* OAuth2.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OAuth2.framework; sourceTree = BUILT_PRODUCTS_DIR; };
159161
65EC05DF1C9050CB00DE9186 /* OAuth2KeychainAccount.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OAuth2KeychainAccount.swift; sourceTree = "<group>"; };
@@ -313,6 +315,7 @@
313315
EE29836F1D40B83600933CDD /* OAuth2.swift */,
314316
EE3174EB1945E83100210E62 /* OAuth2ImplicitGrant.swift */,
315317
EE44F691194F2C7D0094AB8B /* OAuth2CodeGrant.swift */,
318+
0C2F5E5A1DE2DB8500F621E0 /* OAuth2CodeGrantAzure.swift */,
316319
EEACE1DE1A7E8FC1009BF3A7 /* OAuth2CodeGrantFacebook.swift */,
317320
EEC6D57B1C2837EA00FA9B1C /* OAuth2CodeGrantLinkedIn.swift */,
318321
EE1391D91AC5B41A002C7B18 /* OAuth2CodeGrantBasicAuth.swift */,
@@ -545,7 +548,7 @@
545548
attributes = {
546549
LastSwiftMigration = 0700;
547550
LastSwiftUpdateCheck = 0700;
548-
LastUpgradeCheck = 0800;
551+
LastUpgradeCheck = 0810;
549552
ORGANIZATIONNAME = "Pascal Pfiffner";
550553
TargetAttributes = {
551554
659854451C5B3BEA00237D39 = {
@@ -698,6 +701,7 @@
698701
EEC7A8D81AE4851E008C30E7 /* Keychain.swift in Sources */,
699702
EEAEF10B1CDBCF28001A1C6F /* OAuth2Logger.swift in Sources */,
700703
65EC05E01C9050CB00DE9186 /* OAuth2KeychainAccount.swift in Sources */,
704+
0C2F5E5B1DE2DB8500F621E0 /* OAuth2CodeGrantAzure.swift in Sources */,
701705
DD0CCBAD1C4DC83A0044C4E3 /* OAuth2WebViewController.swift in Sources */,
702706
EE9EBF1B1D775F74003263FC /* OAuth2Securable.swift in Sources */,
703707
EE79F65A1BFAA36900746243 /* OAuth2Error.swift in Sources */,
@@ -783,6 +787,7 @@
783787
isa = XCBuildConfiguration;
784788
buildSettings = {
785789
APPLICATION_EXTENSION_API_ONLY = YES;
790+
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
786791
DEBUG_INFORMATION_FORMAT = dwarf;
787792
DEFINES_MODULE = YES;
788793
DYLIB_COMPATIBILITY_VERSION = 1;
@@ -808,6 +813,7 @@
808813
isa = XCBuildConfiguration;
809814
buildSettings = {
810815
APPLICATION_EXTENSION_API_ONLY = YES;
816+
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
811817
COPY_PHASE_STRIP = NO;
812818
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
813819
DEFINES_MODULE = YES;
@@ -844,8 +850,10 @@
844850
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
845851
CLANG_WARN_EMPTY_BODY = YES;
846852
CLANG_WARN_ENUM_CONVERSION = YES;
853+
CLANG_WARN_INFINITE_RECURSION = YES;
847854
CLANG_WARN_INT_CONVERSION = YES;
848855
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
856+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
849857
CLANG_WARN_UNREACHABLE_CODE = YES;
850858
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
851859
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -894,8 +902,10 @@
894902
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
895903
CLANG_WARN_EMPTY_BODY = YES;
896904
CLANG_WARN_ENUM_CONVERSION = YES;
905+
CLANG_WARN_INFINITE_RECURSION = YES;
897906
CLANG_WARN_INT_CONVERSION = YES;
898907
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
908+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
899909
CLANG_WARN_UNREACHABLE_CODE = YES;
900910
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
901911
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -928,7 +938,7 @@
928938
buildSettings = {
929939
CLANG_ENABLE_MODULES = YES;
930940
CODE_SIGN_IDENTITY = "iPhone Developer";
931-
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
941+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
932942
DEFINES_MODULE = YES;
933943
DYLIB_COMPATIBILITY_VERSION = 1;
934944
DYLIB_CURRENT_VERSION = 1;
@@ -950,7 +960,7 @@
950960
buildSettings = {
951961
CLANG_ENABLE_MODULES = YES;
952962
CODE_SIGN_IDENTITY = "iPhone Developer";
953-
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
963+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
954964
DEFINES_MODULE = YES;
955965
DYLIB_COMPATIBILITY_VERSION = 1;
956966
DYLIB_CURRENT_VERSION = 1;

OAuth2.xcodeproj/xcshareddata/xcschemes/OAuth2iOS.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0800"
3+
LastUpgradeVersion = "0810"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

OAuth2.xcodeproj/xcshareddata/xcschemes/OAuth2macOS.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0800"
3+
LastUpgradeVersion = "0810"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

OAuth2.xcodeproj/xcshareddata/xcschemes/OAuth2tvOS.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0800"
3+
LastUpgradeVersion = "0810"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ Some sites also want the client-id/secret combination in the request _body_, not
375375
Sometimes you also need to provide additional authorization parameters.
376376
This can be done in 3 ways:
377377

378-
oauth2.clientConfig.authParameters = ["duration": "permanent"]
378+
oauth2.authParameters = ["duration": "permanent"]
379379
// or in your settings:
380380
"parameters": ["duration": "permanent"]
381381
// or when you authorize manually:

Sources/Base/OAuth2AuthConfig.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ public struct OAuth2AuthConfig {
4545

4646
/// Whether to automatically dismiss the auto-presented authorization screen.
4747
public var authorizeEmbeddedAutoDismiss = true
48-
48+
49+
/// Add custom parameters to the request
50+
public var customParameters: [String: String]? = nil
51+
4952
/// Context information for the authorization flow:
5053
/// - iOS: The parent view controller to present from
5154
/// - macOS: An NSWindow from which to present a modal sheet _or_ `nil` to present in a new window

Sources/Base/OAuth2AuthRequest.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ open class OAuth2AuthRequest {
220220
req.setValue(val, forHTTPHeaderField: key)
221221
}
222222
}
223-
223+
if let customParameters = oauth2.authConfig.customParameters {
224+
for (k, v) in customParameters {
225+
finalParams[k] = v
226+
}
227+
}
224228
// add a body to POST requests
225229
if .POST == method && finalParams.count > 0 {
226230
req.httpBody = try finalParams.utf8EncodedData()

Sources/Base/OAuth2Base.swift

+26-20
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ open class OAuth2Base: OAuth2Securable {
116116

117117
/// Custom authorization parameters.
118118
public var authParameters: OAuth2StringDict? {
119-
get { return clientConfig.authParameters }
120-
set { clientConfig.authParameters = newValue }
119+
get { return authConfig.customParameters }
120+
set { authConfig.customParameters = newValue }
121121
}
122122

123123

@@ -158,24 +158,27 @@ open class OAuth2Base: OAuth2Securable {
158158

159159
The following settings keys are currently supported:
160160

161-
- client_id (string)
162-
- client_secret (string), usually only needed for code grant
163-
- authorize_uri (URL-string)
164-
- token_uri (URL-string), if omitted the authorize_uri will be used to obtain tokens
165-
- redirect_uris (list of URL-strings)
166-
- scope (string)
167-
168-
- client_name (string)
169-
- registration_uri (URL-string)
170-
- logo_uri (URL-string)
171-
- keychain (bool, true by default, applies to using the system keychain)
172-
- keychain_access_mode (string, value for keychain kSecAttrAccessible attribute, kSecAttrAccessibleWhenUnlocked by default)
173-
- keychain_access_group (string, value for keychain kSecAttrAccessGroup attribute, nil by default)
174-
- keychain_account_for_client_credentials(string, "clientCredentials" by default)
175-
- keychain_account_for_tokens(string, "currentTokens" by default)
176-
- verbose (bool, false by default, applies to client logging)
177-
- secret_in_body (bool, false by default, forces the flow to use the request body for the client secret)
178-
- token_assume_unexpired (bool, true by default, whether to use access tokens that do not come with an "expires_in" parameter)
161+
- client_id (String)
162+
- client_secret (String), usually only needed for code grant
163+
- authorize_uri (URL-String)
164+
- token_uri (URL-String), if omitted the authorize_uri will be used to obtain tokens
165+
- redirect_uris (Array of URL-Strings)
166+
- scope (String)
167+
168+
- client_name (String)
169+
- registration_uri (URL-String)
170+
- logo_uri (URL-String)
171+
172+
- keychain (Bool, true by default, applies to using the system keychain)
173+
- keychain_access_mode (String, value for keychain kSecAttrAccessible attribute, kSecAttrAccessibleWhenUnlocked by default)
174+
- keychain_access_group (String, value for keychain kSecAttrAccessGroup attribute, nil by default)
175+
- keychain_account_for_client_credentials(String, "clientCredentials" by default)
176+
- keychain_account_for_tokens(String, "currentTokens" by default)
177+
- secret_in_body (Bool, false by default, forces the flow to use the request body for the client secret)
178+
- parameters ([String: String], custom request parameters to be added during authorization)
179+
- token_assume_unexpired (Bool, true by default, whether to use access tokens that do not come with an "expires_in" parameter)
180+
181+
- verbose (Bool, false by default, applies to client logging)
179182
*/
180183
override public init(settings: OAuth2JSON) {
181184
clientConfig = OAuth2ClientConfig(settings: settings)
@@ -184,6 +187,9 @@ open class OAuth2Base: OAuth2Securable {
184187
if let inBody = settings["secret_in_body"] as? Bool {
185188
authConfig.secretInBody = inBody
186189
}
190+
if let params = settings["parameters"] as? OAuth2StringDict {
191+
authConfig.customParameters = params
192+
}
187193
if let ttl = settings["title"] as? String {
188194
authConfig.ui.title = ttl
189195
}

Sources/Base/OAuth2ClientConfig.swift

+11-6
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,17 @@ open class OAuth2ClientConfig {
6666
/// Contains special authorization request headers, can be used to override defaults.
6767
open var authHeaders: OAuth2Headers?
6868

69-
/// Custom request parameters to be added during authorization.
70-
open var authParameters: OAuth2StringDict?
71-
69+
/// There's an issue with authenticating through 'system browser', where safari says:
70+
/// "Safari cannot open the page because the address is invalid." if you first selects 'Cancel' when asked to switch back to "your" app,
71+
/// and then you try authenticating again. To get rid of it you must restart Safari.
72+
///
73+
/// Read more about it here:
74+
/// http://stackoverflow.com/questions/27739442/ios-safari-does-not-recognize-url-schemes-after-user-cancels
75+
/// https://community.fitbit.com/t5/Web-API/oAuth2-authentication-page-gives-me-a-quot-Cannot-Open-Page-quot-error/td-p/1150391
76+
///
77+
/// Toggling `safariCancelWorkaround` to true will send an extra get-paramter to make the url unique, thus it will ask again for the new
78+
/// url.
79+
open var safariCancelWorkaround = false
7280

7381
/**
7482
Initializer to initialize properties from a settings dictionary.
@@ -111,9 +119,6 @@ open class OAuth2ClientConfig {
111119
if let headers = settings["headers"] as? OAuth2Headers {
112120
authHeaders = headers
113121
}
114-
if let params = settings["parameters"] as? OAuth2StringDict {
115-
authParameters = params
116-
}
117122

118123
// access token options
119124
if let assume = settings["token_assume_unexpired"] as? Bool {

Sources/Base/OAuth2Securable.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ open class OAuth2Securable: OAuth2Requestable {
6666
*/
6767
public init(settings: OAuth2JSON) {
6868
self.settings = settings
69-
69+
7070
// keychain settings
7171
if let accountForClientCredentials = settings["keychain_account_for_client_credentials"] as? String {
7272
keychainAccountForClientCredentials = accountForClientCredentials

0 commit comments

Comments
 (0)