Skip to content

Commit 99c2fa2

Browse files
author
Steve Hobbs
committed
Use domain for tenant connections URL instead of CDN
1 parent c68e8b8 commit 99c2fa2

File tree

2 files changed

+163
-77
lines changed

2 files changed

+163
-77
lines changed

src/__tests__/core/index.test.js

+160-67
Original file line numberDiff line numberDiff line change
@@ -65,89 +65,182 @@ describe('setup', () => {
6565
expect(model).toMatchSnapshot();
6666
});
6767

68-
it('default clientBaseUrl should use the specified domain', () => {
69-
const { mock } = mockInit;
68+
describe('clientBaseUrl', () => {
69+
it('should default to the specified domain', () => {
70+
const { mock } = mockInit;
7071

71-
setup(
72-
'id',
73-
'clientID',
74-
'my-tenant.us.auth0.com',
75-
{},
76-
'hookRunner',
77-
'emitEventFn',
78-
'handleEventFn'
79-
);
72+
setup(
73+
'id',
74+
'clientID',
75+
'my-tenant.us.auth0.com',
76+
{},
77+
'hookRunner',
78+
'emitEventFn',
79+
'handleEventFn'
80+
);
8081

81-
expect(mock.calls.length).toBe(1);
82+
expect(mock.calls.length).toBe(1);
8283

83-
const model = mock.calls[0][1].toJS();
84-
expect(model.clientBaseUrl).toBe('https://my-tenant.us.auth0.com');
85-
});
84+
const model = mock.calls[0][1].toJS();
85+
expect(model.clientBaseUrl).toBe('https://my-tenant.us.auth0.com');
86+
});
8687

87-
it('clientBaseUrl should use clientBaseUrl if given', () => {
88-
const { mock } = mockInit;
88+
it('should use the clientBaseUrl option if given', () => {
89+
const { mock } = mockInit;
8990

90-
setup(
91-
'id',
92-
'clientID',
93-
'my-tenant.us.auth0.com',
94-
{
95-
clientBaseUrl: 'https://client-base-url.example.com',
96-
configurationBaseUrl: 'https://config-base-url.example.com',
97-
assetsUrl: 'https://assets-url.example.com'
98-
},
99-
'hookRunner',
100-
'emitEventFn',
101-
'handleEventFn'
102-
);
91+
setup(
92+
'id',
93+
'clientID',
94+
'my-tenant.us.auth0.com',
95+
{
96+
clientBaseUrl: 'https://client-base-url.example.com',
97+
configurationBaseUrl: 'https://config-base-url.example.com',
98+
assetsUrl: 'https://assets-url.example.com'
99+
},
100+
'hookRunner',
101+
'emitEventFn',
102+
'handleEventFn'
103+
);
103104

104-
expect(mock.calls.length).toBe(1);
105+
expect(mock.calls.length).toBe(1);
105106

106-
const model = mock.calls[0][1].toJS();
107-
expect(model.clientBaseUrl).toBe('https://client-base-url.example.com');
108-
});
107+
const model = mock.calls[0][1].toJS();
108+
expect(model.clientBaseUrl).toBe('https://client-base-url.example.com');
109+
});
109110

110-
it('clientBaseUrl should use configurationBaseUrl if given', () => {
111-
const { mock } = mockInit;
111+
it('should use configurationBaseUrl if given', () => {
112+
const { mock } = mockInit;
112113

113-
setup(
114-
'id',
115-
'clientID',
116-
'my-tenant.us.auth0.com',
117-
{
118-
configurationBaseUrl: 'https://config-base-url.example.com',
119-
assetsUrl: 'https://assets-url.example.com'
120-
},
121-
'hookRunner',
122-
'emitEventFn',
123-
'handleEventFn'
124-
);
114+
setup(
115+
'id',
116+
'clientID',
117+
'my-tenant.us.auth0.com',
118+
{
119+
configurationBaseUrl: 'https://config-base-url.example.com',
120+
assetsUrl: 'https://assets-url.example.com'
121+
},
122+
'hookRunner',
123+
'emitEventFn',
124+
'handleEventFn'
125+
);
125126

126-
expect(mock.calls.length).toBe(1);
127+
expect(mock.calls.length).toBe(1);
127128

128-
const model = mock.calls[0][1].toJS();
129-
expect(model.clientBaseUrl).toBe('https://config-base-url.example.com');
129+
const model = mock.calls[0][1].toJS();
130+
expect(model.clientBaseUrl).toBe('https://config-base-url.example.com');
131+
});
132+
133+
it('should use assetsUrl if given', () => {
134+
const { mock } = mockInit;
135+
136+
setup(
137+
'id',
138+
'clientID',
139+
'my-tenant.us.auth0.com',
140+
{
141+
assetsUrl: 'https://assets-url.example.com'
142+
},
143+
'hookRunner',
144+
'emitEventFn',
145+
'handleEventFn'
146+
);
147+
148+
expect(mock.calls.length).toBe(1);
149+
150+
const model = mock.calls[0][1].toJS();
151+
expect(model.clientBaseUrl).toBe('https://assets-url.example.com');
152+
});
130153
});
131154

132-
it('clientBaseUrl should use assetsUrl if given', () => {
133-
const { mock } = mockInit;
155+
describe('tenantBaseUrl', () => {
156+
it('tenantBaseUrl should default to domain URL when using auth0.com', () => {
157+
const { mock } = mockInit;
134158

135-
setup(
136-
'id',
137-
'clientID',
138-
'my-tenant.us.auth0.com',
139-
{
140-
assetsUrl: 'https://assets-url.example.com'
141-
},
142-
'hookRunner',
143-
'emitEventFn',
144-
'handleEventFn'
145-
);
159+
setup(
160+
'id',
161+
'clientID',
162+
'my-tenant.us.auth0.com',
163+
{
164+
__useTenantInfo: true
165+
},
166+
'hookRunner',
167+
'emitEventFn',
168+
'handleEventFn'
169+
);
146170

147-
expect(mock.calls.length).toBe(1);
171+
expect(mock.calls.length).toBe(1);
148172

149-
const model = mock.calls[0][1].toJS();
150-
expect(model.clientBaseUrl).toBe('https://assets-url.example.com');
173+
const model = mock.calls[0][1].toJS();
174+
expect(model.tenantBaseUrl).toBe('https://my-tenant.us.auth0.com/tenants/v1/my-tenant.js');
175+
});
176+
177+
it('should default to domain URL when using a custom domain', () => {
178+
const { mock } = mockInit;
179+
180+
setup(
181+
'id',
182+
'clientID',
183+
'auth.my-tenant.com',
184+
{
185+
__useTenantInfo: true
186+
},
187+
'hookRunner',
188+
'emitEventFn',
189+
'handleEventFn'
190+
);
191+
192+
expect(mock.calls.length).toBe(1);
193+
194+
const model = mock.calls[0][1].toJS();
195+
expect(model.tenantBaseUrl).toBe('https://auth.my-tenant.com/info-v1.js');
196+
});
197+
198+
it('should use configurationBaseUrl if specified', () => {
199+
const { mock } = mockInit;
200+
201+
setup(
202+
'id',
203+
'clientID',
204+
'auth.my-tenant.com',
205+
{
206+
__useTenantInfo: true,
207+
configurationBaseUrl: 'https://config-base-url.com'
208+
},
209+
'hookRunner',
210+
'emitEventFn',
211+
'handleEventFn'
212+
);
213+
214+
expect(mock.calls.length).toBe(1);
215+
216+
const model = mock.calls[0][1].toJS();
217+
expect(model.tenantBaseUrl).toBe('https://config-base-url.com/info-v1.js');
218+
});
219+
220+
it('should use configurationBaseUrl with a custom tenant if specified', () => {
221+
const { mock } = mockInit;
222+
223+
setup(
224+
'id',
225+
'clientID',
226+
'auth.my-tenant.com',
227+
{
228+
__useTenantInfo: true,
229+
configurationBaseUrl: 'https://config-base-url.com',
230+
overrides: {
231+
__tenant: 'custom-tenant'
232+
}
233+
},
234+
'hookRunner',
235+
'emitEventFn',
236+
'handleEventFn'
237+
);
238+
239+
expect(mock.calls.length).toBe(1);
240+
241+
const model = mock.calls[0][1].toJS();
242+
expect(model.tenantBaseUrl).toBe('https://config-base-url.com/tenants/v1/custom-tenant.js');
243+
});
151244
});
152245
});
153246

src/core/index.js

+3-10
Original file line numberDiff line numberDiff line change
@@ -374,19 +374,12 @@ export function extractTenantBaseUrlOption(opts, domain) {
374374
const domainUrl = 'https://' + domain;
375375
const hostname = getLocationFromUrl(domainUrl).hostname;
376376
const DOT_AUTH0_DOT_COM = '.auth0.com';
377-
const AUTH0_US_CDN_URL = 'https://cdn.auth0.com';
378-
379-
const parts = hostname.split('.');
380-
const tenant_name = parts[0];
381-
var domain;
382377

383378
if (endsWith(hostname, DOT_AUTH0_DOT_COM)) {
384-
domain =
385-
parts.length > 3
386-
? 'https://cdn.' + parts[parts.length - 3] + DOT_AUTH0_DOT_COM
387-
: AUTH0_US_CDN_URL;
379+
const parts = hostname.split('.');
380+
const tenant_name = parts[0];
388381

389-
return urljoin(domain, 'tenants', 'v1', `${tenant_name}.js`);
382+
return urljoin(domainUrl, 'tenants', 'v1', `${tenant_name}.js`);
390383
} else {
391384
return urljoin(domainUrl, 'info-v1.js');
392385
}

0 commit comments

Comments
 (0)