Skip to content

Commit

Permalink
Added configurationBaseURL option
Browse files Browse the repository at this point in the history
Added `configurationBase` convenience setter
Added Tests
  • Loading branch information
cocojoe committed Jun 5, 2018
1 parent 162030f commit 3c525b6
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Lock/ClassicRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Lock/LockOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ struct LockOptions: OptionBuildable {
var passwordlessMethod: PasswordlessMethod = .code
var passwordManager: OnePassword = OnePassword()
var allowShowPassword: Bool = true
var configurationBaseURL: URL?
}
15 changes: 15 additions & 0 deletions Lock/OptionBuildable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}

}
2 changes: 2 additions & 0 deletions Lock/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ public protocol Options {
var passwordlessMethod: PasswordlessMethod { get }
var passwordManager: OnePassword { get }
var allowShowPassword: Bool { get }

var configurationBaseURL: URL? { get }
}
3 changes: 2 additions & 1 deletion Lock/PasswordlessRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
10 changes: 9 additions & 1 deletion LockTests/OptionsSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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") {
Expand Down Expand Up @@ -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())
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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://<YOUR DOMAIN>.auth0.com"
}
```
### Logging
You can easily turn on/off logging capabilities.
Expand Down

0 comments on commit 3c525b6

Please sign in to comment.