Repository: auth0/auth0.js
Pull request #1144 (2020-12-10 02:58:44)

Allow domain to contain http scheme
### Changes
- Add domain scheme as an optional parameter to Authentication.

### References

Resolves https://github.com/auth0/auth0.js/issues/1134

### Testing

- [X] This change adds unit test coverage
- [ ] This change adds integration test coverage

### Checklist

- [X] I have read the [Auth0 general contribution guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md)
- [X] I have read the [Auth0 Code of Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md)
- [X] All tests and linters described in the [Develop section](https://github.com/auth0/auth0.js#develop) run without errors


stale[bot]: This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇‍♂️

cocojoe: @stevehobbsdev can you take a quick look at this please and validate, stalebot seems quite aggressive here.

Patch:
diff --git a/src/authentication/index.js b/src/authentication/index.js
index b08b912..d6ee2b1 100644
--- a/src/authentication/index.js
+++ b/src/authentication/index.js
@@ -78,7 +78,7 @@ function Authentication(auth0, options) {
         optional: true,
         type: 'object',
         message: '_telemetryInfo option is not valid'
-      }
+      },
     }
   );
   /* eslint-enable */
@@ -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(


Test patch:
diff --git a/test/authentication/authentication.test.js b/test/authentication/authentication.test.js
index c94fcb1..d581103 100644
--- a/test/authentication/authentication.test.js
+++ b/test/authentication/authentication.test.js
@@ -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();