Skip to content

Commit c68e8b8

Browse files
author
Steve Hobbs
committed
Use domain URL for client settings instead of CDN
1 parent 1d3e7be commit c68e8b8

File tree

3 files changed

+92
-14
lines changed

3 files changed

+92
-14
lines changed

src/__tests__/core/index.test.js

+89
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('setup', () => {
2929
mockInit = jest.fn();
3030
jest.resetModules();
3131
});
32+
3233
it('default redirectUrl should not include location.hash', () => {
3334
setURL('https://test.com/path/#not-this-part');
3435
const options = {};
@@ -38,6 +39,7 @@ describe('setup', () => {
3839
const model = mock.calls[0][1].toJS();
3940
expect(model.auth.redirectUrl).toBe('https://test.com/path/');
4041
});
42+
4143
it('default redirectUrl should work when `window.location.origin` is not available', () => {
4244
setURL('https://test.com/path/#not-this-part', { noOrigin: true });
4345
const options = {};
@@ -47,19 +49,106 @@ describe('setup', () => {
4749
const model = mock.calls[0][1].toJS();
4850
expect(model.auth.redirectUrl).toBe('https://test.com/path/');
4951
});
52+
5053
it('should work with redirect:false and responseType:id_token', () => {
5154
const options = {
5255
auth: {
5356
redirect: false,
5457
responseType: 'id_token'
5558
}
5659
};
60+
5761
setup('id', 'clientID', 'domain', options, 'hookRunner', 'emitEventFn', 'handleEventFn');
5862
const { mock } = mockInit;
5963
expect(mock.calls.length).toBe(1);
6064
const model = mock.calls[0][1].toJS();
6165
expect(model).toMatchSnapshot();
6266
});
67+
68+
it('default clientBaseUrl should use the specified domain', () => {
69+
const { mock } = mockInit;
70+
71+
setup(
72+
'id',
73+
'clientID',
74+
'my-tenant.us.auth0.com',
75+
{},
76+
'hookRunner',
77+
'emitEventFn',
78+
'handleEventFn'
79+
);
80+
81+
expect(mock.calls.length).toBe(1);
82+
83+
const model = mock.calls[0][1].toJS();
84+
expect(model.clientBaseUrl).toBe('https://my-tenant.us.auth0.com');
85+
});
86+
87+
it('clientBaseUrl should use clientBaseUrl if given', () => {
88+
const { mock } = mockInit;
89+
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+
);
103+
104+
expect(mock.calls.length).toBe(1);
105+
106+
const model = mock.calls[0][1].toJS();
107+
expect(model.clientBaseUrl).toBe('https://client-base-url.example.com');
108+
});
109+
110+
it('clientBaseUrl should use configurationBaseUrl if given', () => {
111+
const { mock } = mockInit;
112+
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+
);
125+
126+
expect(mock.calls.length).toBe(1);
127+
128+
const model = mock.calls[0][1].toJS();
129+
expect(model.clientBaseUrl).toBe('https://config-base-url.example.com');
130+
});
131+
132+
it('clientBaseUrl should use assetsUrl if given', () => {
133+
const { mock } = mockInit;
134+
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+
);
146+
147+
expect(mock.calls.length).toBe(1);
148+
149+
const model = mock.calls[0][1].toJS();
150+
expect(model.clientBaseUrl).toBe('https://assets-url.example.com');
151+
});
63152
});
64153

65154
describe('setResolvedConnection', () => {

src/core/index.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -355,18 +355,7 @@ function extractClientBaseUrlOption(opts, domain) {
355355
return opts.assetsUrl;
356356
}
357357

358-
const domainUrl = 'https://' + domain;
359-
const hostname = getLocationFromUrl(domainUrl).hostname;
360-
const DOT_AUTH0_DOT_COM = '.auth0.com';
361-
const AUTH0_US_CDN_URL = 'https://cdn.auth0.com';
362-
if (endsWith(hostname, DOT_AUTH0_DOT_COM)) {
363-
const parts = hostname.split('.');
364-
return parts.length > 3
365-
? 'https://cdn.' + parts[parts.length - 3] + DOT_AUTH0_DOT_COM
366-
: AUTH0_US_CDN_URL;
367-
} else {
368-
return domainUrl;
369-
}
358+
return `https://${domain}`;
370359
}
371360

372361
export function extractTenantBaseUrlOption(opts, domain) {

support/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ <h1 class="navbar-brand">
122122
});
123123
</script>
124124
<script>
125-
var clientId = 'BWDP9XS89CJq1w6Nzq7iFOHsTh6ChS2b';
126-
var domain = 'brucke.auth0.com';
125+
var clientId = 'ZmFdFjVeCiluK09Uq5XH08T0ckeqhH5A';
126+
var domain = 'auth.elkdanger.co.uk';
127127
var defaultOptions = {
128128
mustAcceptTerms: true,
129129
initialScreen: 'login',

0 commit comments

Comments
 (0)