Skip to content

Commit 12d14f0

Browse files
committed
Update readme to incldue new enable cors feature
1 parent a9f0794 commit 12d14f0

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,11 @@ const pkce = new PKCE({
8686
storage: localStorage, // any Storage object, sessionStorage (default) or localStorage
8787
});
8888
```
89+
90+
## Cors credentials
91+
When using httpOnly cookies, there is some additional configuration required. The method
92+
`enableCorsCredentials` can be called to allow sending credentials.
93+
94+
```javascript
95+
pkce.enableCorsCredentials(true);
96+
```

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-pkce",
3-
"version": "1.3.1",
3+
"version": "1.4.0",
44
"description": "A package that makes using the OAuth2 PKCE flow easier",
55
"main": "dist/PKCE.js",
66
"types": "dist/PKCE.d.ts",

src/ICorsOptions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default interface ICorsOptions {
2-
credentials?: 'omit' | 'same-origin' | 'include',
2+
credentials?: 'omit' | 'same-origin' | 'include';
33
// RFC for mode options: https://fetch.spec.whatwg.org/#concept-request-mode
4-
mode?: 'cors' | 'no-cors' | 'same-origin' | 'navigate'
4+
mode?: 'cors' | 'no-cors' | 'same-origin' | 'navigate';
55
}

src/PKCE.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default class PKCE {
1111
private config: IConfig;
1212
private state: string = '';
1313
private codeVerifier: string = '';
14-
private corsRequestOptions:ICorsOptions = {};
14+
private corsRequestOptions: ICorsOptions = {};
1515

1616
/**
1717
* Initialize the instance with configuration
@@ -27,12 +27,13 @@ export default class PKCE {
2727
* @return ICorsOptions
2828
*/
2929
public enableCorsCredentials(enable: boolean): ICorsOptions {
30-
31-
this.corsRequestOptions = (enable) ? {
32-
credentials: 'include',
33-
mode: 'cors'
34-
} : {}
35-
return this.corsRequestOptions
30+
this.corsRequestOptions = enable
31+
? {
32+
credentials: 'include',
33+
mode: 'cors',
34+
}
35+
: {};
36+
return this.corsRequestOptions;
3637
}
3738

3839
/**
@@ -87,7 +88,7 @@ export default class PKCE {
8788
Accept: 'application/json',
8889
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
8990
},
90-
...this.corsRequestOptions
91+
...this.corsRequestOptions,
9192
}).then((response) => response.json());
9293
});
9394
}

0 commit comments

Comments
 (0)