@@ -71,13 +71,15 @@ interface Config {
71
71
BASE: string;
72
72
VERSION: string;
73
73
CLIENT: 'fetch' | 'xhr';
74
+ WITH_CREDENTIALS: boolean;
74
75
TOKEN: string;
75
76
}
76
77
77
78
export const OpenAPI: Config = {
78
79
BASE: 'http://localhost:8080/api',
79
80
VERSION: '9.0',
80
81
CLIENT: 'fetch',
82
+ WITH_CREDENTIALS: false,
81
83
TOKEN: '',
82
84
};"
83
85
`;
@@ -229,9 +231,15 @@ export async function request(options: Readonly<RequestOptions>): Promise<Result
229
231
const request: RequestInit = {
230
232
headers,
231
233
method: options.method,
232
- credentials: 'same-origin',
233
234
};
234
235
236
+ // If we specified to send requests with credentials, then we
237
+ // set the request credentials options to include. This is only
238
+ // needed if you make cross-origin calls.
239
+ if (OpenAPI.WITH_CREDENTIALS) {
240
+ request.credentials = 'include';
241
+ }
242
+
235
243
// If we have a bearer token then we set the authentication header.
236
244
if (OpenAPI.TOKEN !== null && OpenAPI.TOKEN !== '') {
237
245
headers.append('Authorization', \`Bearer \${OpenAPI.TOKEN}\`);
@@ -423,6 +431,11 @@ export async function requestUsingXHR(url: string, request: Readonly<RequestInit
423
431
// because the request needs to be initialized!
424
432
xhr.open(request.method!, url, true);
425
433
434
+ // When request credentials are set to include then this is
435
+ // the same behaviour as withCredentials = true in XHR:
436
+ // https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
437
+ xhr.withCredentials = request.credentials === 'include';
438
+
426
439
// Add the headers (required when dealing with JSON)
427
440
const headers = request.headers as Headers;
428
441
headers.forEach((value: string, key: string): void => {
@@ -2706,13 +2719,15 @@ interface Config {
2706
2719
BASE: string;
2707
2720
VERSION: string;
2708
2721
CLIENT: 'fetch' | 'xhr';
2722
+ WITH_CREDENTIALS: boolean;
2709
2723
TOKEN: string;
2710
2724
}
2711
2725
2712
2726
export const OpenAPI: Config = {
2713
2727
BASE: '/api',
2714
2728
VERSION: '1',
2715
2729
CLIENT: 'fetch',
2730
+ WITH_CREDENTIALS: false,
2716
2731
TOKEN: '',
2717
2732
};"
2718
2733
`;
@@ -2864,9 +2879,15 @@ export async function request(options: Readonly<RequestOptions>): Promise<Result
2864
2879
const request: RequestInit = {
2865
2880
headers,
2866
2881
method: options.method,
2867
- credentials: 'same-origin',
2868
2882
};
2869
2883
2884
+ // If we specified to send requests with credentials, then we
2885
+ // set the request credentials options to include. This is only
2886
+ // needed if you make cross-origin calls.
2887
+ if (OpenAPI.WITH_CREDENTIALS) {
2888
+ request.credentials = 'include';
2889
+ }
2890
+
2870
2891
// If we have a bearer token then we set the authentication header.
2871
2892
if (OpenAPI.TOKEN !== null && OpenAPI.TOKEN !== '') {
2872
2893
headers.append('Authorization', \`Bearer \${OpenAPI.TOKEN}\`);
@@ -3058,6 +3079,11 @@ export async function requestUsingXHR(url: string, request: Readonly<RequestInit
3058
3079
// because the request needs to be initialized!
3059
3080
xhr.open(request.method!, url, true);
3060
3081
3082
+ // When request credentials are set to include then this is
3083
+ // the same behaviour as withCredentials = true in XHR:
3084
+ // https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
3085
+ xhr.withCredentials = request.credentials === 'include';
3086
+
3061
3087
// Add the headers (required when dealing with JSON)
3062
3088
const headers = request.headers as Headers;
3063
3089
headers.forEach((value: string, key: string): void => {
0 commit comments