From 3c525b60bfc3cab930b25834a245f211130d87ef Mon Sep 17 00:00:00 2001 From: Martin Walsh Date: Tue, 5 Jun 2018 16:53:58 +0100 Subject: [PATCH] Added `configurationBaseURL` option Added `configurationBase` convenience setter Added Tests --- Lock/ClassicRouter.swift | 3 ++- Lock/LockOptions.swift | 1 + Lock/OptionBuildable.swift | 15 +++++++++++++++ Lock/Options.swift | 2 ++ Lock/PasswordlessRouter.swift | 3 ++- LockTests/OptionsSpec.swift | 10 +++++++++- README.md | 11 +++++++++++ 7 files changed, 42 insertions(+), 3 deletions(-) diff --git a/Lock/ClassicRouter.swift b/Lock/ClassicRouter.swift index 9fe6e7e83..f15d4dfd8 100644 --- a/Lock/ClassicRouter.swift +++ b/Lock/ClassicRouter.swift @@ -40,7 +40,8 @@ struct ClassicRouter: Router { let connections = self.lock.connections guard !connections.isEmpty else { self.lock.logger.debug("No connections configured. Loading application info from Auth0...") - let interactor = CDNLoaderInteractor(baseURL: self.lock.authentication.url, clientId: self.lock.authentication.clientId) + let baseURL = self.lock.options.configurationBaseURL ?? self.lock.authentication.url + let interactor = CDNLoaderInteractor(baseURL: baseURL, clientId: self.lock.authentication.clientId) return ConnectionLoadingPresenter(loader: interactor, navigator: self, dispatcher: lock.observerStore, options: self.lock.options) } let whitelistForActiveAuth = self.lock.options.enterpriseConnectionUsingActiveAuth diff --git a/Lock/LockOptions.swift b/Lock/LockOptions.swift index c17436f58..634c8acfc 100644 --- a/Lock/LockOptions.swift +++ b/Lock/LockOptions.swift @@ -51,4 +51,5 @@ struct LockOptions: OptionBuildable { var passwordlessMethod: PasswordlessMethod = .code var passwordManager: OnePassword = OnePassword() var allowShowPassword: Bool = true + var configurationBaseURL: URL? } diff --git a/Lock/OptionBuildable.swift b/Lock/OptionBuildable.swift index 224a6cbbf..938e451bb 100644 --- a/Lock/OptionBuildable.swift +++ b/Lock/OptionBuildable.swift @@ -102,6 +102,9 @@ public protocol OptionBuildable: Options { /// Should Lock display the option to toggle the visibility of the password field text, will not be visible if password manager is available. By default is true var allowShowPassword: Bool { get set } + + /// Set configuration URL to use for Lock configuration. Required when using Custom Domains + var configurationBaseURL: URL? { get set } } extension OptionBuildable { @@ -160,4 +163,16 @@ public extension OptionBuildable { } } + /// Base CDN URL. By default is not set. + var configurationBase: String? { + get { + guard let url = self.configurationBaseURL else { return nil } + return url.absoluteString + } + set { + guard let value = newValue, let url = URL(string: value) else { return } // FIXME: log error + self.configurationBaseURL = url + } + } + } diff --git a/Lock/Options.swift b/Lock/Options.swift index 5b3697e7a..b4dcede43 100644 --- a/Lock/Options.swift +++ b/Lock/Options.swift @@ -53,4 +53,6 @@ public protocol Options { var passwordlessMethod: PasswordlessMethod { get } var passwordManager: OnePassword { get } var allowShowPassword: Bool { get } + + var configurationBaseURL: URL? { get } } diff --git a/Lock/PasswordlessRouter.swift b/Lock/PasswordlessRouter.swift index 56e1feb89..a37d321bf 100644 --- a/Lock/PasswordlessRouter.swift +++ b/Lock/PasswordlessRouter.swift @@ -41,7 +41,8 @@ struct PasswordlessRouter: Router { let connections = self.lock.connections guard !connections.isEmpty else { self.lock.logger.debug("No connections configured. Loading application info from Auth0...") - let interactor = CDNLoaderInteractor(baseURL: self.lock.authentication.url, clientId: self.lock.authentication.clientId) + let baseURL = self.lock.options.configurationBaseURL ?? self.lock.authentication.url + let interactor = CDNLoaderInteractor(baseURL: baseURL, clientId: self.lock.authentication.clientId) return ConnectionLoadingPresenter(loader: interactor, navigator: self, dispatcher: observerStore, options: self.lock.options) } diff --git a/LockTests/OptionsSpec.swift b/LockTests/OptionsSpec.swift index 645b947eb..8e236be0d 100644 --- a/LockTests/OptionsSpec.swift +++ b/LockTests/OptionsSpec.swift @@ -101,7 +101,6 @@ class OptionsSpec: QuickSpec { expect(options.autoClose) == true } - it("should be passwordless emailCode method by default") { expect(options.passwordlessMethod).to(equal(PasswordlessMethod.code)) } @@ -125,6 +124,10 @@ class OptionsSpec: QuickSpec { it("should have mustAcceptTerms disabled") { expect(options.mustAcceptTerms) == false } + s + it("should have configurationBaseURL as nil") { + expect(options.configurationBaseURL).to(beNil()) + } } describe("validation") { @@ -256,6 +259,11 @@ class OptionsSpec: QuickSpec { expect(options.supportURL?.absoluteString) == "https://auth0.com/docs" } + it("should set baseURL") { + options.configurationBase = "https://auth0.customdomain.com" + expect(options.configurationBaseURL?.absoluteString) == "https://auth0.customdomain.com" + } + it("should ignore invalid support site") { options.supportPage = "not a url" expect(options.supportURL?.absoluteString).to(beNil()) diff --git a/README.md b/README.md index 7476ab448..e3465abcd 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,17 @@ Before presenting Lock you can tell it what connections it should display and us } ``` +### Custom Domains + +If you are using [Custom Domains](https://auth0.com/docs/custom-domains), you will need to set the `configurationBaseURL` to your Auth0 Domain so the Lock configuration can +be read correctly. + +```swift +.withOptions { + $0.configurationBase = "https://.auth0.com" +} +``` + ### Logging You can easily turn on/off logging capabilities.