Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add an option to remove the cache-control header #268

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,12 @@ These parameters are overrideable in every platform

**Platform Web**

| parameter | default | required | description | since |
| ------------- | -------- | -------- | -------------------------------------- | ----- |
| windowOptions | | | e.g. width=500,height=600,left=0,top=0 | |
| windowTarget | `_blank` | | | |
| windowReplace | | | | 3.0.0 |
| parameter | default | required | description | since |
|------------------------|----------|----------|-------------------------------------------------------------------------------------------------|-------|
| windowOptions | | | e.g. width=500,height=600,left=0,top=0 | |
| windowTarget | `_blank` | | | |
| windowReplace | | | | 3.0.0 |
| sendCacheControlHeader | true | | Whether to send the cache control header with the token request, unsupported by some providers. | 6.1.0 |

**Platform Android**

Expand Down
4 changes: 4 additions & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ export interface WebOption extends OAuth2AuthenticateBaseOptions {
* Options for the window target. Defaults to _blank
*/
windowTarget?: string;
/**
* Whether to send the cache control header with the token request, unsupported by some providers. Defaults to true.
*/
sendCacheControlHeader?: boolean;
}

export interface AndroidOptions extends OAuth2AuthenticateBaseOptions {
Expand Down
16 changes: 16 additions & 0 deletions src/web-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,22 @@ describe('web options', () => {
expect(webOptions.additionalParameters['emptyParam']).toBeUndefined();
});
});

it('must have the sendCacheControlHeader enabled by default', async () => {
WebUtils.buildWebOptions(oneDriveOptions).then(webOptions => {
expect(webOptions.sendCacheControlHeader).toBeTruthy();
});
});

it('must allow the sendCacheControlHeader to be set to false', async () => {
WebUtils.buildWebOptions({
web: {
sendCacheControlHeader: false,
},
}).then(webOptions => {
expect(webOptions.sendCacheControlHeader).toBeFalsy();
});
});
});

describe('Url param extraction', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/web-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ export class WebUtils {
configOptions,
'pkceEnabled',
);
webOptions.sendCacheControlHeader =
this.getOverwritableValue(configOptions, 'sendCacheControlHeader') ??
webOptions.sendCacheControlHeader;
if (webOptions.pkceEnabled) {
webOptions.pkceCodeVerifier = this.randomString(64);
if (CryptoUtils.HAS_SUBTLE_CRYPTO) {
Expand Down Expand Up @@ -311,6 +314,7 @@ export class WebOptions {
resourceUrl: string;
responseType: string;
scope: string;
sendCacheControlHeader = true;
state: string;
redirectUrl: string;
logsEnabled: boolean;
Expand Down
10 changes: 6 additions & 4 deletions src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ export class GenericOAuth2Web extends WebPlugin implements GenericOAuth2Plugin {
'accept',
'application/json',
);
tokenRequest.setRequestHeader(
'cache-control',
'no-cache',
);
if (this.webOptions.sendCacheControlHeader) {
tokenRequest.setRequestHeader(
'cache-control',
'no-cache',
);
}
tokenRequest.setRequestHeader(
'content-type',
'application/x-www-form-urlencoded',
Expand Down