diff --git a/lib/clientBuilder.js b/lib/clientBuilder.js index f0304d9c7..f6650b1d6 100644 --- a/lib/clientBuilder.js +++ b/lib/clientBuilder.js @@ -39,6 +39,11 @@ function OktaAuthBuilder(args) { 'Required usage: new OktaAuth({url: "https://sample.okta.com"})'); } + if (args.url.indexOf('-admin.') !== -1) { + throw new AuthSdkError('URL passed to constructor contains "-admin" in subdomain. ' + + 'Required usage: new OktaAuth({url: "https://dev-12345.okta.com})'); + } + this.options = { url: util.removeTrailingSlash(args.url), clientId: args.clientId, diff --git a/test/spec/errors.js b/test/spec/errors.js index e86878714..d3b7cca9a 100644 --- a/test/spec/errors.js +++ b/test/spec/errors.js @@ -95,5 +95,16 @@ define(function(require) { 'Required usage: new OktaAuth({url: "https://sample.okta.com"})'); }); + it('throw an error if url contains "-admin" when passed to the constructor', function () { + var err; + try { + new OktaAuth({url: 'https://dev-12345-admin.oktapreview.com'}); // eslint-disable-line no-new + } catch (e) { + err = e; + } + expect(err.name).toEqual('AuthSdkError'); + expect(err.errorSummary).toEqual('URL passed to constructor contains "-admin" in subdomain. ' + + 'Required usage: new OktaAuth({url: "https://dev-12345.okta.com})'); + }); }); });