Skip to content

Commit

Permalink
feat: Add an option to remove the cache-control header (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ionaru authored Jul 31, 2024
1 parent 2ea6626 commit 159e4d0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
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

0 comments on commit 159e4d0

Please sign in to comment.