diff --git a/App/ViewController.swift b/App/ViewController.swift index 49d29e5d3..fe38b6264 100644 --- a/App/ViewController.swift +++ b/App/ViewController.swift @@ -48,15 +48,11 @@ class ViewController: UIViewController { actionButton(withTitle: "LOGIN WITH CDN") { return Lock .classic() - .withOptions { - applyDefaultOptions(&$0) - $0.customSignupFields = [ - CustomTextField(name: "first_name", placeholder: "First Name", icon: LazyImage(name: "ic_person", bundle: Lock.bundle)), - CustomTextField(name: "last_name", placeholder: "Last Name", icon: LazyImage(name: "ic_person", bundle: Lock.bundle)) - ] - } - .withStyle { - $0.oauth2["slack"] = AuthStyle( + .withOptions { + applyDefaultOptions(&$0) + } + .withStyle { + $0.oauth2["slack"] = AuthStyle( name: "Slack", color: UIColor ( red: 0.4118, green: 0.8078, blue: 0.6588, alpha: 1.0 ), withImage: LazyImage(name: "ic_slack") diff --git a/Lock/Auth0OAuth2Interactor.swift b/Lock/Auth0OAuth2Interactor.swift index ce7d7da22..665df47e5 100644 --- a/Lock/Auth0OAuth2Interactor.swift +++ b/Lock/Auth0OAuth2Interactor.swift @@ -30,19 +30,22 @@ struct Auth0OAuth2Interactor: OAuth2Authenticatable { let options: Options let nativeHandlers: [String: AuthProvider] - func login(_ connection: String, callback: @escaping (OAuth2AuthenticatableError?) -> Void) { + func login(_ connection: String, parameters: [String: String] = [:], callback: @escaping (OAuth2AuthenticatableError?) -> Void) { if let nativeHandler = self.nativeHandlers[connection] { self.nativeAuth(withConnection: connection, nativeAuth: nativeHandler, callback: callback) } else { - self.webAuth(withConnection: connection, callback: callback) + self.webAuth(withConnection: connection, parameters: parameters, callback: callback) } } - private func webAuth(withConnection connection: String, callback: @escaping (OAuth2AuthenticatableError?) -> Void) { + private func webAuth(withConnection connection: String, parameters authParameters: [String: String], callback: @escaping (OAuth2AuthenticatableError?) -> Void) { + var parameters: [String: String] = [:] - self.options.parameters.forEach { parameters[$0] = "\($1)" } + authParameters.forEach { parameters[$0] = "\($1)" } - var auth = authentication.webAuth(withConnection: connection) + self.options.parameters.forEach { parameters[$0] = "\($1)" } + var auth = authentication + .webAuth(withConnection: connection) .scope(self.options.scope) .parameters(parameters) diff --git a/Lock/EnterpriseDomainInteractor.swift b/Lock/EnterpriseDomainInteractor.swift index 15efe7369..6edee5bb8 100644 --- a/Lock/EnterpriseDomainInteractor.swift +++ b/Lock/EnterpriseDomainInteractor.swift @@ -73,7 +73,9 @@ struct EnterpriseDomainInteractor: HRDAuthenticatable { func login(_ callback: @escaping (OAuth2AuthenticatableError?) -> Void) { guard let connection = self.connection else { return callback(.noConnectionAvailable) } - authenticator.login(connection.name, callback: callback) + var parameters: [String: String] = [:] + parameters["login_hint"] = self.email + authenticator.login(connection.name, parameters: parameters, callback: callback) } } diff --git a/Lock/OAuth2Authenticatable.swift b/Lock/OAuth2Authenticatable.swift index a7726fa07..074830540 100644 --- a/Lock/OAuth2Authenticatable.swift +++ b/Lock/OAuth2Authenticatable.swift @@ -23,7 +23,13 @@ import Foundation protocol OAuth2Authenticatable { - func login(_ connection: String, callback: @escaping (OAuth2AuthenticatableError?) -> Void) + func login(_ connection: String, parameters: [String: String], callback: @escaping (OAuth2AuthenticatableError?) -> Void) +} + +extension OAuth2Authenticatable { + func login(_ connection: String, parameters: [String: String] = [:], callback: @escaping (OAuth2AuthenticatableError?) -> Void) { + self.login(connection, parameters: parameters, callback: callback) + } } enum OAuth2AuthenticatableError: Error, LocalizableError { diff --git a/LockTests/Interactors/EnterpriseDomainInteractorSpec.swift b/LockTests/Interactors/EnterpriseDomainInteractorSpec.swift index 81ad6c330..0f1ed61ce 100644 --- a/LockTests/Interactors/EnterpriseDomainInteractorSpec.swift +++ b/LockTests/Interactors/EnterpriseDomainInteractorSpec.swift @@ -176,14 +176,21 @@ class EnterpriseDomainInteractorSpec: QuickSpec { } it("should not yield error on success") { - authentication.webAuthResult = { return .success(result: mockCredentials()) } + try! enterprise.updateEmail("user@test.com") + enterprise.login() { error = $0 } + expect(error).toEventually(beNil()) + } + it("should add login_hint to login") { + authentication.webAuthResult = { return .success(result: mockCredentials()) } try! enterprise.updateEmail("user@test.com") enterprise.login() { error = $0 } expect(error).toEventually(beNil()) + expect(authentication.webAuth.parameters["login_hint"]) == "user@test.com" } + it("should call credentials callback") { let expected = mockCredentials() authentication.webAuthResult = { return .success(result: expected) } diff --git a/LockTests/Utils/Mocks.swift b/LockTests/Utils/Mocks.swift index 56f80ea98..781230565 100644 --- a/LockTests/Utils/Mocks.swift +++ b/LockTests/Utils/Mocks.swift @@ -154,9 +154,7 @@ class MockMultifactorInteractor: MultifactorAuthenticatable { } class MockAuthInteractor: OAuth2Authenticatable { - func login(_ connection: String, callback: @escaping (OAuth2AuthenticatableError?) -> ()) { - } - func socialIdPAuth(connection: String, accessToken: String, callback: @escaping (OAuth2AuthenticatableError?) -> ()) { + func login(_ connection: String, parameters: [String: String], callback: @escaping (OAuth2AuthenticatableError?) -> ()) { } } @@ -354,10 +352,14 @@ class MockWebAuth: WebAuth { } class MockOAuth2: OAuth2Authenticatable { + var connection: String? = nil var onLogin: () -> OAuth2AuthenticatableError? = { _ in return nil } - func login(_ connection: String, callback: @escaping (OAuth2AuthenticatableError?) -> ()) { + var parameters: [String: String] = [:] + + func login(_ connection: String, parameters: [String: String] = [:], callback: @escaping (OAuth2AuthenticatableError?) -> ()) { self.connection = connection + self.parameters = parameters callback(self.onLogin()) } }