Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
p2 committed Dec 5, 2016
2 parents aaa6cb2 + e088f8e commit e24dbfa
Show file tree
Hide file tree
Showing 17 changed files with 186 additions and 70 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ Version numbering represents the Swift version, plus a running number representi
You can also refer to commit logs to get details on what was implemented, fixed and improved.


### 3.0.1

- Add Azure flow (thanks @everlof)
- Add `keychain_account_*` settings (thanks @aidzz)
- Workaround for Safari issue (thanks @everlof)


### 3.0.0

- Rewrite in Swift 3
Expand Down
2 changes: 1 addition & 1 deletion Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.0.0</string>
<string>3.0.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
16 changes: 13 additions & 3 deletions OAuth2.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

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

/* Begin PBXFileReference section */
0C2F5E5A1DE2DB8500F621E0 /* OAuth2CodeGrantAzure.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OAuth2CodeGrantAzure.swift; sourceTree = "<group>"; };
6598543F1C5B3B4000237D39 /* OAuth2Authorizer+tvOS.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "OAuth2Authorizer+tvOS.swift"; path = "Sources/tvOS/OAuth2Authorizer+tvOS.swift"; sourceTree = SOURCE_ROOT; };
659854461C5B3BEA00237D39 /* OAuth2.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OAuth2.framework; sourceTree = BUILT_PRODUCTS_DIR; };
65EC05DF1C9050CB00DE9186 /* OAuth2KeychainAccount.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OAuth2KeychainAccount.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -313,6 +315,7 @@
EE29836F1D40B83600933CDD /* OAuth2.swift */,
EE3174EB1945E83100210E62 /* OAuth2ImplicitGrant.swift */,
EE44F691194F2C7D0094AB8B /* OAuth2CodeGrant.swift */,
0C2F5E5A1DE2DB8500F621E0 /* OAuth2CodeGrantAzure.swift */,
EEACE1DE1A7E8FC1009BF3A7 /* OAuth2CodeGrantFacebook.swift */,
EEC6D57B1C2837EA00FA9B1C /* OAuth2CodeGrantLinkedIn.swift */,
EE1391D91AC5B41A002C7B18 /* OAuth2CodeGrantBasicAuth.swift */,
Expand Down Expand Up @@ -545,7 +548,7 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0810;
ORGANIZATIONNAME = "Pascal Pfiffner";
TargetAttributes = {
659854451C5B3BEA00237D39 = {
Expand Down Expand Up @@ -698,6 +701,7 @@
EEC7A8D81AE4851E008C30E7 /* Keychain.swift in Sources */,
EEAEF10B1CDBCF28001A1C6F /* OAuth2Logger.swift in Sources */,
65EC05E01C9050CB00DE9186 /* OAuth2KeychainAccount.swift in Sources */,
0C2F5E5B1DE2DB8500F621E0 /* OAuth2CodeGrantAzure.swift in Sources */,
DD0CCBAD1C4DC83A0044C4E3 /* OAuth2WebViewController.swift in Sources */,
EE9EBF1B1D775F74003263FC /* OAuth2Securable.swift in Sources */,
EE79F65A1BFAA36900746243 /* OAuth2Error.swift in Sources */,
Expand Down Expand Up @@ -783,6 +787,7 @@
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
DEBUG_INFORMATION_FORMAT = dwarf;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -808,6 +813,7 @@
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES;
Expand Down Expand Up @@ -844,8 +850,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -894,8 +902,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -928,7 +938,7 @@
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -950,7 +960,7 @@
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand Down
2 changes: 1 addition & 1 deletion OAuth2.xcodeproj/xcshareddata/xcschemes/OAuth2iOS.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0810"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0810"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0810"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ Some sites also want the client-id/secret combination in the request _body_, not
Sometimes you also need to provide additional authorization parameters.
This can be done in 3 ways:

oauth2.clientConfig.authParameters = ["duration": "permanent"]
oauth2.authParameters = ["duration": "permanent"]
// or in your settings:
"parameters": ["duration": "permanent"]
// or when you authorize manually:
Expand Down
5 changes: 4 additions & 1 deletion Sources/Base/OAuth2AuthConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public struct OAuth2AuthConfig {

/// Whether to automatically dismiss the auto-presented authorization screen.
public var authorizeEmbeddedAutoDismiss = true


/// Add custom parameters to the request
public var customParameters: [String: String]? = nil

/// Context information for the authorization flow:
/// - iOS: The parent view controller to present from
/// - macOS: An NSWindow from which to present a modal sheet _or_ `nil` to present in a new window
Expand Down
6 changes: 5 additions & 1 deletion Sources/Base/OAuth2AuthRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,11 @@ open class OAuth2AuthRequest {
req.setValue(val, forHTTPHeaderField: key)
}
}

if let customParameters = oauth2.authConfig.customParameters {
for (k, v) in customParameters {
finalParams[k] = v
}
}
// add a body to POST requests
if .POST == method && finalParams.count > 0 {
req.httpBody = try finalParams.utf8EncodedData()
Expand Down
46 changes: 26 additions & 20 deletions Sources/Base/OAuth2Base.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ open class OAuth2Base: OAuth2Securable {

/// Custom authorization parameters.
public var authParameters: OAuth2StringDict? {
get { return clientConfig.authParameters }
set { clientConfig.authParameters = newValue }
get { return authConfig.customParameters }
set { authConfig.customParameters = newValue }
}


Expand Down Expand Up @@ -158,24 +158,27 @@ open class OAuth2Base: OAuth2Securable {

The following settings keys are currently supported:

- client_id (string)
- client_secret (string), usually only needed for code grant
- authorize_uri (URL-string)
- token_uri (URL-string), if omitted the authorize_uri will be used to obtain tokens
- redirect_uris (list of URL-strings)
- scope (string)

- client_name (string)
- registration_uri (URL-string)
- logo_uri (URL-string)
- keychain (bool, true by default, applies to using the system keychain)
- keychain_access_mode (string, value for keychain kSecAttrAccessible attribute, kSecAttrAccessibleWhenUnlocked by default)
- keychain_access_group (string, value for keychain kSecAttrAccessGroup attribute, nil by default)
- keychain_account_for_client_credentials(string, "clientCredentials" by default)
- keychain_account_for_tokens(string, "currentTokens" by default)
- verbose (bool, false by default, applies to client logging)
- secret_in_body (bool, false by default, forces the flow to use the request body for the client secret)
- token_assume_unexpired (bool, true by default, whether to use access tokens that do not come with an "expires_in" parameter)
- client_id (String)
- client_secret (String), usually only needed for code grant
- authorize_uri (URL-String)
- token_uri (URL-String), if omitted the authorize_uri will be used to obtain tokens
- redirect_uris (Array of URL-Strings)
- scope (String)

- client_name (String)
- registration_uri (URL-String)
- logo_uri (URL-String)

- keychain (Bool, true by default, applies to using the system keychain)
- keychain_access_mode (String, value for keychain kSecAttrAccessible attribute, kSecAttrAccessibleWhenUnlocked by default)
- keychain_access_group (String, value for keychain kSecAttrAccessGroup attribute, nil by default)
- keychain_account_for_client_credentials(String, "clientCredentials" by default)
- keychain_account_for_tokens(String, "currentTokens" by default)
- secret_in_body (Bool, false by default, forces the flow to use the request body for the client secret)
- parameters ([String: String], custom request parameters to be added during authorization)
- token_assume_unexpired (Bool, true by default, whether to use access tokens that do not come with an "expires_in" parameter)

- verbose (Bool, false by default, applies to client logging)
*/
override public init(settings: OAuth2JSON) {
clientConfig = OAuth2ClientConfig(settings: settings)
Expand All @@ -184,6 +187,9 @@ open class OAuth2Base: OAuth2Securable {
if let inBody = settings["secret_in_body"] as? Bool {
authConfig.secretInBody = inBody
}
if let params = settings["parameters"] as? OAuth2StringDict {
authConfig.customParameters = params
}
if let ttl = settings["title"] as? String {
authConfig.ui.title = ttl
}
Expand Down
17 changes: 11 additions & 6 deletions Sources/Base/OAuth2ClientConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,17 @@ open class OAuth2ClientConfig {
/// Contains special authorization request headers, can be used to override defaults.
open var authHeaders: OAuth2Headers?

/// Custom request parameters to be added during authorization.
open var authParameters: OAuth2StringDict?

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

/**
Initializer to initialize properties from a settings dictionary.
Expand Down Expand Up @@ -111,9 +119,6 @@ open class OAuth2ClientConfig {
if let headers = settings["headers"] as? OAuth2Headers {
authHeaders = headers
}
if let params = settings["parameters"] as? OAuth2StringDict {
authParameters = params
}

// access token options
if let assume = settings["token_assume_unexpired"] as? Bool {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Base/OAuth2Securable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ open class OAuth2Securable: OAuth2Requestable {
*/
public init(settings: OAuth2JSON) {
self.settings = settings

// keychain settings
if let accountForClientCredentials = settings["keychain_account_for_client_credentials"] as? String {
keychainAccountForClientCredentials = accountForClientCredentials
Expand Down
Loading

0 comments on commit e24dbfa

Please sign in to comment.