Skip to content

Commit

Permalink
Allow domain to contain http scheme (#1144)
Browse files Browse the repository at this point in the history
* Allow root url scheme to be passed as an option

* Fix typo in test name

* Refactor to check whether http(s) is passed and append if not

* Use indexof instead of startswith
  • Loading branch information
danmastrowcoles authored Jan 14, 2021
1 parent 23515b8 commit 0a869fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/authentication/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function Authentication(auth0, options) {
optional: true,
type: 'object',
message: '_telemetryInfo option is not valid'
}
},
}
);
/* eslint-enable */
Expand All @@ -88,9 +88,11 @@ function Authentication(auth0, options) {
this.baseOptions._sendTelemetry === false
? this.baseOptions._sendTelemetry
: true;

this.baseOptions.rootUrl = 'https://' + this.baseOptions.domain;


this.baseOptions.rootUrl = (this.baseOptions.domain && this.baseOptions.domain.toLowerCase().indexOf('http') === 0)
? this.baseOptions.domain
: 'https://' + this.baseOptions.domain;

this.request = new RequestBuilder(this.baseOptions);

this.passwordless = new PasswordlessAuthentication(
Expand Down
13 changes: 13 additions & 0 deletions test/authentication/authentication.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ describe('auth0.authentication', function() {
var auth0 = new Authentication({}, { domain: 'foo', clientID: 'cid' });
expect(auth0.baseOptions.domain).to.be.equal('foo');
});

[
{domain: 'https://foo', expectedRootUrl: 'https://foo'},
{domain: 'http://foo', expectedRootUrl: 'http://foo'},
{domain: 'HTTPS://FOO', expectedRootUrl: 'HTTPS://FOO'},
{domain: 'foo', expectedRootUrl: 'https://foo'},
].forEach(function(mockData) {
it(`should construct root url ${mockData.expectedRootUrl} when using domain ${mockData.domain}`, function() {
var auth0 = new Authentication({ domain: mockData.domain, clientID: 'cid' });
expect(auth0.baseOptions.rootUrl).to.be.equal(mockData.expectedRootUrl);
});
});

it('should check that options is passed', function() {
expect(function() {
var auth0 = new Authentication();
Expand Down

0 comments on commit 0a869fd

Please sign in to comment.