@axa-fr/react-oidc 6.6.6 → 6.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/FetchToken.d.ts +1 -1
- package/dist/FetchToken.d.ts.map +1 -1
- package/dist/FetchToken.js +6 -5
- package/dist/FetchToken.js.map +1 -1
- package/package.json +1 -1
- package/src/oidc/FetchToken.tsx +13 -15
package/dist/FetchToken.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ export interface ComponentWithOidcFetchProps {
|
|
|
5
5
|
}
|
|
6
6
|
export declare const withOidcFetch: (fetch?: Fetch, configurationName?: string) => (WrappedComponent: any) => (props: ComponentWithOidcFetchProps) => JSX.Element;
|
|
7
7
|
export declare const useOidcFetch: (fetch?: Fetch, configurationName?: string) => {
|
|
8
|
-
fetch: (
|
|
8
|
+
fetch: (input: URL | RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
9
9
|
};
|
|
10
10
|
//# sourceMappingURL=FetchToken.d.ts.map
|
package/dist/FetchToken.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetchToken.d.ts","sourceRoot":"","sources":["../src/oidc/FetchToken.tsx"],"names":[],"mappings":";AAKA,oBAAY,KAAK,GAAG,OAAO,MAAM,CAAC,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"FetchToken.d.ts","sourceRoot":"","sources":["../src/oidc/FetchToken.tsx"],"names":[],"mappings":";AAKA,oBAAY,KAAK,GAAG,OAAO,MAAM,CAAC,KAAK,CAAC;AAExC,MAAM,WAAW,2BAA2B;IAC1C,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAmCD,eAAO,MAAM,aAAa,WAAW,KAAK,oEAE3B,2BAA2B,gBAGvC,CAAC;AAGJ,eAAO,MAAM,YAAY,WAAU,KAAK;;CAMvC,CAAA"}
|
package/dist/FetchToken.js
CHANGED
|
@@ -18,9 +18,10 @@ const oidc_1 = __importDefault(require("./vanilla/oidc"));
|
|
|
18
18
|
const parseTokens_1 = require("./vanilla/parseTokens");
|
|
19
19
|
const initWorker_1 = require("./vanilla/initWorker");
|
|
20
20
|
const defaultConfigurationName = "default";
|
|
21
|
-
const fetchWithToken = (fetch, getOidcWithConfigurationName) => (
|
|
21
|
+
const fetchWithToken = (fetch, getOidcWithConfigurationName) => (...params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
const [url, options, ...rest] = params;
|
|
23
|
+
const optionTmp = options ? Object.assign({}, options) : { method: "GET" };
|
|
22
24
|
let headers = new Headers();
|
|
23
|
-
const optionTmp = Object.assign({}, options);
|
|
24
25
|
if (optionTmp.headers) {
|
|
25
26
|
headers = !(optionTmp.headers instanceof Headers)
|
|
26
27
|
? new Headers(optionTmp.headers)
|
|
@@ -29,7 +30,7 @@ const fetchWithToken = (fetch, getOidcWithConfigurationName) => (url, options =
|
|
|
29
30
|
const oidc = getOidcWithConfigurationName();
|
|
30
31
|
// @ts-ignore
|
|
31
32
|
const accessToken = oidc.tokens ? oidc.tokens.accessToken : null;
|
|
32
|
-
// We wait
|
|
33
|
+
// We wait the synchronisation before making a request
|
|
33
34
|
while (oidc.tokens && accessToken && !(0, parseTokens_1.isTokensValid)(oidc.tokens)) {
|
|
34
35
|
yield (0, initWorker_1.sleepAsync)(200);
|
|
35
36
|
}
|
|
@@ -43,7 +44,7 @@ const fetchWithToken = (fetch, getOidcWithConfigurationName) => (url, options =
|
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
const newOptions = Object.assign(Object.assign({}, optionTmp), { headers });
|
|
46
|
-
return yield fetch(url, newOptions);
|
|
47
|
+
return yield fetch(url, newOptions, ...rest);
|
|
47
48
|
});
|
|
48
49
|
const withOidcFetch = (fetch = null, configurationName = defaultConfigurationName) => (WrappedComponent) => (props) => {
|
|
49
50
|
const { fetch: newFetch } = (0, exports.useOidcFetch)(fetch || props.fetch, configurationName);
|
|
@@ -53,7 +54,7 @@ exports.withOidcFetch = withOidcFetch;
|
|
|
53
54
|
const useOidcFetch = (fetch = null, configurationName = defaultConfigurationName) => {
|
|
54
55
|
const previousFetch = fetch || window.fetch;
|
|
55
56
|
const getOidc = oidc_1.default.get;
|
|
56
|
-
const getOidcWithConfigurationName = () =>
|
|
57
|
+
const getOidcWithConfigurationName = () => getOidc(configurationName);
|
|
57
58
|
const newFetch = fetchWithToken(previousFetch, getOidcWithConfigurationName);
|
|
58
59
|
return { fetch: newFetch };
|
|
59
60
|
};
|
package/dist/FetchToken.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetchToken.js","sourceRoot":"","sources":["../src/oidc/FetchToken.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,0DAAkC;AAClC,uDAAoD;AACpD,qDAAgD;
|
|
1
|
+
{"version":3,"file":"FetchToken.js","sourceRoot":"","sources":["../src/oidc/FetchToken.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,0DAAkC;AAClC,uDAAoD;AACpD,qDAAgD;AAQhD,MAAM,wBAAwB,GAAG,SAAS,CAAC;AAE3C,MAAM,cAAc,GAAG,CAAC,KAAY,EAAE,4BAA+C,EAAE,EAAE,CAAC,CAAO,GAAG,MAAyB,EAAE,EAAE;IAC/H,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC;IACvC,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,mBAAM,OAAO,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAE9D,IAAI,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC5B,IAAI,SAAS,CAAC,OAAO,EAAE;QACrB,OAAO,GAAG,CAAC,CAAC,SAAS,CAAC,OAAO,YAAY,OAAO,CAAC;YAC7C,CAAC,CAAC,IAAI,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC;YAChC,CAAC,CAAC,SAAS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S,QAAA,aAAa,iBAKtB;AAGG,MAAM,YAAY,GAAE,CAAC,QAAe,IAAI,EAAE,iBAAiB,GAAG,wBAAwB,EAAE,EAAE;IAC/F,MAAM,aAAa,GAAG,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC;IAC5C,MAAM,OAAO,GAAG,cAAI,CAAC,GAAG,CAAC;IACzB,MAAM,4BAA4B,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACtE,MAAM,QAAQ,GAAG,cAAc,CAAC,aAAa,EAAE,4BAA4B,CAAC,CAAC;IAC7E,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AAC7B,CAAC,CAAA;AANY,QAAA,YAAY,gBAMxB"}
|
package/package.json
CHANGED
package/src/oidc/FetchToken.tsx
CHANGED
|
@@ -4,18 +4,18 @@ import {isTokensValid} from "./vanilla/parseTokens";
|
|
|
4
4
|
import {sleepAsync} from "./vanilla/initWorker";
|
|
5
5
|
|
|
6
6
|
export type Fetch = typeof window.fetch;
|
|
7
|
+
|
|
7
8
|
export interface ComponentWithOidcFetchProps {
|
|
8
9
|
fetch?: Fetch;
|
|
9
10
|
}
|
|
11
|
+
|
|
10
12
|
const defaultConfigurationName = "default";
|
|
11
13
|
|
|
12
|
-
const fetchWithToken = (fetch: Fetch, getOidcWithConfigurationName: () => Oidc | null) => async (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const fetchWithToken = (fetch: Fetch, getOidcWithConfigurationName: () => Oidc | null) => async (...params: Parameters<Fetch>) => {
|
|
15
|
+
const [url, options, ...rest] = params;
|
|
16
|
+
const optionTmp = options ? { ...options} : { method: "GET" };
|
|
17
|
+
|
|
16
18
|
let headers = new Headers();
|
|
17
|
-
const optionTmp = { ...options };
|
|
18
|
-
|
|
19
19
|
if (optionTmp.headers) {
|
|
20
20
|
headers = !(optionTmp.headers instanceof Headers)
|
|
21
21
|
? new Headers(optionTmp.headers)
|
|
@@ -23,11 +23,9 @@ const fetchWithToken = (fetch: Fetch, getOidcWithConfigurationName: () => Oidc |
|
|
|
23
23
|
}
|
|
24
24
|
const oidc = getOidcWithConfigurationName();
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
26
|
// @ts-ignore
|
|
29
27
|
const accessToken = oidc.tokens ? oidc.tokens.accessToken : null;
|
|
30
|
-
// We wait
|
|
28
|
+
// We wait the synchronisation before making a request
|
|
31
29
|
while (oidc.tokens && accessToken && !isTokensValid(oidc.tokens)){
|
|
32
30
|
await sleepAsync(200);
|
|
33
31
|
}
|
|
@@ -41,10 +39,10 @@ const fetchWithToken = (fetch: Fetch, getOidcWithConfigurationName: () => Oidc |
|
|
|
41
39
|
}
|
|
42
40
|
}
|
|
43
41
|
const newOptions = { ...optionTmp, headers };
|
|
44
|
-
return await fetch(url, newOptions);
|
|
42
|
+
return await fetch(url, newOptions, ...rest);
|
|
45
43
|
};
|
|
46
44
|
|
|
47
|
-
export const withOidcFetch = (fetch:Fetch=null, configurationName=defaultConfigurationName) => (
|
|
45
|
+
export const withOidcFetch = (fetch: Fetch = null, configurationName = defaultConfigurationName) => (
|
|
48
46
|
WrappedComponent
|
|
49
47
|
) => (props: ComponentWithOidcFetchProps) => {
|
|
50
48
|
const {fetch:newFetch} = useOidcFetch(fetch || props.fetch, configurationName)
|
|
@@ -52,10 +50,10 @@ export const withOidcFetch = (fetch:Fetch=null, configurationName=defaultConfigu
|
|
|
52
50
|
};
|
|
53
51
|
|
|
54
52
|
|
|
55
|
-
export const useOidcFetch =(fetch:Fetch=null, configurationName=defaultConfigurationName) =>{
|
|
53
|
+
export const useOidcFetch =(fetch: Fetch = null, configurationName = defaultConfigurationName) =>{
|
|
56
54
|
const previousFetch = fetch || window.fetch;
|
|
57
|
-
const getOidc =
|
|
58
|
-
const getOidcWithConfigurationName = () =>
|
|
55
|
+
const getOidc = Oidc.get;
|
|
56
|
+
const getOidcWithConfigurationName = () => getOidc(configurationName);
|
|
59
57
|
const newFetch = fetchWithToken(previousFetch, getOidcWithConfigurationName);
|
|
60
|
-
return { fetch:newFetch };
|
|
58
|
+
return { fetch: newFetch };
|
|
61
59
|
}
|