-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enterprise Connection only authentication #336
Changes from 3 commits
31962c6
25526b1
b7e0a88
ef5049d
b74ec3e
26f8595
7708cf2
f4f1c35
f99cfcd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,4 @@ class ConnectionLoadingPresenter: Presentable, Loggable { | |
} | ||
return LoadingView() | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ import Foundation | |
public protocol Connections { | ||
var database: DatabaseConnection? { get } | ||
var oauth2: [OAuth2Connection] { get } | ||
var enterprise: [EnterpriseConnection] {get} | ||
|
||
var isEmpty: Bool { get } | ||
|
||
|
@@ -59,3 +60,17 @@ public struct SocialConnection: OAuth2Connection { | |
public let name: String | ||
public let style: AuthStyle | ||
} | ||
|
||
public protocol EnterpriseConnection { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't need this protocol now right? or it has some use I don't see? |
||
var name: String { get } | ||
var strategy: String { get } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought it might be useful to know the enterprise strategy, if AD present this view etc |
||
var domain: String { get } | ||
var domainAlias: [String] { get } | ||
} | ||
|
||
public struct EnterpriseConnector : EnterpriseConnection { | ||
public let name: String | ||
public let strategy: String | ||
public let domain: String | ||
public let domainAlias: [String] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// EnterpriseDomain.swift | ||
// | ||
// Copyright (c) 2016 Auth0 (http://auth0.com) | ||
// | ||
// 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 | ||
|
||
protocol EnterpriseDomain { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's rename this to |
||
var email: String? { get } | ||
var validEmail: Bool { get } | ||
var validDomain: Bool { get } | ||
|
||
mutating func updateEmail(value: String?) throws | ||
|
||
func requestConnection(callback: (OAuth2AuthenticatableError?) -> ()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// EnterpriseDomainInteractor.swift | ||
// | ||
// Copyright (c) 2016 Auth0 (http://auth0.com) | ||
// | ||
// 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 | ||
import Auth0 | ||
|
||
struct EnterpriseDomainInteractor: EnterpriseDomain { | ||
|
||
var email: String? = nil | ||
var validEmail: Bool = false | ||
var validDomain: Bool = false | ||
|
||
let connections: Connections | ||
let emailValidator: InputValidator = EmailValidator() | ||
let domainValidator: EnterpriseDomainValidator | ||
let authenticator: OAuth2Authenticatable | ||
|
||
init(connections: Connections, auth: OAuth2Authenticatable) { | ||
self.connections = connections | ||
self.domainValidator = EnterpriseDomainValidator(connections: connections.enterprise) | ||
self.authenticator = auth | ||
} | ||
|
||
mutating func updateEmail(value: String?) throws { | ||
|
||
validEmail = false | ||
validDomain = false | ||
|
||
// Validate email | ||
email = value?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) | ||
if let error = emailValidator.validate(value) { | ||
throw error | ||
} | ||
validEmail = true | ||
|
||
// Validate Enterprise domain | ||
if let error = domainValidator.validate(self.email) { | ||
throw error | ||
} | ||
validDomain = true | ||
} | ||
|
||
func requestConnection(callback: (OAuth2AuthenticatableError?) -> ()) { | ||
guard let _ = self.email else { return callback(.NoConnectionAvailable) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably best to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels less swifty in comparison to guard. However, I also do not like using |
||
guard let connection = self.domainValidator.enterpriseConnection else { return callback(.NoConnectionAvailable) } | ||
|
||
authenticator.login(connection.name) { error in | ||
return callback(error) | ||
} | ||
callback(nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this right?, shouldn't it be inside of the callback?. Maybe just login like authenticator.login(connection.name, callback); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll try this it's cleaner. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// EnterpriseDomainPresenter.swift | ||
// | ||
// Copyright (c) 2016 Auth0 (http://auth0.com) | ||
// | ||
// 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 | ||
|
||
class EnterpriseDomainPresenter: Presentable, Loggable { | ||
|
||
var interactor: EnterpriseDomainInteractor | ||
var customLogger: Logger? | ||
|
||
init(interactor: EnterpriseDomainInteractor) { | ||
self.interactor = interactor | ||
} | ||
|
||
var messagePresenter: MessagePresenter? | ||
|
||
var view: View { | ||
let email = self.interactor.validEmail ? self.interactor.email : nil | ||
let view = EnterpriseDomainView(email: email) | ||
let form = view.form | ||
view.form?.onValueChange = { input in | ||
self.messagePresenter?.hideCurrent() | ||
|
||
guard case .Email = input.type else { return } | ||
do { | ||
try self.interactor.updateEmail(input.text) | ||
input.showValid() | ||
} catch { | ||
input.showError() | ||
} | ||
} | ||
|
||
let action = { (button: PrimaryButton) in | ||
self.messagePresenter?.hideCurrent() | ||
self.logger.info("Enterprise connection validation: \(self.interactor.email)") | ||
let interactor = self.interactor | ||
button.inProgress = true | ||
interactor.requestConnection { error in | ||
Queue.main.async { | ||
button.inProgress = false | ||
form?.needsToUpdateState() | ||
if let error = error { | ||
self.messagePresenter?.showError(error) | ||
self.logger.error("Failed: \(error)") | ||
} else { | ||
self.logger.debug("Launch Web Auth") | ||
} | ||
} | ||
|
||
} | ||
} | ||
view.primaryButton?.onPress = action | ||
view.form?.onReturn = {_ in | ||
guard let button = view.primaryButton else { return } | ||
action(button) | ||
} | ||
return view | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's coalesce into a single
domain
parameter of type[String]
. And make sure when we parse the info from the CDN we put thedomain
one first.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, I was focusing on AD which is just a comma list in dashboard that presents then first domain in the list as the primary domain. Will change.