Skip to content
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

Added configurationBaseURL option for Custom Domains support #505

Merged
merged 2 commits into from
Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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?
}
21 changes: 18 additions & 3 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 @@ -132,7 +135,7 @@ public extension OptionBuildable {
return self.termsOfServiceURL.absoluteString
}
set {
guard let url = URL(string: newValue) else { return } // FIXME: log error
guard let url = URL(string: newValue) else { return }
self.termsOfServiceURL = url
}
}
Expand All @@ -143,7 +146,7 @@ public extension OptionBuildable {
return self.privacyPolicyURL.absoluteString
}
set {
guard let url = URL(string: newValue) else { return } // FIXME: log error
guard let url = URL(string: newValue) else { return }
self.privacyPolicyURL = url
}
}
Expand All @@ -155,9 +158,21 @@ public extension OptionBuildable {
return url.absoluteString
}
set {
guard let value = newValue, let url = URL(string: value) else { return } // FIXME: log error
guard let value = newValue, let url = URL(string: value) else { return }
self.supportURL = url
}
}

/// Base CDN URL. By default is not set.
var configurationBase: String? {
get {
guard let url = self.configurationBaseURL else { return nil }
return url.absoluteString
Copy link
Contributor

@mariancerny mariancerny Jun 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those two lines can be shortened to return self.configurationBaseURL?.absoluteString.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure could, this is for clarity.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I find it more clear (not knowing swift) with a single line. But it's up to you @cocojoe .

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine as it is

}
set {
guard let value = newValue, let url = URL(string: value) else { return }
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
}

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 configurationBaseURL") {
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