@axa-fr/react-oidc
Advanced tools
Comparing version 7.22.18 to 7.22.19-alpha.1516
@@ -1,5 +0,8 @@ | ||
import { ComponentType } from 'react'; | ||
import { FC } from 'react'; | ||
declare const SilentCallbackManager: ComponentType<any>; | ||
export interface SilentCallbackProps { | ||
configurationName: string; | ||
} | ||
declare const SilentCallbackManager: FC<SilentCallbackProps>; | ||
export default SilentCallbackManager; | ||
//# sourceMappingURL=SilentCallback.component.d.ts.map |
@@ -6,5 +6,5 @@ export { useOidcFetch, withOidcFetch } from './FetchToken.js'; | ||
export { OidcUserStatus, useOidcUser } from './User.js'; | ||
export type { AuthorityConfiguration, Fetch, OidcConfiguration, StringMap, ILOidcLocation } from '@axa-fr/oidc-client'; | ||
export { TokenRenewMode, OidcClient, TokenAutomaticRenewMode, OidcLocation } from '@axa-fr/oidc-client'; | ||
export type { AuthorityConfiguration, Fetch, ILOidcLocation, OidcConfiguration, StringMap, } from '@axa-fr/oidc-client'; | ||
export type { OidcUserInfo } from '@axa-fr/oidc-client'; | ||
export { OidcClient, OidcLocation, TokenAutomaticRenewMode, TokenRenewMode, } from '@axa-fr/oidc-client'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { jsx as i, jsxs as E, Fragment as b } from "react/jsx-runtime"; | ||
import { jsx as i, jsxs as E, Fragment as m } from "react/jsx-runtime"; | ||
import { OidcClient as r, getParseQueryStringFromLocation as V, getPath as O, OidcLocation as M, getFetchDefault as X } from "@axa-fr/oidc-client"; | ||
@@ -6,3 +6,7 @@ import { OidcClient as Me, OidcLocation as De, TokenAutomaticRenewMode as xe, TokenRenewMode as We } from "@axa-fr/oidc-client"; | ||
const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithTokens(t, e)(...n), Oe = (t = null, s = x, e = !1) => (n) => (o) => { | ||
const { fetch: c } = ne(t || o.fetch, s, e); | ||
const { fetch: c } = ne( | ||
t || o.fetch, | ||
s, | ||
e | ||
); | ||
return /* @__PURE__ */ i(n, { ...o, fetch: c }); | ||
@@ -12,3 +16,7 @@ }, ne = (t = null, s = x, e = !1) => { | ||
return { fetch: ee( | ||
(l, a) => te(n, () => o(s), e)(l, a), | ||
(l, a) => te( | ||
n, | ||
() => o(s), | ||
e | ||
)(l, a), | ||
[n, s] | ||
@@ -22,7 +30,12 @@ ) }; | ||
/* @__PURE__ */ i("p", { className: "oidc-authenticating__content", children: "You will be redirected to the login page." }) | ||
] }) }), oe = () => Math.random().toString(36).substr(2, 6), ce = (t, s) => (e, n) => { | ||
] }) }), oe = () => Math.random().toString(36).slice(2, 8), ce = (t, s) => (e, n) => { | ||
if (typeof t.CustomEvent == "function") | ||
return new t.CustomEvent(e, n); | ||
const o = n || { bubbles: !1, cancelable: !1, detail: void 0 }, c = s.createEvent("CustomEvent"); | ||
return c.initCustomEvent(e, o.bubbles, o.cancelable, o.detail), c.prototype = t.Event.prototype, c; | ||
return c.initCustomEvent( | ||
e, | ||
o.bubbles, | ||
o.cancelable, | ||
o.detail | ||
), c.prototype = t.Event.prototype, c; | ||
}, re = (t, s, e) => ({ | ||
@@ -36,3 +49,8 @@ replaceState: (n, o) => { | ||
/* @__PURE__ */ i("p", { className: "oidc-callback__content", children: "You will be redirected to your application." }) | ||
] }) }), ae = ({ callBackError: t, callBackSuccess: s, configurationName: e, withCustomHistory: n }) => { | ||
] }) }), ae = ({ | ||
callBackError: t, | ||
callBackSuccess: s, | ||
configurationName: e, | ||
withCustomHistory: n | ||
}) => { | ||
const [o, c] = f(!1); | ||
@@ -63,6 +81,7 @@ v(() => { | ||
(async () => { | ||
const e = r.get; | ||
e(t).silentLoginCallbackAsync(); | ||
})(); | ||
}, []), /* @__PURE__ */ i(b, {})), he = ({ configurationName: t }) => { | ||
r.get(t).silentLoginCallbackAsync(); | ||
})().catch((e) => { | ||
console.error("Error during silent login callback:", e); | ||
}); | ||
}, [t]), null), he = ({ configurationName: t }) => { | ||
const s = V(window.location.href), e = r.get, n = e(t); | ||
@@ -74,3 +93,3 @@ let o = null; | ||
n.tokens || n.loginAsync(null, o, !0, s.scope); | ||
}, []), /* @__PURE__ */ i(b, {}); | ||
}, []), /* @__PURE__ */ i(m, {}); | ||
}, _e = ({ | ||
@@ -84,22 +103,33 @@ callbackErrorComponent: t, | ||
configurationName: l, | ||
withCustomHistory: a = null, | ||
location: d | ||
withCustomHistory: a = null | ||
}) => { | ||
const u = window ? O(window.location.href) : "", [_, h] = f(u); | ||
const d = window ? O(window.location.href) : "", [u, _] = f(d); | ||
v(() => { | ||
const g = () => h(O(window.location.href)); | ||
const g = () => _(O(window.location.href)); | ||
return g(), window.addEventListener("popstate", g, !1), () => window.removeEventListener("popstate", g, !1); | ||
}, []); | ||
const p = O(e); | ||
if (n && _ === O(n)) | ||
const h = O(e); | ||
if (n && u === O(n)) | ||
return /* @__PURE__ */ i(ke, { configurationName: l }); | ||
if (o && _ === O(o)) | ||
if (o && u === O(o)) | ||
return /* @__PURE__ */ i(he, { configurationName: l }); | ||
switch (_) { | ||
case p: | ||
return /* @__PURE__ */ i(ae, { callBackError: t, callBackSuccess: s, configurationName: l, withCustomHistory: a }); | ||
switch (u) { | ||
case h: | ||
return /* @__PURE__ */ i( | ||
ae, | ||
{ | ||
callBackError: t, | ||
callBackSuccess: s, | ||
configurationName: l, | ||
withCustomHistory: a | ||
} | ||
); | ||
default: | ||
return /* @__PURE__ */ i(b, { children: c }); | ||
return /* @__PURE__ */ i(m, { children: c }); | ||
} | ||
}, fe = Z.memo(_e), D = { name: "", data: null }, ve = ({ loadingComponent: t, children: s, configurationName: e }) => { | ||
}, fe = Z.memo(_e), D = { name: "", data: null }, ve = ({ | ||
loadingComponent: t, | ||
children: s, | ||
configurationName: e | ||
}) => { | ||
const [n, o] = f(!0), c = r.get, l = c(e); | ||
@@ -113,6 +143,6 @@ return v(() => { | ||
}; | ||
}, [e]), /* @__PURE__ */ i(b, { children: n ? /* @__PURE__ */ i(t, { configurationName: e }) : /* @__PURE__ */ i(b, { children: s }) }); | ||
}, [e]), /* @__PURE__ */ i(m, { children: n ? /* @__PURE__ */ i(t, { configurationName: e }) : /* @__PURE__ */ i(m, { children: s }) }); | ||
}, P = ({ isLoading: t, loadingComponent: s, children: e, configurationName: n }) => { | ||
const o = s; | ||
return t ? /* @__PURE__ */ i(o, { configurationName: n, children: e }) : /* @__PURE__ */ i(b, { children: e }); | ||
return t ? /* @__PURE__ */ i(o, { configurationName: n, children: e }) : /* @__PURE__ */ i(m, { children: e }); | ||
}, Pe = ({ | ||
@@ -131,11 +161,14 @@ children: t, | ||
onLogoutFromSameTab: h = null, | ||
withCustomHistory: p = null, | ||
onEvent: g = null, | ||
getFetch: y = null, | ||
withCustomHistory: g = null, | ||
onEvent: T = null, | ||
getFetch: p = null, | ||
location: S = null | ||
}) => { | ||
const w = (L = "default") => r.getOrCreate(y ?? X, S ?? new M())(s, L), [j, B] = f(!0), [z, C] = f(D), [K, $] = f("default"); | ||
const w = (L = "default") => r.getOrCreate(p ?? X, S ?? new M())( | ||
s, | ||
L | ||
), [j, B] = f(!0), [z, C] = f(D), [K, $] = f("default"); | ||
v(() => { | ||
const I = w(e).subscribeEvents((k, T) => { | ||
g && g(e, k, T); | ||
const I = w(e).subscribeEvents((k, b) => { | ||
T && T(e, k, b); | ||
}); | ||
@@ -145,4 +178,4 @@ return () => { | ||
}; | ||
}, [e, g]), v(() => { | ||
const I = w(e).subscribeEvents((k, T) => { | ||
}, [e, T]), v(() => { | ||
const I = w(e).subscribeEvents((k, b) => { | ||
if (k === r.eventNames.refreshTokensAsync_error || k === r.eventNames.syncTokensAsync_error) { | ||
@@ -153,3 +186,3 @@ if (u != null) { | ||
} | ||
C({ name: k, data: T }); | ||
C({ name: k, data: b }); | ||
} else if (k === r.eventNames.logout_from_another_tab) { | ||
@@ -160,5 +193,5 @@ if (_ != null) { | ||
} | ||
C({ name: k, data: T }); | ||
C({ name: k, data: b }); | ||
} else | ||
k === r.eventNames.logout_from_same_tab ? h != null && h() : k === r.eventNames.loginAsync_begin || k === r.eventNames.loginCallbackAsync_end || k === r.eventNames.loginAsync_error || k === r.eventNames.loginCallbackAsync_error ? C({ name: k, data: T }) : k === r.eventNames.service_worker_not_supported_by_browser && s.service_worker_only === !0 && C({ name: k, data: T }); | ||
k === r.eventNames.logout_from_same_tab ? h != null && h() : k === r.eventNames.loginAsync_begin || k === r.eventNames.loginCallbackAsync_end || k === r.eventNames.loginAsync_error || k === r.eventNames.loginCallbackAsync_error ? C({ name: k, data: b }) : k === r.eventNames.service_worker_not_supported_by_browser && s.service_worker_only === !0 && C({ name: k, data: b }); | ||
}); | ||
@@ -169,37 +202,82 @@ return $(e), B(!1), () => { | ||
}, [s, e]); | ||
const G = d, H = o, m = c, Q = l, J = a, A = j || K !== e, N = w(e); | ||
const G = d, H = o, y = c, Q = l, J = a, A = j || K !== e, N = w(e); | ||
switch (z.name) { | ||
case r.eventNames.service_worker_not_supported_by_browser: | ||
return /* @__PURE__ */ i(P, { loadingComponent: m, isLoading: A, configurationName: e, children: /* @__PURE__ */ i(Q, { configurationName: e }) }); | ||
return /* @__PURE__ */ i( | ||
P, | ||
{ | ||
loadingComponent: y, | ||
isLoading: A, | ||
configurationName: e, | ||
children: /* @__PURE__ */ i(Q, { configurationName: e }) | ||
} | ||
); | ||
case r.eventNames.loginAsync_begin: | ||
return /* @__PURE__ */ i(P, { loadingComponent: m, isLoading: A, configurationName: e, children: /* @__PURE__ */ i(H, { configurationName: e }) }); | ||
return /* @__PURE__ */ i( | ||
P, | ||
{ | ||
loadingComponent: y, | ||
isLoading: A, | ||
configurationName: e, | ||
children: /* @__PURE__ */ i(H, { configurationName: e }) | ||
} | ||
); | ||
case r.eventNames.loginAsync_error: | ||
case r.eventNames.loginCallbackAsync_error: | ||
return /* @__PURE__ */ i(P, { loadingComponent: m, isLoading: A, configurationName: e, children: /* @__PURE__ */ i(J, { configurationName: e }) }); | ||
return /* @__PURE__ */ i( | ||
P, | ||
{ | ||
loadingComponent: y, | ||
isLoading: A, | ||
configurationName: e, | ||
children: /* @__PURE__ */ i(J, { configurationName: e }) | ||
} | ||
); | ||
case r.eventNames.refreshTokensAsync_error: | ||
case r.eventNames.syncTokensAsync_error: | ||
case r.eventNames.logout_from_another_tab: | ||
return /* @__PURE__ */ i(P, { loadingComponent: m, isLoading: A, configurationName: e, children: /* @__PURE__ */ i(G, { configurationName: e }) }); | ||
return /* @__PURE__ */ i( | ||
P, | ||
{ | ||
loadingComponent: y, | ||
isLoading: A, | ||
configurationName: e, | ||
children: /* @__PURE__ */ i(G, { configurationName: e }) | ||
} | ||
); | ||
default: | ||
return /* @__PURE__ */ i(P, { loadingComponent: m, isLoading: A, configurationName: e, children: /* @__PURE__ */ i( | ||
fe, | ||
return /* @__PURE__ */ i( | ||
P, | ||
{ | ||
redirect_uri: N.configuration.redirect_uri, | ||
silent_redirect_uri: N.configuration.silent_redirect_uri, | ||
silent_login_uri: N.configuration.silent_login_uri, | ||
callbackSuccessComponent: n, | ||
callbackErrorComponent: a, | ||
authenticatingComponent: o, | ||
loadingComponent: y, | ||
isLoading: A, | ||
configurationName: e, | ||
withCustomHistory: p, | ||
location: S ?? new M(), | ||
children: /* @__PURE__ */ i(ve, { loadingComponent: m, configurationName: e, children: t }) | ||
children: /* @__PURE__ */ i( | ||
fe, | ||
{ | ||
redirect_uri: N.configuration.redirect_uri, | ||
silent_redirect_uri: N.configuration.silent_redirect_uri, | ||
silent_login_uri: N.configuration.silent_login_uri, | ||
callbackSuccessComponent: n, | ||
callbackErrorComponent: a, | ||
authenticatingComponent: o, | ||
configurationName: e, | ||
withCustomHistory: g, | ||
location: S ?? new M(), | ||
children: /* @__PURE__ */ i(ve, { loadingComponent: y, configurationName: e, children: t }) | ||
} | ||
) | ||
} | ||
) }); | ||
); | ||
} | ||
}, ge = ({ children: t, callbackPath: s = null, extras: e = null, configurationName: n = "default" }) => { | ||
}, ge = ({ | ||
children: t, | ||
callbackPath: s = null, | ||
extras: e = null, | ||
configurationName: n = "default" | ||
}) => { | ||
const o = r.get, c = o(n); | ||
return v(() => { | ||
c.tokens || c.loginAsync(s, e); | ||
}, [n, s, e]), c.tokens ? /* @__PURE__ */ i(b, { children: t }) : null; | ||
}, [n, s, e]), c.tokens ? /* @__PURE__ */ i(m, { children: t }) : null; | ||
}, Ee = (t, s = null, e = null, n = "default") => (o) => /* @__PURE__ */ i(ge, { callbackPath: s, extras: e, configurationName: n, children: /* @__PURE__ */ i(t, { ...o }) }), F = "default", U = (t, s) => { | ||
@@ -209,3 +287,5 @@ let e = !1; | ||
}, Se = (t = F) => { | ||
const s = r.get, [e, n] = f(U(s, t)); | ||
const s = r.get, [e, n] = f( | ||
U(s, t) | ||
); | ||
return v(() => { | ||
@@ -221,3 +301,9 @@ let a = !0; | ||
}; | ||
}, [t]), { login: (a = void 0, d = null, u = !1) => s(t).loginAsync(a, d, !1, void 0, u), logout: (a = void 0, d = null) => s(t).logoutAsync(a, d), renewTokens: async (a = null) => { | ||
}, [t]), { login: (a = void 0, d = null, u = !1) => s(t).loginAsync( | ||
a, | ||
d, | ||
!1, | ||
void 0, | ||
u | ||
), logout: (a = void 0, d = null) => s(t).logoutAsync(a, d), renewTokens: async (a = null) => { | ||
const d = await s(t).renewTokensAsync(a); | ||
@@ -257,3 +343,6 @@ return { | ||
const a = c.tokens; | ||
n({ accessToken: a.accessToken, accessTokenPayload: a.accessTokenPayload }); | ||
n({ | ||
accessToken: a.accessToken, | ||
accessTokenPayload: a.accessTokenPayload | ||
}); | ||
} | ||
@@ -263,7 +352,9 @@ const l = c.subscribeEvents((a, d) => { | ||
const u = c.tokens; | ||
n(u != null ? { | ||
accessToken: u.accessToken, | ||
accessTokenPayload: u.accessTokenPayload, | ||
generateDemonstrationOfProofOfPossessionAsync: ye(c, u) | ||
} : q); | ||
n( | ||
u != null ? { | ||
accessToken: u.accessToken, | ||
accessTokenPayload: u.accessTokenPayload, | ||
generateDemonstrationOfProofOfPossessionAsync: ye(c, u) | ||
} : q | ||
); | ||
} | ||
@@ -294,3 +385,5 @@ }); | ||
const u = c.tokens; | ||
n(u != null ? { idToken: u.idToken, idTokenPayload: u.idTokenPayload } : Y); | ||
n( | ||
u != null ? { idToken: u.idToken, idTokenPayload: u.idTokenPayload } : Y | ||
); | ||
} | ||
@@ -312,6 +405,6 @@ }); | ||
const h = r.get(t); | ||
let p = !0; | ||
let g = !0; | ||
if (h && h.tokens) { | ||
const y = l === d; | ||
if (y && h.userInfo()) | ||
const p = l === d; | ||
if (p && h.userInfo()) | ||
return; | ||
@@ -322,4 +415,4 @@ c({ | ||
/* Loading */ | ||
}), h.userInfoAsync(!y, s).then((S) => { | ||
p && c({ | ||
}), h.userInfoAsync(!p, s).then((S) => { | ||
g && c({ | ||
user: S, | ||
@@ -340,4 +433,4 @@ status: "User loaded" | ||
}); | ||
const g = h.subscribeEvents((y) => { | ||
(y === r.eventNames.logout_from_another_tab || y === r.eventNames.logout_from_same_tab) && p && c({ | ||
const T = h.subscribeEvents((p) => { | ||
(p === r.eventNames.logout_from_another_tab || p === r.eventNames.logout_from_same_tab) && g && c({ | ||
user: null, | ||
@@ -349,3 +442,3 @@ status: "Unauthenticated" | ||
return () => { | ||
p = !1, h.removeEventSubscription(g); | ||
g = !1, h.removeEventSubscription(T); | ||
}; | ||
@@ -352,0 +445,0 @@ }, [l]); |
@@ -1,2 +0,2 @@ | ||
import { Fetch, OidcConfiguration, OidcClient, ILOidcLocation } from '@axa-fr/oidc-client'; | ||
import { Fetch, ILOidcLocation, OidcClient, OidcConfiguration } from '@axa-fr/oidc-client'; | ||
import { ComponentType, FC, PropsWithChildren } from 'react'; | ||
@@ -3,0 +3,0 @@ import { CustomHistory } from './core/routes/withRouter.js'; |
@@ -8,9 +8,9 @@ // Add bellow trusted domains, access tokens will automatically injected to be send to | ||
const trustedDomains = { | ||
default: ['https://demo.duendesoftware.com', 'https://kdhttps.auth0.com'], | ||
config_classic: ['https://demo.duendesoftware.com'], | ||
config_without_silent_login: ['https://demo.duendesoftware.com'], | ||
config_without_refresh_token: ['https://demo.duendesoftware.com'], | ||
config_without_refresh_token_silent_login: ['https://demo.duendesoftware.com'], | ||
config_google: ['https://oauth2.googleapis.com', 'https://openidconnect.googleapis.com'], | ||
config_with_hash: ['https://demo.duendesoftware.com'], | ||
default: ['https://demo.duendesoftware.com', 'https://kdhttps.auth0.com'], | ||
config_classic: ['https://demo.duendesoftware.com'], | ||
config_without_silent_login: ['https://demo.duendesoftware.com'], | ||
config_without_refresh_token: ['https://demo.duendesoftware.com'], | ||
config_without_refresh_token_silent_login: ['https://demo.duendesoftware.com'], | ||
config_google: ['https://oauth2.googleapis.com', 'https://openidconnect.googleapis.com'], | ||
config_with_hash: ['https://demo.duendesoftware.com'], | ||
}; | ||
@@ -21,8 +21,11 @@ | ||
// scenarios which require it. For example, to send it via websocket connection. | ||
trustedDomains.config_show_access_token = { domains: ['https://demo.duendesoftware.com'], showAccessToken: true }; | ||
trustedDomains.config_show_access_token = { | ||
domains: ['https://demo.duendesoftware.com'], | ||
showAccessToken: true, | ||
}; | ||
// This example defines domains used by OIDC server separately from domains to which access tokens will be injected. | ||
trustedDomains.config_separate_oidc_access_token_domains = { | ||
oidcDomains: ['https://demo.duendesoftware.com'], | ||
accessTokenDomains: ['https://myapi'], | ||
oidcDomains: ['https://demo.duendesoftware.com'], | ||
accessTokenDomains: ['https://myapi'], | ||
}; |
{ | ||
"name": "@axa-fr/react-oidc", | ||
"version": "7.22.18", | ||
"version": "7.22.19-alpha.1516", | ||
"private": false, | ||
@@ -43,4 +43,4 @@ "type": "module", | ||
"dependencies": { | ||
"@axa-fr/oidc-client-service-worker": "7.22.18", | ||
"@axa-fr/oidc-client": "7.22.18" | ||
"@axa-fr/oidc-client-service-worker": "7.22.19-alpha.1516", | ||
"@axa-fr/oidc-client": "7.22.19-alpha.1516" | ||
}, | ||
@@ -47,0 +47,0 @@ "peerDependencies": { |
201
README.md
@@ -14,3 +14,2 @@ # @axa-fr/react-oidc | ||
<img src="https://raw.githubusercontent.com/AxaFrance/oidc-client/main/docs/img/introduction.gif" alt="Sample React Oicd"/> | ||
@@ -64,2 +63,3 @@ | ||
WARNING : If you use Service Worker mode, the OidcServiceWorker.js file should always be up to date with the version of the library. You may setup a postinstall script in your package.json file to update it at each npm install. For example : | ||
```sh | ||
@@ -71,2 +71,3 @@ "scripts": { | ||
``` | ||
If you need a very secure mode where refresh_token and access_token will be hide behind a service worker that will proxify requests. | ||
@@ -85,4 +86,4 @@ The only file you should edit is "OidcTrustedDomains.js". | ||
default: { | ||
oidcDomains :["https://demo.duendesoftware.com"], | ||
accessTokenDomains : ["https://www.myapi.com/users"] | ||
oidcDomains: ['https://demo.duendesoftware.com'], | ||
accessTokenDomains: ['https://www.myapi.com/users'], | ||
}, | ||
@@ -94,6 +95,6 @@ }; | ||
// scenarios which require it. For example, to send it via websocket connection. | ||
trustedDomains.config_show_access_token = { | ||
oidcDomains :["https://demo.duendesoftware.com"], | ||
accessTokenDomains : ["https://www.myapi.com/users"], | ||
showAccessToken: true, | ||
trustedDomains.config_show_access_token = { | ||
oidcDomains: ['https://demo.duendesoftware.com'], | ||
accessTokenDomains: ['https://www.myapi.com/users'], | ||
showAccessToken: true, | ||
// convertAllRequestsToCorsExceptNavigate: false, // default value is false | ||
@@ -105,3 +106,3 @@ // setAccessTokenToNavigateRequests: true, // default value is true | ||
trustedDomains.config_with_dpop = { | ||
domains: ["https://demo.duendesoftware.com"], | ||
domains: ['https://demo.duendesoftware.com'], | ||
demonstratingProofOfPossession: true, | ||
@@ -129,6 +130,5 @@ demonstratingProofOfPossessionOnlyWhenDpopHeaderPresent: true, // default value is false, inject DPOP token only when DPOP header is present | ||
trustedDomains.config_multi_tab_login = { | ||
domains: ["https://demo.duendesoftware.com"], | ||
allowMultiTabLogin: true | ||
domains: ['https://demo.duendesoftware.com'], | ||
allowMultiTabLogin: true, | ||
}; | ||
``` | ||
@@ -159,8 +159,8 @@ | ||
```javascript | ||
import React from "react"; | ||
import { render } from "react-dom"; | ||
import { BrowserRouter as Router } from "react-router-dom"; | ||
import { OidcProvider } from "@axa-fr/react-oidc"; | ||
import Header from "./Layout/Header"; | ||
import Routes from "./Router"; | ||
import React from 'react'; | ||
import { render } from 'react-dom'; | ||
import { BrowserRouter as Router } from 'react-router-dom'; | ||
import { OidcProvider } from '@axa-fr/react-oidc'; | ||
import Header from './Layout/Header'; | ||
import Routes from './Router'; | ||
@@ -171,11 +171,10 @@ // This configuration use hybrid mode | ||
const configuration = { | ||
client_id: "interactive.public.short", | ||
redirect_uri: window.location.origin + "/authentication/callback", | ||
silent_redirect_uri: | ||
window.location.origin + "/authentication/silent-callback", | ||
scope: "openid profile email api offline_access", // offline_access scope allow your client to retrieve the refresh_token | ||
authority: "https://demo.duendesoftware.com", | ||
service_worker_relative_url: "/OidcServiceWorker.js", // just comment that line to disable service worker mode | ||
client_id: 'interactive.public.short', | ||
redirect_uri: window.location.origin + '/authentication/callback', | ||
silent_redirect_uri: window.location.origin + '/authentication/silent-callback', | ||
scope: 'openid profile email api offline_access', // offline_access scope allow your client to retrieve the refresh_token | ||
authority: 'https://demo.duendesoftware.com', | ||
service_worker_relative_url: '/OidcServiceWorker.js', // just comment that line to disable service worker mode | ||
service_worker_only: false, | ||
demonstrating_proof_of_possession: false, | ||
demonstrating_proof_of_possession: false, | ||
}; | ||
@@ -192,3 +191,3 @@ | ||
render(<App />, document.getElementById("root")); | ||
render(<App />, document.getElementById('root')); | ||
``` | ||
@@ -227,3 +226,3 @@ | ||
service_worker_keep_alive_path: String, // default is "/" | ||
service_worker_only: Boolean, // default false | ||
service_worker_only: Boolean, // default false | ||
service_worker_activate: () => boolean, // you can take the control of the service worker default activation which use user agent string | ||
@@ -255,3 +254,3 @@ service_worker_update_require_callback: (registration:any, stopKeepAlive:Function) => Promise<void>, // callback called when service worker need to be updated, you can take the control of the update process | ||
interface DemonstratingProofOfPossessionConfiguration | ||
interface DemonstratingProofOfPossessionConfiguration | ||
{ | ||
@@ -289,4 +288,4 @@ generateKeyAlgorithm: RsaHashedKeyGenParams | EcKeyGenParams, | ||
```javascript | ||
import React from "react"; | ||
import { useOidc } from "./oidc"; | ||
import React from 'react'; | ||
import { useOidc } from './oidc'; | ||
@@ -301,11 +300,5 @@ export const Home = () => { | ||
<h5 className="card-title">Welcome !!!</h5> | ||
<p className="card-text"> | ||
React Demo Application protected by OpenId Connect | ||
</p> | ||
<p className="card-text">React Demo Application protected by OpenId Connect</p> | ||
{!isAuthenticated && ( | ||
<button | ||
type="button" | ||
className="btn btn-primary" | ||
onClick={() => login("/profile")} | ||
> | ||
<button type="button" className="btn btn-primary" onClick={() => login('/profile')}> | ||
Login | ||
@@ -315,7 +308,3 @@ </button> | ||
{isAuthenticated && ( | ||
<button | ||
type="button" | ||
className="btn btn-primary" | ||
onClick={() => logout()} | ||
> | ||
<button type="button" className="btn btn-primary" onClick={() => logout()}> | ||
logout | ||
@@ -325,7 +314,3 @@ </button> | ||
{isAuthenticated && ( | ||
<button | ||
type="button" | ||
className="btn btn-primary" | ||
onClick={() => renewTokens()} | ||
> | ||
<button type="button" className="btn btn-primary" onClick={() => renewTokens()}> | ||
renewTokens | ||
@@ -353,4 +338,4 @@ </button> | ||
```javascript | ||
import React from "react"; | ||
import { OidcSecure } from "@axa-fr/react-oidc"; | ||
import React from 'react'; | ||
import { OidcSecure } from '@axa-fr/react-oidc'; | ||
@@ -372,8 +357,8 @@ const AdminSecure = () => ( | ||
```javascript | ||
import React from "react"; | ||
import { Switch, Route } from "react-router-dom"; | ||
import { withOidcSecure } from "@axa-fr/react-oidc"; | ||
import Home from "../Pages/Home"; | ||
import Dashboard from "../Pages/Dashboard"; | ||
import Admin from "../Pages/Admin"; | ||
import React from 'react'; | ||
import { Switch, Route } from 'react-router-dom'; | ||
import { withOidcSecure } from '@axa-fr/react-oidc'; | ||
import Home from '../Pages/Home'; | ||
import Dashboard from '../Pages/Dashboard'; | ||
import Admin from '../Pages/Admin'; | ||
@@ -395,3 +380,3 @@ const Routes = () => ( | ||
```javascript | ||
import { useOidcAccessToken } from "@axa-fr/react-oidc"; | ||
import { useOidcAccessToken } from '@axa-fr/react-oidc'; | ||
@@ -408,7 +393,6 @@ const DisplayAccessToken = () => { | ||
<h5 className="card-title">Access Token</h5> | ||
<p style={{ color: "red", backgroundColor: "white" }}> | ||
Please consider to configure the ServiceWorker in order to protect | ||
your application from XSRF attacks. ""access_token" and | ||
"refresh_token" will never be accessible from your client side | ||
javascript. | ||
<p style={{ color: 'red', backgroundColor: 'white' }}> | ||
Please consider to configure the ServiceWorker in order to protect your application from | ||
XSRF attacks. ""access_token" and "refresh_token" will never be accessible from your | ||
client side javascript. | ||
</p> | ||
@@ -428,3 +412,3 @@ {<p className="card-text">{JSON.stringify(accessToken)}</p>} | ||
```javascript | ||
import { useOidcIdToken } from "@axa-fr/react-oidc"; | ||
import { useOidcIdToken } from '@axa-fr/react-oidc'; | ||
@@ -443,5 +427,3 @@ const DisplayIdToken = () => { | ||
{<p className="card-text">{JSON.stringify(idToken)}</p>} | ||
{idTokenPayload != null && ( | ||
<p className="card-text">{JSON.stringify(idTokenPayload)}</p> | ||
)} | ||
{idTokenPayload != null && <p className="card-text">{JSON.stringify(idTokenPayload)}</p>} | ||
</div> | ||
@@ -456,3 +438,3 @@ </div> | ||
```javascript | ||
import { useOidcUser, UserStatus } from "@axa-fr/react-oidc"; | ||
import { useOidcUser, UserStatus } from '@axa-fr/react-oidc'; | ||
@@ -488,4 +470,4 @@ const DisplayUserInfo = () => { | ||
```javascript | ||
import React, { useEffect, useState } from "react"; | ||
import { useOidcFetch, OidcSecure } from "@axa-fr/react-oidc"; | ||
import React, { useEffect, useState } from 'react'; | ||
import { useOidcFetch, OidcSecure } from '@axa-fr/react-oidc'; | ||
@@ -498,5 +480,3 @@ const DisplayUserInfo = ({ fetch }) => { | ||
const fetchUserInfoAsync = async () => { | ||
const res = await fetch( | ||
"https://demo.duendesoftware.com/connect/userinfo", | ||
); | ||
const res = await fetch('https://demo.duendesoftware.com/connect/userinfo'); | ||
if (res.status != 200) { | ||
@@ -508,3 +488,3 @@ return null; | ||
let isMounted = true; | ||
fetchUserInfoAsync().then((userInfo) => { | ||
fetchUserInfoAsync().then(userInfo => { | ||
if (isMounted) { | ||
@@ -529,5 +509,3 @@ setLoading(false); | ||
<h5 className="card-title">User information</h5> | ||
{oidcUser != null && ( | ||
<p className="card-text">{JSON.stringify(oidcUser)}</p> | ||
)} | ||
{oidcUser != null && <p className="card-text">{JSON.stringify(oidcUser)}</p>} | ||
</div> | ||
@@ -555,4 +533,4 @@ </div> | ||
```javascript | ||
import React, { useEffect, useState } from "react"; | ||
import { useOidcFetch, OidcSecure } from "@axa-fr/react-oidc"; | ||
import React, { useEffect, useState } from 'react'; | ||
import { useOidcFetch, OidcSecure } from '@axa-fr/react-oidc'; | ||
@@ -565,5 +543,3 @@ const DisplayUserInfo = ({ fetch }) => { | ||
const fetchUserInfoAsync = async () => { | ||
const res = await fetch( | ||
"https://demo.duendesoftware.com/connect/userinfo", | ||
); | ||
const res = await fetch('https://demo.duendesoftware.com/connect/userinfo'); | ||
if (res.status != 200) { | ||
@@ -575,3 +551,3 @@ return null; | ||
let isMounted = true; | ||
fetchUserInfoAsync().then((userInfo) => { | ||
fetchUserInfoAsync().then(userInfo => { | ||
if (isMounted) { | ||
@@ -596,5 +572,3 @@ setLoading(false); | ||
<h5 className="card-title">User information</h5> | ||
{oidcUser != null && ( | ||
<p className="card-text">{JSON.stringify(oidcUser)}</p> | ||
)} | ||
{oidcUser != null && <p className="card-text">{JSON.stringify(oidcUser)}</p>} | ||
</div> | ||
@@ -620,8 +594,8 @@ </div> | ||
```javascript | ||
import React from "react"; | ||
import { render } from "react-dom"; | ||
import { BrowserRouter as Router } from "react-router-dom"; | ||
import { OidcProvider } from "@axa-fr/react-oidc"; | ||
import Header from "./Layout/Header"; | ||
import Routes from "./Router"; | ||
import React from 'react'; | ||
import { render } from 'react-dom'; | ||
import { BrowserRouter as Router } from 'react-router-dom'; | ||
import { OidcProvider } from '@axa-fr/react-oidc'; | ||
import Header from './Layout/Header'; | ||
import Routes from './Router'; | ||
@@ -632,8 +606,8 @@ // This configuration use hybrid mode | ||
const configuration = { | ||
client_id: "interactive.public.short", | ||
redirect_uri: "http://localhost:4200/authentication/callback", | ||
silent_redirect_uri: "http://localhost:4200/authentication/silent-callback", | ||
scope: "openid profile email api offline_access", | ||
authority: "https://demo.identityserver.io", | ||
service_worker_relative_url: "/OidcServiceWorker.js", | ||
client_id: 'interactive.public.short', | ||
redirect_uri: 'http://localhost:4200/authentication/callback', | ||
silent_redirect_uri: 'http://localhost:4200/authentication/silent-callback', | ||
scope: 'openid profile email api offline_access', | ||
authority: 'https://demo.identityserver.io', | ||
service_worker_relative_url: '/OidcServiceWorker.js', | ||
service_worker_only: false, | ||
@@ -674,3 +648,3 @@ }; | ||
render(<App />, document.getElementById("root")); | ||
render(<App />, document.getElementById('root')); | ||
``` | ||
@@ -697,11 +671,11 @@ | ||
```javascript | ||
import { OidcProvider } from "@axa-fr/react-oidc"; | ||
import { useRouter } from "next/router"; | ||
import { OidcProvider } from '@axa-fr/react-oidc'; | ||
import { useRouter } from 'next/router'; | ||
const configuration = { | ||
client_id: "interactive.public.short", | ||
redirect_uri: "http://localhost:3001/#authentication/callback", | ||
silent_redirect_uri: "http://localhost:3001/#authentication/silent-callback", // Optional activate silent-login that use cookies between OIDC server and client javascript to restore the session | ||
scope: "openid profile email api offline_access", | ||
authority: "https://demo.duendesoftware.com", | ||
client_id: 'interactive.public.short', | ||
redirect_uri: 'http://localhost:3001/#authentication/callback', | ||
silent_redirect_uri: 'http://localhost:3001/#authentication/silent-callback', // Optional activate silent-login that use cookies between OIDC server and client javascript to restore the session | ||
scope: 'openid profile email api offline_access', | ||
authority: 'https://demo.duendesoftware.com', | ||
}; | ||
@@ -717,3 +691,3 @@ | ||
return { | ||
replaceState: (url) => { | ||
replaceState: url => { | ||
router | ||
@@ -724,3 +698,3 @@ .replace({ | ||
.then(() => { | ||
window.dispatchEvent(new Event("popstate")); | ||
window.dispatchEvent(new Event('popstate')); | ||
}); | ||
@@ -753,12 +727,11 @@ }, | ||
export const configurationIdentityServerWithHash = { | ||
client_id: "interactive.public.short", | ||
redirect_uri: window.location.origin + "#authentication-callback", | ||
silent_redirect_uri: | ||
window.location.origin + "#authentication-silent-callback", | ||
scope: "openid profile email api offline_access", | ||
authority: "https://demo.duendesoftware.com", | ||
client_id: 'interactive.public.short', | ||
redirect_uri: window.location.origin + '#authentication-callback', | ||
silent_redirect_uri: window.location.origin + '#authentication-silent-callback', | ||
scope: 'openid profile email api offline_access', | ||
authority: 'https://demo.duendesoftware.com', | ||
refresh_time_before_tokens_expiration_in_second: 70, | ||
service_worker_relative_url: "/OidcServiceWorker.js", | ||
service_worker_relative_url: '/OidcServiceWorker.js', | ||
service_worker_only: false, | ||
}; | ||
``` |
@@ -9,7 +9,12 @@ export { useOidcFetch, withOidcFetch } from './FetchToken.js'; | ||
Fetch, | ||
ILOidcLocation, | ||
OidcConfiguration, | ||
StringMap, | ||
ILOidcLocation | ||
} from '@axa-fr/oidc-client'; | ||
export { TokenRenewMode, OidcClient, TokenAutomaticRenewMode, OidcLocation } from '@axa-fr/oidc-client'; | ||
export type { OidcUserInfo } from '@axa-fr/oidc-client'; | ||
export type { OidcUserInfo } from '@axa-fr/oidc-client'; | ||
export { | ||
OidcClient, | ||
OidcLocation, | ||
TokenAutomaticRenewMode, | ||
TokenRenewMode, | ||
} from '@axa-fr/oidc-client'; |
110
src/User.ts
@@ -1,62 +0,72 @@ | ||
import { type OidcUserInfo, OidcClient } from '@axa-fr/oidc-client'; | ||
import { OidcClient, type OidcUserInfo } from '@axa-fr/oidc-client'; | ||
import { useEffect, useState } from 'react'; | ||
export enum OidcUserStatus { | ||
Unauthenticated= 'Unauthenticated', | ||
Loading = 'Loading user', | ||
Loaded = 'User loaded', | ||
LoadingError = 'Error loading user' | ||
Unauthenticated = 'Unauthenticated', | ||
Loading = 'Loading user', | ||
Loaded = 'User loaded', | ||
LoadingError = 'Error loading user', | ||
} | ||
export type OidcUser<T extends OidcUserInfo = OidcUserInfo> = { | ||
user: T | null; | ||
status: OidcUserStatus; | ||
} | ||
user: T | null; | ||
status: OidcUserStatus; | ||
}; | ||
export const useOidcUser = <T extends OidcUserInfo = OidcUserInfo>(configurationName = 'default', demonstrating_proof_of_possession=false) => { | ||
export const useOidcUser = <T extends OidcUserInfo = OidcUserInfo>( | ||
configurationName = 'default', | ||
demonstrating_proof_of_possession = false, | ||
) => { | ||
const oidc = OidcClient.get(configurationName); | ||
const user = oidc.userInfo<T>(); | ||
const [oidcUser, setOidcUser] = useState<OidcUser<T>>({ | ||
user: user, | ||
status: user ? OidcUserStatus.Loaded : OidcUserStatus.Unauthenticated, | ||
}); | ||
const [oidcUserId, setOidcUserId] = useState<number>(user ? 1 : 0); | ||
const [oidcPreviousUserId, setPreviousOidcUserId] = useState<number>(user ? 1 : 0); | ||
useEffect(() => { | ||
const oidc = OidcClient.get(configurationName); | ||
const user = oidc.userInfo<T>(); | ||
const [oidcUser, setOidcUser] = useState<OidcUser<T>>({ user: user, status: user ? OidcUserStatus.Loaded : OidcUserStatus.Unauthenticated }); | ||
const [oidcUserId, setOidcUserId] = useState<number>(user ? 1 : 0); | ||
const [oidcPreviousUserId, setPreviousOidcUserId] = useState<number>(user ? 1 : 0); | ||
useEffect(() => { | ||
const oidc = OidcClient.get(configurationName); | ||
let isMounted = true; | ||
if (oidc && oidc.tokens) { | ||
const isCache = oidcUserId === oidcPreviousUserId; | ||
if(isCache && oidc.userInfo<T>()) { | ||
return; | ||
} | ||
setOidcUser({ ...oidcUser, status: OidcUserStatus.Loading }); | ||
oidc.userInfoAsync(!isCache, demonstrating_proof_of_possession) | ||
.then((info) => { | ||
if (isMounted) { | ||
// @ts-ignore | ||
setOidcUser({ user: info, status: OidcUserStatus.Loaded }); | ||
} | ||
}) | ||
.catch(() => setOidcUser({ ...oidcUser, status: OidcUserStatus.LoadingError })); | ||
setPreviousOidcUserId(oidcUserId); | ||
} else { | ||
setOidcUser({ user: null, status: OidcUserStatus.Unauthenticated }); | ||
let isMounted = true; | ||
if (oidc && oidc.tokens) { | ||
const isCache = oidcUserId === oidcPreviousUserId; | ||
if (isCache && oidc.userInfo<T>()) { | ||
return; | ||
} | ||
setOidcUser({ ...oidcUser, status: OidcUserStatus.Loading }); | ||
oidc | ||
.userInfoAsync(!isCache, demonstrating_proof_of_possession) | ||
.then(info => { | ||
if (isMounted) { | ||
// @ts-ignore | ||
setOidcUser({ user: info, status: OidcUserStatus.Loaded }); | ||
} | ||
}) | ||
.catch(() => setOidcUser({ ...oidcUser, status: OidcUserStatus.LoadingError })); | ||
setPreviousOidcUserId(oidcUserId); | ||
} else { | ||
setOidcUser({ user: null, status: OidcUserStatus.Unauthenticated }); | ||
} | ||
const newSubscriptionId = oidc.subscribeEvents((name: string) => { | ||
if ( | ||
name === OidcClient.eventNames.logout_from_another_tab || | ||
name === OidcClient.eventNames.logout_from_same_tab | ||
) { | ||
if (isMounted) { | ||
setOidcUser({ user: null, status: OidcUserStatus.Unauthenticated }); | ||
} | ||
const newSubscriptionId = oidc.subscribeEvents((name: string) => { | ||
if (name === OidcClient.eventNames.logout_from_another_tab || name === OidcClient.eventNames.logout_from_same_tab) { | ||
if (isMounted) { | ||
setOidcUser({ user: null, status: OidcUserStatus.Unauthenticated }); | ||
} | ||
} | ||
}); | ||
return () => { | ||
isMounted = false; | ||
oidc.removeEventSubscription(newSubscriptionId); | ||
}; | ||
}, [oidcUserId]); | ||
const reloadOidcUser = () => { | ||
setOidcUserId(oidcUserId+1); | ||
} | ||
}); | ||
return () => { | ||
isMounted = false; | ||
oidc.removeEventSubscription(newSubscriptionId); | ||
}; | ||
}, [oidcUserId]); | ||
return { oidcUser: oidcUser.user, oidcUserLoadingState: oidcUser.status, reloadOidcUser }; | ||
const reloadOidcUser = () => { | ||
setOidcUserId(oidcUserId + 1); | ||
}; | ||
return { oidcUser: oidcUser.user, oidcUserLoadingState: oidcUser.status, reloadOidcUser }; | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1685
112611
3
700
+ Added@axa-fr/oidc-client@7.22.19-alpha.1516(transitive)
+ Added@axa-fr/oidc-client-service-worker@7.22.19-alpha.1516(transitive)
- Removed@axa-fr/oidc-client@7.22.18(transitive)
- Removed@axa-fr/oidc-client-service-worker@7.22.18(transitive)
Updated@axa-fr/oidc-client-service-worker@7.22.19-alpha.1516