@axa-fr/react-oidc 6.6.7 → 6.6.8
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.map +1 -1
- package/dist/FetchToken.js +4 -9
- package/dist/FetchToken.js.map +1 -1
- package/dist/OidcProvider.d.ts.map +1 -1
- package/dist/OidcProvider.js +19 -19
- package/dist/OidcProvider.js.map +1 -1
- package/dist/OidcSecure.d.ts +1 -2
- package/dist/OidcSecure.d.ts.map +1 -1
- package/dist/OidcSecure.js +4 -7
- package/dist/OidcSecure.js.map +1 -1
- package/dist/ReactOidc.d.ts +3 -3
- package/dist/ReactOidc.d.ts.map +1 -1
- package/dist/ReactOidc.js +19 -17
- package/dist/ReactOidc.js.map +1 -1
- package/dist/User.d.ts.map +1 -1
- package/dist/User.js +2 -5
- package/dist/User.js.map +1 -1
- package/dist/core/default-component/Callback.component.js +3 -3
- package/dist/core/default-component/Callback.component.js.map +1 -1
- package/dist/core/default-component/SilentCallback.component.js +3 -6
- package/dist/core/default-component/SilentCallback.component.js.map +1 -1
- package/dist/core/default-component/SilentLogin.component.js +2 -5
- package/dist/core/default-component/SilentLogin.component.js.map +1 -1
- package/dist/vanilla/index.d.ts +1 -1
- package/dist/vanilla/index.d.ts.map +1 -1
- package/dist/vanilla/index.js +3 -3
- package/dist/vanilla/index.js.map +1 -1
- package/dist/vanilla/initWorker.d.ts +1 -1
- package/dist/vanilla/initWorker.d.ts.map +1 -1
- package/dist/vanilla/initWorker.js +4 -0
- package/dist/vanilla/initWorker.js.map +1 -1
- package/dist/vanilla/noHashQueryStringUtils.d.ts.map +1 -1
- package/dist/vanilla/noHashQueryStringUtils.js +1 -2
- package/dist/vanilla/noHashQueryStringUtils.js.map +1 -1
- package/dist/vanilla/oidc.d.ts +16 -12
- package/dist/vanilla/oidc.d.ts.map +1 -1
- package/dist/vanilla/oidc.js +37 -38
- package/dist/vanilla/oidc.js.map +1 -1
- package/dist/vanilla/parseTokens.d.ts +11 -2
- package/dist/vanilla/parseTokens.d.ts.map +1 -1
- package/dist/vanilla/parseTokens.js +2 -2
- package/dist/vanilla/parseTokens.js.map +1 -1
- package/dist/vanilla/timer.js +3 -3
- package/dist/vanilla/timer.js.map +1 -1
- package/dist/vanilla/vanillaOidc.d.ts +56 -0
- package/dist/vanilla/vanillaOidc.d.ts.map +1 -0
- package/dist/vanilla/vanillaOidc.js +84 -0
- package/dist/vanilla/vanillaOidc.js.map +1 -0
- package/package.json +1 -1
- package/src/Home.tsx +0 -1
- package/src/configurations.ts +3 -3
- package/src/oidc/FetchToken.tsx +6 -11
- package/src/oidc/OidcProvider.tsx +21 -20
- package/src/oidc/OidcSecure.tsx +5 -6
- package/src/oidc/ReactOidc.tsx +20 -14
- package/src/oidc/User.ts +2 -4
- package/src/oidc/core/default-component/Callback.component.tsx +3 -3
- package/src/oidc/core/default-component/SilentCallback.component.tsx +3 -3
- package/src/oidc/core/default-component/SilentLogin.component.tsx +2 -2
- package/src/oidc/vanilla/index.ts +1 -1
- package/src/oidc/vanilla/initWorker.ts +5 -0
- package/src/oidc/vanilla/noHashQueryStringUtils.ts +1 -2
- package/src/oidc/vanilla/oidc.ts +57 -64
- package/src/oidc/vanilla/parseTokens.ts +13 -4
- package/src/oidc/vanilla/timer.ts +3 -3
- package/src/oidc/vanilla/vanillaOidc.ts +74 -0
package/dist/vanilla/timer.js
CHANGED
|
@@ -28,9 +28,9 @@ const timer = (function () {
|
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
30
|
function onMessage(port, event) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
const method = event.data[0];
|
|
32
|
+
const id = event.data[1];
|
|
33
|
+
const option = event.data[2];
|
|
34
34
|
if (methods[method]) {
|
|
35
35
|
methods[method](port, id, option);
|
|
36
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timer.js","sourceRoot":"","sources":["../../src/oidc/vanilla/timer.ts"],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AE,OAAO;QACvC,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;QACnB,UAAU,CAAC,WAAW,CAAC,CAAC,YAAY,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;QACpD,oBAAoB,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC;QACpC,OAAO,EAAE,CAAC;IACd,CAAC;IAED,SAAS,kBAAkB,CAAC,EAAE;QAC1B,UAAU,CAAC,WAAW,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,CAAC;QAC7C,oBAAoB,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;IACpC,CAAC;IAED,SAAS,iBAAiB,CAAC,QAAQ,EAAE,OAAO;QACxC,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;QACnB,UAAU,CAAC,WAAW,CAAC,CAAC,aAAa,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;QACrD,qBAAqB,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC;QACrC,OAAO,EAAE,CAAC;IACd,CAAC;IAED,SAAS,mBAAmB,CAAC,EAAE;QAC3B,UAAU,CAAC,WAAW,CAAC,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,CAAC;QAC9C,qBAAqB,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;IACrC,CAAC;IAED,OAAO;QACH,UAAU,EAAE,gBAAgB;QAC5B,YAAY,EAAE,kBAAkB;QAChC,WAAW,EAAE,iBAAiB;QAC9B,aAAa,EAAE,mBAAmB;KACrC,CAAC;AACN,CAAC,EAAE,CAAC,CAAC;AAEL,kBAAe,KAAK,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { LoginCallback, Oidc, OidcConfiguration, StringMap } from "./oidc";
|
|
2
|
+
import { Tokens } from "./parseTokens";
|
|
3
|
+
declare type ValidToken = {
|
|
4
|
+
isTokensValid: Boolean;
|
|
5
|
+
tokens: Tokens;
|
|
6
|
+
numberWaited: Number;
|
|
7
|
+
};
|
|
8
|
+
export declare class VanillaOidc {
|
|
9
|
+
private _oidc;
|
|
10
|
+
constructor(oidc: Oidc);
|
|
11
|
+
subscriveEvents(func: Function): string;
|
|
12
|
+
removeEventSubscription(id: string): void;
|
|
13
|
+
publishEvent(eventName: string, data: any): void;
|
|
14
|
+
static getOrCreate(configuration: OidcConfiguration, name?: string): VanillaOidc;
|
|
15
|
+
static get(name?: string): VanillaOidc;
|
|
16
|
+
static eventNames: {
|
|
17
|
+
service_worker_not_supported_by_browser: string;
|
|
18
|
+
token_aquired: string;
|
|
19
|
+
logout_from_another_tab: string;
|
|
20
|
+
logout_from_same_tab: string;
|
|
21
|
+
token_renewed: string;
|
|
22
|
+
token_timer: string;
|
|
23
|
+
loginAsync_begin: string;
|
|
24
|
+
loginAsync_error: string;
|
|
25
|
+
loginCallbackAsync_begin: string;
|
|
26
|
+
loginCallbackAsync_end: string;
|
|
27
|
+
loginCallbackAsync_error: string;
|
|
28
|
+
refreshTokensAsync_begin: string;
|
|
29
|
+
refreshTokensAsync: string;
|
|
30
|
+
refreshTokensAsync_end: string;
|
|
31
|
+
refreshTokensAsync_error: string;
|
|
32
|
+
refreshTokensAsync_silent_error: string;
|
|
33
|
+
tryKeepExistingSessionAsync_begin: string;
|
|
34
|
+
tryKeepExistingSessionAsync_end: string;
|
|
35
|
+
tryKeepExistingSessionAsync_error: string;
|
|
36
|
+
silentLoginAsync_begin: string;
|
|
37
|
+
silentLoginAsync: string;
|
|
38
|
+
silentLoginAsync_end: string;
|
|
39
|
+
silentLoginAsync_error: string;
|
|
40
|
+
syncTokensAsync_begin: string;
|
|
41
|
+
syncTokensAsync_end: string;
|
|
42
|
+
syncTokensAsync_error: string;
|
|
43
|
+
};
|
|
44
|
+
tryKeepExistingSessionAsync(): Promise<boolean>;
|
|
45
|
+
loginAsync(callbackPath?: string, extras?: StringMap, isSilentSignin?: boolean, scope?: string, silentLoginOnly?: boolean): Promise<void>;
|
|
46
|
+
logoutAsync(callbackPathOrUrl?: string | null | undefined, extras?: StringMap): Promise<void>;
|
|
47
|
+
silentLoginCallbackAsync(): Promise<any>;
|
|
48
|
+
renewTokensAsync(extras?: StringMap): Promise<void>;
|
|
49
|
+
loginCallbackAsync(): Promise<LoginCallback>;
|
|
50
|
+
get tokens(): Tokens;
|
|
51
|
+
get configuration(): OidcConfiguration;
|
|
52
|
+
getValidTokenAsync(waitMs?: number, numberWait?: number): Promise<ValidToken>;
|
|
53
|
+
userInfoAsync(): Promise<any>;
|
|
54
|
+
}
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=vanillaOidc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vanillaOidc.d.ts","sourceRoot":"","sources":["../../src/oidc/vanilla/vanillaOidc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,IAAI,EAAE,iBAAiB,EAAE,SAAS,EAAC,MAAM,QAAQ,CAAC;AAGzE,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAErC,aAAK,UAAU,GAAG;IACd,aAAa,EAAE,OAAO,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,qBAAa,WAAW;IACpB,OAAO,CAAC,KAAK,CAAO;gBACR,IAAI,EAAE,IAAI;IAGtB,eAAe,CAAC,IAAI,EAAC,QAAQ,GAAE,MAAM;IAGrC,uBAAuB,CAAC,EAAE,EAAC,MAAM,GAAE,IAAI;IAGvC,YAAY,CAAC,SAAS,EAAC,MAAM,EAAE,IAAI,EAAC,GAAG,GAAI,IAAI;IAG/C,MAAM,CAAC,WAAW,CAAC,aAAa,EAAC,iBAAiB,EAAE,IAAI,GAAC,MAAgB,GAAE,WAAW;IAGtF,MAAM,CAAC,GAAG,CAAC,IAAI,GAAC,MAAgB,GAAE,WAAW;IAG7C,MAAM,CAAC,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAmB;IACpC,2BAA2B,IAAG,OAAO,CAAC,OAAO,CAAC;IAG9C,UAAU,CAAC,YAAY,GAAC,MAAgB,EAAE,MAAM,GAAC,SAAc,EAAE,cAAc,GAAC,OAAa,EAAE,KAAK,GAAC,MAAgB,EAAE,eAAe,UAAQ,GAAE,OAAO,CAAC,IAAI,CAAC;IAG7J,WAAW,CAAC,iBAAiB,GAAE,MAAM,GAAG,IAAI,GAAG,SAAqB,EAAE,MAAM,GAAE,SAAgB,GAAE,OAAO,CAAC,IAAI,CAAC;IAG7G,wBAAwB,IAAG,OAAO,CAAC,GAAG,CAAC;IAGvC,gBAAgB,CAAC,MAAM,GAAC,SAAc,GAAE,OAAO,CAAC,IAAI,CAAC;IAGrD,kBAAkB,IAAG,OAAO,CAAC,aAAa,CAAC;IAG3C,IAAI,MAAM,IAAG,MAAM,CAElB;IACD,IAAI,aAAa,IAAG,iBAAiB,CAEpC;IACK,kBAAkB,CAAC,MAAM,SAAI,EAAE,UAAU,SAAG,GAAI,OAAO,CAAC,UAAU,CAAC;IAcnE,aAAa,IAAG,OAAO,CAAC,GAAG,CAAC;CAGrC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.VanillaOidc = void 0;
|
|
13
|
+
const oidc_1 = require("./oidc");
|
|
14
|
+
const parseTokens_1 = require("./parseTokens");
|
|
15
|
+
const initWorker_1 = require("./initWorker");
|
|
16
|
+
class VanillaOidc {
|
|
17
|
+
constructor(oidc) {
|
|
18
|
+
this._oidc = oidc;
|
|
19
|
+
}
|
|
20
|
+
subscriveEvents(func) {
|
|
21
|
+
return this._oidc.subscriveEvents(func);
|
|
22
|
+
}
|
|
23
|
+
removeEventSubscription(id) {
|
|
24
|
+
this._oidc.removeEventSubscription(id);
|
|
25
|
+
}
|
|
26
|
+
publishEvent(eventName, data) {
|
|
27
|
+
this._oidc.publishEvent(eventName, data);
|
|
28
|
+
}
|
|
29
|
+
static getOrCreate(configuration, name = "default") {
|
|
30
|
+
return new VanillaOidc(oidc_1.Oidc.getOrCreate(configuration, name));
|
|
31
|
+
}
|
|
32
|
+
static get(name = "default") {
|
|
33
|
+
return new VanillaOidc(oidc_1.Oidc.get(name));
|
|
34
|
+
}
|
|
35
|
+
tryKeepExistingSessionAsync() {
|
|
36
|
+
return this._oidc.tryKeepExistingSessionAsync();
|
|
37
|
+
}
|
|
38
|
+
loginAsync(callbackPath = undefined, extras = null, isSilentSignin = false, scope = undefined, silentLoginOnly = false) {
|
|
39
|
+
return this._oidc.loginAsync(callbackPath, extras, isSilentSignin, scope, silentLoginOnly);
|
|
40
|
+
}
|
|
41
|
+
logoutAsync(callbackPathOrUrl = undefined, extras = null) {
|
|
42
|
+
return this._oidc.logoutAsync(callbackPathOrUrl, extras);
|
|
43
|
+
}
|
|
44
|
+
silentLoginCallbackAsync() {
|
|
45
|
+
return this._oidc.silentLoginCallbackAsync();
|
|
46
|
+
}
|
|
47
|
+
;
|
|
48
|
+
renewTokensAsync(extras = null) {
|
|
49
|
+
return this._oidc.renewTokensAsync(extras);
|
|
50
|
+
}
|
|
51
|
+
loginCallbackAsync() {
|
|
52
|
+
return this._oidc.loginCallbackWithAutoTokensRenewAsync();
|
|
53
|
+
}
|
|
54
|
+
get tokens() {
|
|
55
|
+
return this._oidc.tokens;
|
|
56
|
+
}
|
|
57
|
+
get configuration() {
|
|
58
|
+
return this._oidc.configuration;
|
|
59
|
+
}
|
|
60
|
+
getValidTokenAsync(waitMs = 200, numberWait = 50) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
const oidc = this._oidc;
|
|
63
|
+
let numberWaitTemp = numberWait;
|
|
64
|
+
while (oidc.tokens && !(0, parseTokens_1.isTokensValid)(oidc.tokens) && numberWaitTemp > 0) {
|
|
65
|
+
yield (0, initWorker_1.sleepAsync)(200);
|
|
66
|
+
numberWaitTemp = numberWaitTemp - 1;
|
|
67
|
+
}
|
|
68
|
+
const isValid = !(0, parseTokens_1.isTokensValid)(oidc.tokens);
|
|
69
|
+
return {
|
|
70
|
+
isTokensValid: isValid,
|
|
71
|
+
tokens: oidc.tokens,
|
|
72
|
+
numberWaited: numberWaitTemp - numberWait
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
userInfoAsync() {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
return this._oidc.userInfoAsync();
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.VanillaOidc = VanillaOidc;
|
|
83
|
+
VanillaOidc.eventNames = oidc_1.Oidc.eventNames;
|
|
84
|
+
//# sourceMappingURL=vanillaOidc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vanillaOidc.js","sourceRoot":"","sources":["../../src/oidc/vanilla/vanillaOidc.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAyE;AACzE,+CAA4C;AAC5C,6CAAwC;AASxC,MAAa,WAAW;IAEpB,YAAY,IAAU;QAClB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACtB,CAAC;IACD,eAAe,CAAC,IAAa;QACzB,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IACD,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C,qCAAqC,EAAE,CAAC;IAC9D,CAAC;IACD,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC7B,CAAC;IACD,IAAI,aAAa;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC;IACpC,CAAC;IACK,kBAAkB,CAAC,MAAM,GAAC,GAAG,EAAE,UAAU,GAAC,EAAE;;YAC9C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;YACxB,IAAI,cAAc,GAAG,UAAU,CAAC;YAChC,OAAO,IAAI,CAAC,MAAM,IAAI,CAAC,IAAA,2BAAa,EAAC,IAAI,CAAC,MAAM,CAAC,IAAI,cAAc,GAAG,CAAC,EAAE;gBACrE,MAAM,IAAA,uBAAU,EAAC,GAAG,CAAC,CAAC;gBACtB,cAAc,GAAC,cAAc,GAAC,CAAC,CAAC;aACnC;YACD,MAAM,OAAO,GAAG,CAAC,IAAA,2BAAa,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC5C,OAAO;gBACH,aAAa,EAAE,OAAO;gBACtB,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,YAAY,EAAE,cAAc,GAAG,UAAU;aAC5C,CAAC;QACN,CAAC;KAAA;IACK,aAAa;;YACf,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;QACtC,CAAC;KAAA;;AA7DL,kCA8DC;AA1CU,sBAAU,GAAG,WAAI,CAAC,UAAU,CAAC"}
|
package/package.json
CHANGED
package/src/Home.tsx
CHANGED
|
@@ -12,7 +12,6 @@ export const Home = () => {
|
|
|
12
12
|
<h5 className="card-title">Home</h5>
|
|
13
13
|
<p className="card-text">React Demo Application protected by OpenId Connect. More info on about oidc on <a href="https://github.com/AxaGuilDEv/react-oidc">GitHub @axa-fr/react-oidc</a></p>
|
|
14
14
|
{!isAuthenticated && <p><button type="button" className="btn btn-primary" onClick={() => login('/profile')}>Login</button></p>}
|
|
15
|
-
{!isAuthenticated && <p><button type="button" className="btn btn-primary" onClick={() => login('/profile', null, "youhou")}>Login with state</button></p>}
|
|
16
15
|
{isAuthenticated && <p><button type="button" className="btn btn-primary" onClick={() => logout('/profile')}>logout /profile</button></p>}
|
|
17
16
|
{isAuthenticated && <p><button type="button" className="btn btn-primary" onClick={() => logout()}>logout</button></p>}
|
|
18
17
|
{isAuthenticated && <p><button type="button" className="btn btn-primary" onClick={() => logout(null)}>logout whithout callbackredirect</button></p>}
|
package/src/configurations.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export const configurationIdentityServer = {
|
|
2
2
|
client_id: 'interactive.public.short',
|
|
3
|
-
redirect_uri: window.location.origin+'/authentication/callback',
|
|
4
|
-
silent_redirect_uri: window.location.origin+'/authentication/silent-callback',
|
|
3
|
+
redirect_uri: window.location.origin + '/authentication/callback',
|
|
4
|
+
silent_redirect_uri: window.location.origin + '/authentication/silent-callback',
|
|
5
5
|
//silent_login_uri: window.location.origin+'/authentication/silent-login',
|
|
6
6
|
scope: 'openid profile email api offline_access',
|
|
7
7
|
authority: 'https://demo.duendesoftware.com',
|
|
8
8
|
//authority_time_cache_wellknowurl_in_second: 60* 60,
|
|
9
|
-
refresh_time_before_tokens_expiration_in_second:
|
|
9
|
+
refresh_time_before_tokens_expiration_in_second: 40,
|
|
10
10
|
service_worker_relative_url:'/OidcServiceWorker.js',
|
|
11
11
|
service_worker_only: false,
|
|
12
12
|
//storage: sessionStorage,
|
package/src/oidc/FetchToken.tsx
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import {isTokensValid} from "./vanilla/parseTokens";
|
|
4
|
-
import {sleepAsync} from "./vanilla/initWorker";
|
|
2
|
+
import {VanillaOidc} from './vanilla/vanillaOidc'
|
|
5
3
|
|
|
6
4
|
export type Fetch = typeof window.fetch;
|
|
7
5
|
|
|
@@ -11,7 +9,7 @@ export interface ComponentWithOidcFetchProps {
|
|
|
11
9
|
|
|
12
10
|
const defaultConfigurationName = "default";
|
|
13
11
|
|
|
14
|
-
const fetchWithToken = (fetch: Fetch, getOidcWithConfigurationName: () =>
|
|
12
|
+
const fetchWithToken = (fetch: Fetch, getOidcWithConfigurationName: () => VanillaOidc | null) => async (...params: Parameters<Fetch>) => {
|
|
15
13
|
const [url, options, ...rest] = params;
|
|
16
14
|
const optionTmp = options ? { ...options} : { method: "GET" };
|
|
17
15
|
|
|
@@ -24,11 +22,9 @@ const fetchWithToken = (fetch: Fetch, getOidcWithConfigurationName: () => Oidc |
|
|
|
24
22
|
const oidc = getOidcWithConfigurationName();
|
|
25
23
|
|
|
26
24
|
// @ts-ignore
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
await sleepAsync(200);
|
|
31
|
-
}
|
|
25
|
+
const getValidToken = await oidc.getValidTokenAsync();
|
|
26
|
+
const accessToken = getValidToken.tokens.accessToken;
|
|
27
|
+
|
|
32
28
|
if (!headers.has('Accept')) {
|
|
33
29
|
headers.set('Accept', 'application/json');
|
|
34
30
|
}
|
|
@@ -49,10 +45,9 @@ export const withOidcFetch = (fetch: Fetch = null, configurationName = defaultCo
|
|
|
49
45
|
return <WrappedComponent {...props} fetch={newFetch} />;
|
|
50
46
|
};
|
|
51
47
|
|
|
52
|
-
|
|
53
48
|
export const useOidcFetch =(fetch: Fetch = null, configurationName = defaultConfigurationName) =>{
|
|
54
49
|
const previousFetch = fetch || window.fetch;
|
|
55
|
-
const getOidc =
|
|
50
|
+
const getOidc = VanillaOidc.get;
|
|
56
51
|
const getOidcWithConfigurationName = () => getOidc(configurationName);
|
|
57
52
|
const newFetch = fetchWithToken(previousFetch, getOidcWithConfigurationName);
|
|
58
53
|
return { fetch: newFetch };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React, {ComponentType, FC, PropsWithChildren, useEffect, useState} from 'react';
|
|
2
|
-
import
|
|
2
|
+
import {OidcConfiguration} from './vanilla/oidc';
|
|
3
|
+
import {VanillaOidc} from './vanilla/vanillaOidc';
|
|
3
4
|
import OidcRoutes from './core/routes/OidcRoutes';
|
|
4
|
-
import {Authenticating,
|
|
5
|
+
import {Authenticating, SessionLost, Loading, CallBackSuccess} from './core/default-component/index';
|
|
5
6
|
import ServiceWorkerNotSupported from "./core/default-component/ServiceWorkerNotSupported.component";
|
|
6
7
|
import AuthenticatingError from "./core/default-component/AuthenticateError.component";
|
|
7
8
|
import { CustomHistory } from "./core/routes/withRouter";
|
|
@@ -37,7 +38,7 @@ export type OidcSessionProps = {
|
|
|
37
38
|
|
|
38
39
|
const OidcSession : FC<PropsWithChildren<OidcSessionProps>> = ({loadingComponent, children, configurationName}) =>{
|
|
39
40
|
const [loading, setLoading] = useState(true);
|
|
40
|
-
const getOidc =
|
|
41
|
+
const getOidc = VanillaOidc.get;
|
|
41
42
|
const oidc = getOidc(configurationName);
|
|
42
43
|
useEffect(() => {
|
|
43
44
|
let isMounted = true;
|
|
@@ -51,7 +52,7 @@ const OidcSession : FC<PropsWithChildren<OidcSessionProps>> = ({loadingComponent
|
|
|
51
52
|
return () => {
|
|
52
53
|
isMounted = false;
|
|
53
54
|
}
|
|
54
|
-
}, [
|
|
55
|
+
}, [configurationName]);
|
|
55
56
|
const LoadingComponent = loadingComponent;
|
|
56
57
|
return (
|
|
57
58
|
<>
|
|
@@ -89,7 +90,7 @@ export const OidcProvider : FC<PropsWithChildren<OidcProviderProps>> = ({ child
|
|
|
89
90
|
onEvent=null,
|
|
90
91
|
}) => {
|
|
91
92
|
const getOidc =(configurationName="default") => {
|
|
92
|
-
return
|
|
93
|
+
return VanillaOidc.getOrCreate(configuration, configurationName);
|
|
93
94
|
}
|
|
94
95
|
const [loading, setLoading] = useState(true);
|
|
95
96
|
const [event, setEvent] = useState(defaultEventState);
|
|
@@ -112,34 +113,34 @@ export const OidcProvider : FC<PropsWithChildren<OidcProviderProps>> = ({ child
|
|
|
112
113
|
useEffect(() => {
|
|
113
114
|
const oidc = getOidc(configurationName);
|
|
114
115
|
const newSubscriptionId = oidc.subscriveEvents((name, data) => {
|
|
115
|
-
if(name ==
|
|
116
|
+
if(name == VanillaOidc.eventNames.refreshTokensAsync_error || name == VanillaOidc.eventNames.syncTokensAsync_error){
|
|
116
117
|
if(onSessionLost != null){
|
|
117
118
|
onSessionLost();
|
|
118
119
|
return;
|
|
119
120
|
}
|
|
120
121
|
setEvent({name, data});
|
|
121
122
|
}
|
|
122
|
-
else if(name ===
|
|
123
|
+
else if(name === VanillaOidc.eventNames.logout_from_another_tab){
|
|
123
124
|
if(onLogoutFromAnotherTab != null){
|
|
124
125
|
onLogoutFromAnotherTab();
|
|
125
126
|
return;
|
|
126
127
|
}
|
|
127
128
|
setEvent({name, data});
|
|
128
129
|
}
|
|
129
|
-
else if(name ===
|
|
130
|
+
else if(name === VanillaOidc.eventNames.logout_from_same_tab){
|
|
130
131
|
if(onLogoutFromSameTab != null){
|
|
131
132
|
onLogoutFromSameTab();
|
|
132
133
|
return;
|
|
133
134
|
}
|
|
134
135
|
//setEvent({name, data});
|
|
135
136
|
}
|
|
136
|
-
else if (name ==
|
|
137
|
-
|| name ==
|
|
138
|
-
|| name ==
|
|
139
|
-
|| name ==
|
|
137
|
+
else if (name == VanillaOidc.eventNames.loginAsync_begin
|
|
138
|
+
|| name == VanillaOidc.eventNames.loginCallbackAsync_end
|
|
139
|
+
|| name == VanillaOidc.eventNames.loginAsync_error
|
|
140
|
+
|| name == VanillaOidc.eventNames.loginCallbackAsync_error
|
|
140
141
|
) {
|
|
141
142
|
setEvent({name, data});
|
|
142
|
-
} else if (name ==
|
|
143
|
+
} else if (name == VanillaOidc.eventNames.service_worker_not_supported_by_browser && configuration.service_worker_only === true) {
|
|
143
144
|
setEvent({name, data});
|
|
144
145
|
}
|
|
145
146
|
});
|
|
@@ -164,22 +165,22 @@ export const OidcProvider : FC<PropsWithChildren<OidcProviderProps>> = ({ child
|
|
|
164
165
|
const oidc = getOidc(configurationName);
|
|
165
166
|
let eventName = event.name;
|
|
166
167
|
switch(eventName){
|
|
167
|
-
case
|
|
168
|
+
case VanillaOidc.eventNames.service_worker_not_supported_by_browser:
|
|
168
169
|
return <Switch loadingComponent={LoadingComponent} isLoading={isLoading} configurationName={configurationName}>
|
|
169
170
|
<ServiceWorkerNotSupportedComponent configurationName={configurationName} />
|
|
170
171
|
</Switch>;
|
|
171
|
-
case
|
|
172
|
+
case VanillaOidc.eventNames.loginAsync_begin:
|
|
172
173
|
return <Switch loadingComponent={LoadingComponent} isLoading={isLoading} configurationName={configurationName}>
|
|
173
174
|
<AuthenticatingComponent configurationName={configurationName} />
|
|
174
175
|
</Switch>;
|
|
175
|
-
case
|
|
176
|
-
case
|
|
176
|
+
case VanillaOidc.eventNames.loginAsync_error:
|
|
177
|
+
case VanillaOidc.eventNames.loginCallbackAsync_error:
|
|
177
178
|
return <Switch loadingComponent={LoadingComponent} isLoading={isLoading} configurationName={configurationName}>
|
|
178
179
|
<AuthenticatingErrorComponent configurationName={configurationName} />
|
|
179
180
|
</Switch>;
|
|
180
|
-
case
|
|
181
|
-
case
|
|
182
|
-
case
|
|
181
|
+
case VanillaOidc.eventNames.refreshTokensAsync_error:
|
|
182
|
+
case VanillaOidc.eventNames.syncTokensAsync_error:
|
|
183
|
+
case VanillaOidc.eventNames.logout_from_another_tab:
|
|
183
184
|
return <Switch loadingComponent={LoadingComponent} isLoading={isLoading} configurationName={configurationName}>
|
|
184
185
|
<SessionLostComponent configurationName={configurationName} />
|
|
185
186
|
</Switch>;
|
package/src/oidc/OidcSecure.tsx
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import React, {useEffect, PropsWithChildren, FC} from 'react';
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import {StringMap} from "./vanilla/oidc";
|
|
4
|
+
import {VanillaOidc} from "./vanilla/vanillaOidc";
|
|
4
5
|
|
|
5
6
|
export type OidcSecureProps = {
|
|
6
7
|
callbackPath?:string;
|
|
7
8
|
extras?:StringMap
|
|
8
9
|
configurationName?: string;
|
|
9
|
-
state?: string|undefined;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export const OidcSecure: FC<PropsWithChildren<OidcSecureProps>> = ({children, callbackPath=null, extras=null, configurationName="default"}) => {
|
|
13
|
-
const getOidc =
|
|
13
|
+
const getOidc = VanillaOidc.get;
|
|
14
14
|
const oidc = getOidc(configurationName);
|
|
15
15
|
useEffect(() => {
|
|
16
16
|
if(!oidc.tokens){
|
|
@@ -30,8 +30,7 @@ export const withOidcSecure = (
|
|
|
30
30
|
WrappedComponent: FC<PropsWithChildren<OidcSecureProps>>,
|
|
31
31
|
callbackPath=null,
|
|
32
32
|
extras=null,
|
|
33
|
-
configurationName="default"
|
|
34
|
-
state: string|undefined=undefined
|
|
33
|
+
configurationName="default"
|
|
35
34
|
) => (props) => {
|
|
36
|
-
return <OidcSecure
|
|
35
|
+
return <OidcSecure callbackPath={callbackPath} extras={extras} configurationName={configurationName}><WrappedComponent {...props} /></OidcSecure>;
|
|
37
36
|
};
|
package/src/oidc/ReactOidc.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, {useEffect, useState} from 'react';
|
|
2
|
-
import
|
|
2
|
+
import {StringMap} from "./vanilla/oidc";
|
|
3
|
+
import {VanillaOidc} from "./vanilla/vanillaOidc";
|
|
3
4
|
|
|
4
5
|
const defaultConfigurationName = "default";
|
|
5
6
|
|
|
@@ -13,7 +14,7 @@ const defaultIsAuthenticated = (getOidc, configurationName) =>{
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export const useOidc =(configurationName=defaultConfigurationName) =>{
|
|
16
|
-
const getOidc =
|
|
17
|
+
const getOidc = VanillaOidc.get;
|
|
17
18
|
const [isAuthenticated, setIsAuthenticated] = useState<boolean>(defaultIsAuthenticated(getOidc, configurationName));
|
|
18
19
|
|
|
19
20
|
useEffect(() => {
|
|
@@ -21,7 +22,7 @@ export const useOidc =(configurationName=defaultConfigurationName) =>{
|
|
|
21
22
|
const oidc = getOidc(configurationName);
|
|
22
23
|
setIsAuthenticated(defaultIsAuthenticated(getOidc, configurationName));
|
|
23
24
|
const newSubscriptionId = oidc.subscriveEvents((name, data) => {
|
|
24
|
-
if(name ===
|
|
25
|
+
if(name === VanillaOidc.eventNames.logout_from_another_tab || name === VanillaOidc.eventNames.logout_from_same_tab || name === VanillaOidc.eventNames.token_aquired){
|
|
25
26
|
if(isMounted) {
|
|
26
27
|
setIsAuthenticated(defaultIsAuthenticated(getOidc, configurationName));
|
|
27
28
|
}
|
|
@@ -48,7 +49,7 @@ export const useOidc =(configurationName=defaultConfigurationName) =>{
|
|
|
48
49
|
const accessTokenInitialState = {accessToken:null, accessTokenPayload:null};
|
|
49
50
|
|
|
50
51
|
const initTokens = (configurationName) => {
|
|
51
|
-
const getOidc =
|
|
52
|
+
const getOidc = VanillaOidc.get;
|
|
52
53
|
const oidc = getOidc(configurationName);
|
|
53
54
|
if(oidc.tokens) {
|
|
54
55
|
const tokens = oidc.tokens;
|
|
@@ -63,7 +64,7 @@ export type OidcAccessToken = {
|
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
export const useOidcAccessToken =(configurationName=defaultConfigurationName) =>{
|
|
66
|
-
const getOidc =
|
|
67
|
+
const getOidc = VanillaOidc.get;
|
|
67
68
|
const [state, setAccessToken] = useState<OidcAccessToken>(initTokens(configurationName));
|
|
68
69
|
|
|
69
70
|
useEffect(() => {
|
|
@@ -74,10 +75,12 @@ export const useOidcAccessToken =(configurationName=defaultConfigurationName) =>
|
|
|
74
75
|
setAccessToken({accessToken :tokens.accessToken, accessTokenPayload: tokens.accessTokenPayload });
|
|
75
76
|
}
|
|
76
77
|
const newSubscriptionId = oidc.subscriveEvents((name, data) => {
|
|
77
|
-
if(name ==
|
|
78
|
-
|| name ==
|
|
79
|
-
|| name ===
|
|
80
|
-
|| name ===
|
|
78
|
+
if(name == VanillaOidc.eventNames.token_renewed
|
|
79
|
+
|| name == VanillaOidc.eventNames.token_aquired
|
|
80
|
+
|| name === VanillaOidc.eventNames.logout_from_another_tab
|
|
81
|
+
|| name === VanillaOidc.eventNames.logout_from_same_tab
|
|
82
|
+
|| name == VanillaOidc.eventNames.refreshTokensAsync_error
|
|
83
|
+
|| name == VanillaOidc.eventNames.syncTokensAsync_error){
|
|
81
84
|
if(isMounted) {
|
|
82
85
|
const tokens = oidc.tokens;
|
|
83
86
|
setAccessToken(tokens != null ? {accessToken :tokens.accessToken, accessTokenPayload: tokens.accessTokenPayload } : accessTokenInitialState);
|
|
@@ -95,7 +98,7 @@ export const useOidcAccessToken =(configurationName=defaultConfigurationName) =>
|
|
|
95
98
|
const idTokenInitialState = {idToken:null, idTokenPayload:null};
|
|
96
99
|
|
|
97
100
|
const initIdToken= (configurationName) =>{
|
|
98
|
-
const getOidc =
|
|
101
|
+
const getOidc = VanillaOidc.get;
|
|
99
102
|
const oidc = getOidc(configurationName);
|
|
100
103
|
if(oidc.tokens) {
|
|
101
104
|
const tokens = oidc.tokens;
|
|
@@ -110,7 +113,7 @@ export type OidcIdToken = {
|
|
|
110
113
|
}
|
|
111
114
|
|
|
112
115
|
export const useOidcIdToken =(configurationName= defaultConfigurationName) =>{
|
|
113
|
-
const getOidc =
|
|
116
|
+
const getOidc = VanillaOidc.get;
|
|
114
117
|
const [state, setIDToken] = useState<OidcIdToken>(initIdToken(configurationName));
|
|
115
118
|
|
|
116
119
|
useEffect(() => {
|
|
@@ -121,9 +124,12 @@ export const useOidcIdToken =(configurationName= defaultConfigurationName) =>{
|
|
|
121
124
|
setIDToken({idToken: tokens.idToken, idTokenPayload:tokens.idTokenPayload});
|
|
122
125
|
}
|
|
123
126
|
const newSubscriptionId = oidc.subscriveEvents((name, data) => {
|
|
124
|
-
if(name ==
|
|
125
|
-
|| name ==
|
|
126
|
-
|| name ===
|
|
127
|
+
if(name == VanillaOidc.eventNames.token_renewed
|
|
128
|
+
|| name == VanillaOidc.eventNames.token_aquired
|
|
129
|
+
|| name === VanillaOidc.eventNames.logout_from_another_tab
|
|
130
|
+
|| name === VanillaOidc.eventNames.logout_from_same_tab
|
|
131
|
+
|| name == VanillaOidc.eventNames.refreshTokensAsync_error
|
|
132
|
+
|| name == VanillaOidc.eventNames.syncTokensAsync_error){
|
|
127
133
|
if(isMounted) {
|
|
128
134
|
const tokens = oidc.tokens;
|
|
129
135
|
setIDToken(tokens != null ? {idToken: tokens.idToken, idTokenPayload:tokens.idTokenPayload} : idTokenInitialState);
|
package/src/oidc/User.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useState} from "react";
|
|
2
|
-
import
|
|
2
|
+
import {VanillaOidc} from "./vanilla/vanillaOidc";
|
|
3
3
|
|
|
4
4
|
export enum OidcUserStatus {
|
|
5
5
|
Unauthenticated= 'Unauthenticated',
|
|
@@ -16,10 +16,9 @@ export type OidcUser = {
|
|
|
16
16
|
export const useOidcUser = (configurationName="default") => {
|
|
17
17
|
const [oidcUser, setOidcUser] = useState<OidcUser>({user: null, status: OidcUserStatus.Unauthenticated});
|
|
18
18
|
|
|
19
|
-
const oidc =
|
|
19
|
+
const oidc = VanillaOidc.get(configurationName);
|
|
20
20
|
useEffect(() => {
|
|
21
21
|
let isMounted = true;
|
|
22
|
-
|
|
23
22
|
if(oidc && oidc.tokens) {
|
|
24
23
|
setOidcUser({...oidcUser, status: OidcUserStatus.Loading});
|
|
25
24
|
oidc.userInfoAsync()
|
|
@@ -30,7 +29,6 @@ export const useOidcUser = (configurationName="default") => {
|
|
|
30
29
|
})
|
|
31
30
|
.catch(() => setOidcUser({...oidcUser, status: OidcUserStatus.LoadingError}));
|
|
32
31
|
}
|
|
33
|
-
|
|
34
32
|
return () => { isMounted = false };
|
|
35
33
|
}, []);
|
|
36
34
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, {useEffect, useState, ComponentType} from 'react';
|
|
2
2
|
import AuthenticatingError from "./AuthenticateError.component";
|
|
3
|
-
import
|
|
3
|
+
import {VanillaOidc} from "../../vanilla/vanillaOidc";
|
|
4
4
|
import {getCustomHistory} from "../routes/withRouter";
|
|
5
5
|
|
|
6
6
|
export const CallBackSuccess: ComponentType<any> = () => (<div className="oidc-callback">
|
|
@@ -16,9 +16,9 @@ const CallbackManager: ComponentType<any> = ({callBackError, callBackSuccess, co
|
|
|
16
16
|
useEffect(() => {
|
|
17
17
|
let isMounted = true;
|
|
18
18
|
const playCallbackAsync = async () => {
|
|
19
|
-
const getOidc =
|
|
19
|
+
const getOidc = VanillaOidc.get;
|
|
20
20
|
try {
|
|
21
|
-
const {callbackPath} = await getOidc(configurationName).
|
|
21
|
+
const {callbackPath} = await getOidc(configurationName).loginCallbackAsync();
|
|
22
22
|
const history = (withCustomHistory)? withCustomHistory(): getCustomHistory();
|
|
23
23
|
history.replaceState(callbackPath || "/")
|
|
24
24
|
} catch (error) {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import React, {useEffect, ComponentType} from 'react';
|
|
2
|
-
import
|
|
2
|
+
import {VanillaOidc} from "../../vanilla/vanillaOidc"
|
|
3
3
|
|
|
4
4
|
const CallbackManager: ComponentType<any> = ({configurationName }) => {
|
|
5
5
|
|
|
6
6
|
useEffect(() => {
|
|
7
7
|
let isMounted = true;
|
|
8
8
|
const playCallbackAsync = async () => {
|
|
9
|
-
const getOidc =
|
|
9
|
+
const getOidc = VanillaOidc.get;
|
|
10
10
|
const oidc = getOidc(configurationName);
|
|
11
|
-
oidc.
|
|
11
|
+
oidc.silentLoginCallbackAsync();
|
|
12
12
|
};
|
|
13
13
|
playCallbackAsync();
|
|
14
14
|
return () => {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React, {useEffect, ComponentType} from 'react';
|
|
2
|
-
import
|
|
2
|
+
import {VanillaOidc} from "../../vanilla/vanillaOidc";
|
|
3
3
|
import {getParseQueryStringFromLocation} from "../../vanilla/route-utils";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
const SilentLogin: ComponentType<any> = (({configurationName }) => {
|
|
7
7
|
const queryParams = getParseQueryStringFromLocation(window.location.href);
|
|
8
8
|
|
|
9
|
-
const getOidc =
|
|
9
|
+
const getOidc = VanillaOidc.get;
|
|
10
10
|
const oidc = getOidc(configurationName);
|
|
11
11
|
|
|
12
12
|
let extras = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { VanillaOidc } from './vanillaOidc';
|
|
@@ -45,6 +45,11 @@ const keepAlive = () => {
|
|
|
45
45
|
} catch (error){console.log(error)}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/*window.addEventListener('error', (event) => {
|
|
49
|
+
var textContent = `${event.type}: ${event.message}\n`;
|
|
50
|
+
console.log(textContent)
|
|
51
|
+
});*/
|
|
52
|
+
|
|
48
53
|
const isServiceWorkerProxyActiveAsync = () => {
|
|
49
54
|
try {
|
|
50
55
|
return fetch('/OidcKeepAliveServiceWorker.json', {
|
|
@@ -2,8 +2,7 @@ import {BasicQueryStringUtils} from '@openid/appauth';
|
|
|
2
2
|
|
|
3
3
|
export class NoHashQueryStringUtils extends BasicQueryStringUtils {
|
|
4
4
|
parse(input, useHash) {
|
|
5
|
-
|
|
6
|
-
return output;
|
|
5
|
+
return super.parse(input, false /* never use hash */);
|
|
7
6
|
}
|
|
8
7
|
}
|
|
9
8
|
|