-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #242 from uber/erichg/AuthStrategy
auth with Eats
- Loading branch information
Showing
29 changed files
with
819 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
github "AliSoftware/OHHTTPStubs" "57feceaabf333e72b2c637dfba6c13a7a5c49619" | ||
github "AliSoftware/OHHTTPStubs" "f90c2bb0fb882e43761ab963ca8869d349d2c6e3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
examples/Obj-C SDK/Obj-C SDK.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
examples/Swift SDK/Swift SDK.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
70 changes: 70 additions & 0 deletions
70
source/UberCore/Authentication/Authenticators/AuthenticationProvider.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// AuthenticationProvider.swift | ||
// UberRides | ||
// | ||
// Copyright © 2018 Uber Technologies, Inc. All rights reserved. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONN | ||
|
||
import Foundation | ||
|
||
/** | ||
* Builder for the given loginType's applicable UberAuthenticators. | ||
*/ | ||
class AuthenticationProvider { | ||
|
||
let productFlowPriority: [UberAuthenticationProductFlow] | ||
let scopes: [UberScope] | ||
|
||
/// Returns an AuthenticationProvider. | ||
/// | ||
/// - Parameters: | ||
/// - scopes: The access scopes for authentication. | ||
/// - productFlowPriority: The product flows against which to authenticate, in the order of which Uber products you'd like to use to authenticate the user. | ||
/// | ||
/// For example, you may want to SSO with the UberEats app, but if the app does not exist on the user's device, then try to authenticate with the Uber Rides app instead. In this example you'd call this parameter with [ eats, rides ]. | ||
init(scopes: [UberScope], productFlowPriority: [UberAuthenticationProductFlow]) { | ||
self.scopes = scopes | ||
self.productFlowPriority = productFlowPriority | ||
} | ||
|
||
/// Returns the ordered list of authenticators to use for the given login type. | ||
func authenticators(for loginType: LoginType) -> [ UberAuthenticating ] { | ||
return productFlowPriority.map { (authProduct: UberAuthenticationProductFlow) in | ||
uberAuthenticator(loginType: loginType, authProduct: authProduct) | ||
} | ||
} | ||
|
||
private func uberAuthenticator(loginType: LoginType, authProduct: UberAuthenticationProductFlow) -> UberAuthenticating { | ||
switch loginType { | ||
case .authorizationCode: | ||
// Rides and Eats temporarily share the same authorization code flow | ||
return AuthorizationCodeGrantAuthenticator(scopes: scopes) | ||
case .implicit: | ||
// Rides and Eats temporarily share the same implicit grant code flow | ||
return ImplicitGrantAuthenticator(scopes: scopes) | ||
case .native: | ||
switch authProduct.uberProductType { | ||
case .rides: | ||
return RidesNativeAuthenticator(scopes: scopes) | ||
case .eats: | ||
return EatsNativeAuthenticator(scopes: scopes) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
source/UberCore/Authentication/Authenticators/EatsAuthenticationDeeplink.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// EatsAuthenticationDeeplink.swift | ||
// UberRides | ||
// | ||
// Copyright © 2018 Uber Technologies, Inc. All rights reserved. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import Foundation | ||
|
||
/** | ||
* A Deeplinking object for authenticating a user via the native UberEats food delivery app | ||
*/ | ||
@objc(UBSDKEatsAuthenticationDeeplink) public class EatsAuthenticationDeeplink: BaseDeeplink { | ||
|
||
/** | ||
Initializes an Authentication Deeplink to request the provided scopes | ||
|
||
- parameter scopes: An array of UberScopes you would like to request | ||
|
||
- returns: An initialized AuthenticationDeeplink | ||
*/ | ||
@objc public init(scopes: [UberScope]) { | ||
let queryItems = AuthenticationURLUtility.buildQueryParameters(scopes) | ||
let scheme = "eatsauth" | ||
let domain = "connect" | ||
|
||
super.init(scheme: scheme, host: domain, path: "", queryItems: queryItems)! | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
source/UberCore/Authentication/Authenticators/EatsNativeAuthenticator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// EatsNativeAuthenticator.swift | ||
// UberRides | ||
// | ||
// Copyright © 2018 Uber Technologies, Inc. All rights reserved. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import Foundation | ||
|
||
/** | ||
* UberAuthenticating object for authenticating a user via the native UberEats food delivery app | ||
*/ | ||
@objc(UBSSOEatsNativeAuthenticator) public class EatsNativeAuthenticator: BaseAuthenticator { | ||
private var deeplink: EatsAuthenticationDeeplink | ||
|
||
@objc override var authorizationURL: URL { | ||
return deeplink.url | ||
} | ||
|
||
/** | ||
Creates a NativeAuthenticator using the provided scopes | ||
|
||
- parameter request: the URL request. | ||
|
||
- returns: true if a redirect was handled, false otherwise. | ||
*/ | ||
@objc public override init(scopes: [UberScope]) { | ||
deeplink = EatsAuthenticationDeeplink(scopes: scopes) | ||
super.init(scopes: scopes) | ||
} | ||
} |
Oops, something went wrong.