@snokam/auth 2.0.42 → 2.0.44
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/CHANGELOG.md +22 -0
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.0.44](https://github.com/snokam/components/compare/@snokam/auth@2.0.43...@snokam/auth@2.0.44) (2025-01-17)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* add inherit color ([d51bae9](https://github.com/snokam/components/commit/d51bae9a35373b8be946865870a1c9b89d21af98))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [2.0.43](https://github.com/snokam/components/compare/@snokam/auth@2.0.42...@snokam/auth@2.0.43) (2025-01-17)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* export color and base color ([e85a72c](https://github.com/snokam/components/commit/e85a72c229f6e17e83b2c3e8cdd73c286a498efa))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
## [2.0.42](https://github.com/snokam/components/compare/@snokam/auth@2.0.41...@snokam/auth@2.0.42) (2025-01-16)
|
|
7
29
|
|
|
8
30
|
**Note:** Version bump only for package @snokam/auth
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.snokam=t():e.snokam=t()}(this,(()=>(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Authenticated:()=>r.AuthenticatedTemplate,Unauthenticated:()=>r.UnauthenticatedTemplate,default:()=>
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.snokam=t():e.snokam=t()}(this,(()=>(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Authenticated:()=>r.AuthenticatedTemplate,Unauthenticated:()=>r.UnauthenticatedTemplate,default:()=>y,useAuth:()=>d});const n=require("react/jsx-runtime"),r=require("@azure/msal-react"),o=require("@azure/msal-browser"),i=require("next/router"),s=require("react"),c="redirect",a=()=>{window.sessionStorage.setItem(c,window.location.pathname)},l=require("@snokam/core"),u=require("@mui/material"),d=()=>{const{instance:e,inProgress:t}=(0,r.useMsal)(),n=e.getAllAccounts()[0];return{getToken:t=>e.acquireTokenSilent({scopes:t||[],account:n}).then((({accessToken:e})=>`Bearer ${e}`)),isAuthenticated:(0,r.useIsAuthenticated)(),inProgress:"startup"===t||"login"===t,instance:e,account:n}},g={scopes:["openid"]},p=require("@emotion/styled");var m=e.n(p);const f={Container:m().div`
|
|
2
2
|
display: flex;
|
|
3
3
|
flex-direction: column;
|
|
4
4
|
justify-content: center;
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
flex: 1;
|
|
7
7
|
`,Link:m().a`
|
|
8
8
|
text-decoration: "underline";
|
|
9
|
-
`},
|
|
9
|
+
`},h=()=>{const{instance:e}=(0,r.useMsal)(),{account:t}=d(),[o,i]=(0,s.useState)();return o?(0,n.jsxs)(f.Container,{children:[(0,n.jsxs)("p",{children:["En feil oppstod: ",o.errorCode]}),(0,n.jsxs)("span",{children:["Prøv å gå direkte til ",(0,n.jsx)(f.Link,{target:"_blank",href:"https://skjer.snokam.no/?enforceLogin=true",rel:"noopener noreferrer",children:"skjer.snokam.no"}),"."]})]}):(0,n.jsxs)(f.Container,{children:["Du må logge inn på nytt for å vise siden",(0,n.jsx)(u.Button,{sx:{marginTop:"1rem"},onClick:()=>{a(),e.loginPopup(Object.assign(Object.assign(Object.assign({},g),t&&{account:t}),{redirectUri:"/blank.html"})).then((()=>i(void 0))).catch((e=>i(e)))},children:"Fortsett"})]})},j=e=>{const{children:t,loader:s}=e,{query:c}=(0,i.useRouter)(),u=c.username,d=(null==c?void 0:c.enforceLogin)&&(null==c?void 0:c.username)?o.InteractionType.Silent:o.InteractionType.Redirect,p=Object.assign(Object.assign(Object.assign({},g),u&&{loginHint:u}),{onRedirectNavigate:e=>{a()}});return(0,n.jsx)(r.MsalAuthenticationTemplate,{interactionType:d,authenticationRequest:p,errorComponent:h,loadingComponent:()=>(0,n.jsx)(l.PageLoader,{color:s.color}),children:t})},b=e=>{const{children:t,enforceLogin:c}=e,{query:a}=(0,i.useRouter)(),l=(0,s.useRef)(null);if(!l.current){const t={auth:{clientId:e.config.clientId,authority:`https://login.microsoftonline.com/${e.config.tenantId}/`,postLogoutRedirectUri:"/",redirectUri:"/callback",navigateToLoginRequestUrl:!1},system:{allowRedirectInIframe:!0},cache:{storeAuthStateInCookie:!0,cacheLocation:"localStorage"}};l.current=new o.PublicClientApplication(t),l.current.initialize()}const u=l.current;return a.enforceLogin||c?(0,n.jsx)(r.MsalProvider,{instance:u,children:(0,n.jsx)(j,Object.assign({},e,{children:t}))}):(0,n.jsx)(r.MsalProvider,{instance:u,children:t})};b.Callback=()=>{const e=(0,i.useRouter)();return(0,s.useEffect)((()=>{const t=window.sessionStorage.getItem(c);t?(window.sessionStorage.removeItem(c),console.log(`Redirecting to ${t} ...`),e.replace(t)):e.replace("/")}),[e]),(0,n.jsx)(l.PageLoader,{})};const y={Provider:b,Authenticate:j};return t})()));
|
|
10
10
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAgB,OAAID,IAEpBD,EAAa,OAAIC,GAClB,CATD,CASGK,MAAM,I,mBCRT,IAAIC,EAAsB,CCA1BA,EAAyBJ,IACxB,IAAIK,EAASL,GAAUA,EAAOM,WAC7B,IAAON,EAAiB,QACxB,IAAM,EAEP,OADAI,EAAoBG,EAAEF,EAAQ,CAAEG,EAAGH,IAC5BA,CAAM,ECLdD,EAAwB,CAACL,EAASU,KACjC,IAAI,IAAIC,KAAOD,EACXL,EAAoBO,EAAEF,EAAYC,KAASN,EAAoBO,EAAEZ,EAASW,IAC5EE,OAAOC,eAAed,EAASW,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDN,EAAwB,CAACY,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFb,EAAyBL,IACH,oBAAXsB,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAed,EAASsB,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eA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MAAMa,EAAehB,EAAgBE,QACrC,OAAIxB,EAAMI,cAAgBA,GACd,SAAK,EAAAmC,aAAc,CAAE5E,SAAU2E,EAAcxD,UAAU,SAAKe,EAAcvD,OAAOkD,OAAO,CAAC,EAAGM,EAAO,CAAEhB,SAAUA,QAEpH,SAAK,EAAAyD,aAAc,CAAE5E,SAAU2E,EAAcxD,SAAUA,GAAW,EAE7EuC,EAASmB,SC/Be,KACpB,MAAMC,GAAS,IAAAxC,aAYf,OAXA,IAAAyC,YAAU,KACN,MAAMC,EXJHtF,OAAOC,eAAesF,QAAQzF,GWK7BwF,GXFRtF,OAAOC,eAAeuF,WAAW1F,GWIzB2F,QAAQC,IAAI,kBAAkBJ,SAC9BF,EAAOO,QAAQL,IAGfF,EAAOO,QAAQ,IACnB,GACD,CAACP,KACG,SAAK,EAAAxB,WAAY,CAAEC,MAAO,EAAAC,MAAMC,UAAW,EDmBtD,MElCA,GAAiBC,SAAQ,eAAc,G","sources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/webpack/bootstrap","webpack://snokam/webpack/runtime/compat get default export","webpack://snokam/webpack/runtime/define property getters","webpack://snokam/webpack/runtime/hasOwnProperty shorthand","webpack://snokam/webpack/runtime/make namespace object","webpack://snokam/external commonjs \"react/jsx-runtime\"","webpack://snokam/external commonjs \"@azure/msal-react\"","webpack://snokam/external commonjs \"@azure/msal-browser\"","webpack://snokam/external commonjs \"next/router\"","webpack://snokam/external commonjs \"react\"","webpack://snokam/./src/storage.ts","webpack://snokam/external commonjs \"@snokam/core\"","webpack://snokam/external commonjs \"@mui/material\"","webpack://snokam/./src/hooks.ts","webpack://snokam/./src/config.ts","webpack://snokam/external commonjs \"@emotion/styled\"","webpack://snokam/./src/components/Provider/styled.tsx","webpack://snokam/./src/components/Provider/Provider.PopupLogin.tsx","webpack://snokam/external commonjs \"@snokam/core/theme\"","webpack://snokam/./src/components/Provider/Provider.Authenticate.tsx","webpack://snokam/./src/components/Provider/index.tsx","webpack://snokam/./src/components/Provider/Provider.Callback.tsx","webpack://snokam/./src/index.tsx"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"snokam\"] = factory();\n\telse\n\t\troot[\"snokam\"] = factory();\n})(this, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"react/jsx-runtime\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@azure/msal-react\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@azure/msal-browser\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next/router\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"react\");","const SessionStorageKey = \"redirect\";\nexport const storeCurrentPath = () => {\n window.sessionStorage.setItem(SessionStorageKey, window.location.pathname);\n};\nexport const getStoredPath = () => {\n return window.sessionStorage.getItem(SessionStorageKey);\n};\nexport const clearStoredPath = () => {\n window.sessionStorage.removeItem(SessionStorageKey);\n};\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@snokam/core\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@mui/material\");","import { useIsAuthenticated, useMsal } from \"@azure/msal-react\";\nexport const useAuth = () => {\n const { instance, inProgress } = useMsal();\n const account = instance.getAllAccounts()[0];\n const isAuthenticated = useIsAuthenticated();\n const getToken = (scopes) => instance\n .acquireTokenSilent({\n scopes: scopes || [],\n account: account,\n })\n .then(({ accessToken }) => `Bearer ${accessToken}`);\n return {\n getToken,\n isAuthenticated,\n inProgress: inProgress === \"startup\" || inProgress === \"login\",\n instance,\n account,\n };\n};\n","export const loginRequest = {\n scopes: [\"openid\"],\n};\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@emotion/styled\");","import styled from \"@emotion/styled\";\nconst Container = styled.div `\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n flex: 1;\n`;\nconst Link = styled.a `\n text-decoration: \"underline\";\n`;\nexport default { Container, Link };\n","import { jsxs as _jsxs, jsx as _jsx } from \"react/jsx-runtime\";\nimport { useMsal } from \"@azure/msal-react\";\nimport { Button } from \"@mui/material\";\nimport { storeCurrentPath } from \"../../storage\";\nimport { useState } from \"react\";\nimport { useAuth } from \"../../hooks\";\nimport { loginRequest } from \"../../config\";\nimport Styled from \"./styled\";\nexport const PopupLogin = () => {\n const { instance } = useMsal();\n const { account } = useAuth();\n const [popupError, setPopupError] = useState();\n if (popupError) {\n return (_jsxs(Styled.Container, { children: [_jsxs(\"p\", { children: [\"En feil oppstod: \", popupError.errorCode] }), _jsxs(\"span\", { children: [`Prøv å gå direkte til `, _jsx(Styled.Link, { target: \"_blank\", href: \"https://skjer.snokam.no/?enforceLogin=true\", rel: \"noopener noreferrer\", children: \"skjer.snokam.no\" }), \".\"] })] }));\n }\n return (_jsxs(Styled.Container, { children: [\"Du m\\u00E5 logge inn p\\u00E5 nytt for \\u00E5 vise siden\", _jsx(Button, { sx: { marginTop: \"1rem\" }, onClick: () => {\n storeCurrentPath();\n instance\n .loginPopup(Object.assign(Object.assign(Object.assign({}, loginRequest), (account && {\n account,\n })), { redirectUri: \"/blank.html\" }))\n .then(() => setPopupError(undefined))\n .catch((error) => setPopupError(error));\n }, children: \"Fortsett\" })] }));\n};\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@snokam/core/theme\");","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { MsalAuthenticationTemplate } from \"@azure/msal-react\";\nimport { InteractionType } from \"@azure/msal-browser\";\nimport { storeCurrentPath } from \"../../storage\";\nimport { useRouter } from \"next/router\";\nimport { PageLoader } from \"@snokam/core\";\nimport { PopupLogin } from \"./Provider.PopupLogin\";\nimport { loginRequest } from \"../../config\";\nimport { Color } from \"@snokam/core/theme\";\nexport const Authenticate = (props) => {\n const { children, loader } = props;\n const { query } = useRouter();\n const username = query.username;\n const interactionType = (query === null || query === void 0 ? void 0 : query.enforceLogin) && (query === null || query === void 0 ? void 0 : query.username)\n ? InteractionType.Silent\n : InteractionType.Redirect;\n const authRequest = Object.assign(Object.assign(Object.assign({}, loginRequest), (username && {\n loginHint: username,\n })), { onRedirectNavigate: (_) => {\n storeCurrentPath();\n } });\n const Loading = () => {\n var _a;\n return _jsx(PageLoader, { color: (_a = loader.color) !== null && _a !== void 0 ? _a : Color.DarkBlue });\n };\n return (_jsx(MsalAuthenticationTemplate, { interactionType: interactionType, authenticationRequest: authRequest, errorComponent: PopupLogin, loadingComponent: Loading, children: children }));\n};\n","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { MsalProvider } from \"@azure/msal-react\";\nimport { PublicClientApplication } from \"@azure/msal-browser\";\nimport { useRouter } from \"next/router\";\nimport { useRef } from \"react\";\nimport { Authenticate } from \"./Provider.Authenticate\";\nimport Callback from \"./Provider.Callback\";\nexport const Provider = (props) => {\n const { children, enforceLogin } = props;\n const { query } = useRouter();\n // Store msalInstance in a ref to ensure it initializes only once\n const msalInstanceRef = useRef(null);\n if (!msalInstanceRef.current) {\n const config = {\n auth: {\n clientId: props.config.clientId,\n authority: `https://login.microsoftonline.com/${props.config.tenantId}/`,\n postLogoutRedirectUri: \"/\",\n redirectUri: `/callback`,\n navigateToLoginRequestUrl: false,\n },\n system: {\n allowRedirectInIframe: true,\n },\n cache: {\n storeAuthStateInCookie: true,\n cacheLocation: \"localStorage\",\n },\n };\n msalInstanceRef.current = new PublicClientApplication(config);\n }\n const msalInstance = msalInstanceRef.current;\n if (query.enforceLogin || enforceLogin) {\n return (_jsx(MsalProvider, { instance: msalInstance, children: _jsx(Authenticate, Object.assign({}, props, { children: children })) }));\n }\n return _jsx(MsalProvider, { instance: msalInstance, children: children });\n};\nProvider.Callback = Callback;\nexport default Provider;\n","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useEffect } from \"react\";\nimport { useRouter } from \"next/router\";\nimport { clearStoredPath, getStoredPath } from \"../../storage\";\nimport { PageLoader } from \"@snokam/core\";\nimport { Color } from \"@snokam/core/theme\";\nexport const Callback = () => {\n const router = useRouter();\n useEffect(() => {\n const redirectUrl = getStoredPath();\n if (redirectUrl) {\n clearStoredPath();\n console.log(`Redirecting to ${redirectUrl} ...`);\n router.replace(redirectUrl);\n }\n else {\n router.replace(\"/\");\n }\n }, [router]);\n return _jsx(PageLoader, { color: Color.DarkBlue });\n};\nexport default Callback;\n","import { Provider } from \"./components/Provider\";\nimport { Authenticate } from \"./components/Provider/Provider.Authenticate\";\nexport { useAuth } from \"./hooks\";\nexport { AuthenticatedTemplate as Authenticated, UnauthenticatedTemplate as Unauthenticated, } from \"@azure/msal-react\";\nexport default { Provider, Authenticate };\n"],"names":["root","factory","exports","module","define","amd","this","__webpack_require__","getter","__esModule","d","a","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","require","SessionStorageKey","storeCurrentPath","window","sessionStorage","setItem","location","pathname","useAuth","instance","inProgress","useMsal","account","getAllAccounts","getToken","scopes","acquireTokenSilent","then","accessToken","isAuthenticated","useIsAuthenticated","loginRequest","Container","Link","PopupLogin","popupError","setPopupError","useState","children","errorCode","target","href","rel","Button","sx","marginTop","onClick","loginPopup","assign","redirectUri","undefined","catch","error","Authenticate","props","loader","query","useRouter","username","interactionType","enforceLogin","InteractionType","Silent","Redirect","authRequest","loginHint","onRedirectNavigate","_","MsalAuthenticationTemplate","authenticationRequest","errorComponent","loadingComponent","_a","PageLoader","color","Color","DarkBlue","Provider","msalInstanceRef","useRef","current","config","auth","clientId","authority","tenantId","postLogoutRedirectUri","navigateToLoginRequestUrl","system","allowRedirectInIframe","cache","storeAuthStateInCookie","cacheLocation","PublicClientApplication","msalInstance","MsalProvider","Callback","router","useEffect","redirectUrl","getItem","removeItem","console","log","replace"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAgB,OAAID,IAEpBD,EAAa,OAAIC,GAClB,CATD,CASGK,MAAM,I,mBCRT,IAAIC,EAAsB,CCA1BA,EAAyBJ,IACxB,IAAIK,EAASL,GAAUA,EAAOM,WAC7B,IAAON,EAAiB,QACxB,IAAM,EAEP,OADAI,EAAoBG,EAAEF,EAAQ,CAAEG,EAAGH,IAC5BA,CAAM,ECLdD,EAAwB,CAACL,EAASU,KACjC,IAAI,IAAIC,KAAOD,EACXL,EAAoBO,EAAEF,EAAYC,KAASN,EAAoBO,EAAEZ,EAASW,IAC5EE,OAAOC,eAAed,EAASW,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDN,EAAwB,CAACY,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFb,EAAyBL,IACH,oBAAXsB,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAed,EAASsB,OAAOC,YAAa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AAK,EAAAiC,aAAc,CAAE1E,SAAUyE,EAActD,UAAU,SAAKe,EAAcvD,OAAOkD,OAAO,CAAC,EAAGM,EAAO,CAAEhB,SAAUA,QAEpH,SAAK,EAAAuD,aAAc,CAAE1E,SAAUyE,EAActD,SAAUA,GAAW,EAE7EoC,EAASoB,SCjCe,KACpB,MAAMC,GAAS,IAAAtC,aAYf,OAXA,IAAAuC,YAAU,KACN,MAAMC,EVHHpF,OAAOC,eAAeoF,QAAQvF,GUI7BsF,GVDRpF,OAAOC,eAAeqF,WAAWxF,GUGzByF,QAAQC,IAAI,kBAAkBJ,SAC9BF,EAAOO,QAAQL,IAGfF,EAAOO,QAAQ,IACnB,GACD,CAACP,KACG,SAAK,EAAAvB,WAAY,CAAC,EAAE,EDqB/B,MEnCA,GAAiBE,SAAQ,eAAc,G","sources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/webpack/bootstrap","webpack://snokam/webpack/runtime/compat get default export","webpack://snokam/webpack/runtime/define property getters","webpack://snokam/webpack/runtime/hasOwnProperty shorthand","webpack://snokam/webpack/runtime/make namespace object","webpack://snokam/external commonjs \"react/jsx-runtime\"","webpack://snokam/external commonjs \"@azure/msal-react\"","webpack://snokam/external commonjs \"@azure/msal-browser\"","webpack://snokam/external commonjs \"next/router\"","webpack://snokam/external commonjs \"react\"","webpack://snokam/./src/storage.ts","webpack://snokam/external commonjs \"@snokam/core\"","webpack://snokam/external commonjs \"@mui/material\"","webpack://snokam/./src/hooks.ts","webpack://snokam/./src/config.ts","webpack://snokam/external commonjs \"@emotion/styled\"","webpack://snokam/./src/components/Provider/styled.tsx","webpack://snokam/./src/components/Provider/Provider.PopupLogin.tsx","webpack://snokam/./src/components/Provider/Provider.Authenticate.tsx","webpack://snokam/./src/components/Provider/index.tsx","webpack://snokam/./src/components/Provider/Provider.Callback.tsx","webpack://snokam/./src/index.tsx"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"snokam\"] = factory();\n\telse\n\t\troot[\"snokam\"] = factory();\n})(this, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"react/jsx-runtime\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@azure/msal-react\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@azure/msal-browser\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next/router\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"react\");","const SessionStorageKey = \"redirect\";\nexport const storeCurrentPath = () => {\n window.sessionStorage.setItem(SessionStorageKey, window.location.pathname);\n};\nexport const getStoredPath = () => {\n return window.sessionStorage.getItem(SessionStorageKey);\n};\nexport const clearStoredPath = () => {\n window.sessionStorage.removeItem(SessionStorageKey);\n};\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@snokam/core\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@mui/material\");","import { useIsAuthenticated, useMsal } from \"@azure/msal-react\";\nexport const useAuth = () => {\n const { instance, inProgress } = useMsal();\n const account = instance.getAllAccounts()[0];\n const isAuthenticated = useIsAuthenticated();\n const getToken = (scopes) => instance\n .acquireTokenSilent({\n scopes: scopes || [],\n account: account,\n })\n .then(({ accessToken }) => `Bearer ${accessToken}`);\n return {\n getToken,\n isAuthenticated,\n inProgress: inProgress === \"startup\" || inProgress === \"login\",\n instance,\n account,\n };\n};\n","export const loginRequest = {\n scopes: [\"openid\"],\n};\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@emotion/styled\");","import styled from \"@emotion/styled\";\nconst Container = styled.div `\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n flex: 1;\n`;\nconst Link = styled.a `\n text-decoration: \"underline\";\n`;\nexport default { Container, Link };\n","import { jsxs as _jsxs, jsx as _jsx } from \"react/jsx-runtime\";\nimport { useMsal } from \"@azure/msal-react\";\nimport { Button } from \"@mui/material\";\nimport { storeCurrentPath } from \"../../storage\";\nimport { useState } from \"react\";\nimport { useAuth } from \"../../hooks\";\nimport { loginRequest } from \"../../config\";\nimport Styled from \"./styled\";\nexport const PopupLogin = () => {\n const { instance } = useMsal();\n const { account } = useAuth();\n const [popupError, setPopupError] = useState();\n if (popupError) {\n return (_jsxs(Styled.Container, { children: [_jsxs(\"p\", { children: [\"En feil oppstod: \", popupError.errorCode] }), _jsxs(\"span\", { children: [`Prøv å gå direkte til `, _jsx(Styled.Link, { target: \"_blank\", href: \"https://skjer.snokam.no/?enforceLogin=true\", rel: \"noopener noreferrer\", children: \"skjer.snokam.no\" }), \".\"] })] }));\n }\n return (_jsxs(Styled.Container, { children: [\"Du m\\u00E5 logge inn p\\u00E5 nytt for \\u00E5 vise siden\", _jsx(Button, { sx: { marginTop: \"1rem\" }, onClick: () => {\n storeCurrentPath();\n instance\n .loginPopup(Object.assign(Object.assign(Object.assign({}, loginRequest), (account && {\n account,\n })), { redirectUri: \"/blank.html\" }))\n .then(() => setPopupError(undefined))\n .catch((error) => setPopupError(error));\n }, children: \"Fortsett\" })] }));\n};\n","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { MsalAuthenticationTemplate } from \"@azure/msal-react\";\nimport { InteractionType } from \"@azure/msal-browser\";\nimport { storeCurrentPath } from \"../../storage\";\nimport { useRouter } from \"next/router\";\nimport { PageLoader } from \"@snokam/core\";\nimport { PopupLogin } from \"./Provider.PopupLogin\";\nimport { loginRequest } from \"../../config\";\nexport const Authenticate = (props) => {\n const { children, loader } = props;\n const { query } = useRouter();\n const username = query.username;\n const interactionType = (query === null || query === void 0 ? void 0 : query.enforceLogin) && (query === null || query === void 0 ? void 0 : query.username)\n ? InteractionType.Silent\n : InteractionType.Redirect;\n const authRequest = Object.assign(Object.assign(Object.assign({}, loginRequest), (username && {\n loginHint: username,\n })), { onRedirectNavigate: (_) => {\n storeCurrentPath();\n } });\n const Loading = () => {\n return _jsx(PageLoader, { color: loader.color });\n };\n return (_jsx(MsalAuthenticationTemplate, { interactionType: interactionType, authenticationRequest: authRequest, errorComponent: PopupLogin, loadingComponent: Loading, children: children }));\n};\n","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { MsalProvider } from \"@azure/msal-react\";\nimport { PublicClientApplication } from \"@azure/msal-browser\";\nimport { useRouter } from \"next/router\";\nimport { useRef } from \"react\";\nimport { Authenticate } from \"./Provider.Authenticate\";\nimport Callback from \"./Provider.Callback\";\nexport const Provider = (props) => {\n const { children, enforceLogin } = props;\n const { query } = useRouter();\n // Store msalInstance in a ref to ensure it initializes only once\n const msalInstanceRef = useRef(null);\n if (!msalInstanceRef.current) {\n const config = {\n auth: {\n clientId: props.config.clientId,\n authority: `https://login.microsoftonline.com/${props.config.tenantId}/`,\n postLogoutRedirectUri: \"/\",\n redirectUri: `/callback`,\n navigateToLoginRequestUrl: false,\n },\n system: {\n allowRedirectInIframe: true,\n },\n cache: {\n storeAuthStateInCookie: true,\n cacheLocation: \"localStorage\",\n },\n };\n msalInstanceRef.current = new PublicClientApplication(config);\n msalInstanceRef.current.initialize();\n }\n const msalInstance = msalInstanceRef.current;\n if (query.enforceLogin || enforceLogin) {\n return (_jsx(MsalProvider, { instance: msalInstance, children: _jsx(Authenticate, Object.assign({}, props, { children: children })) }));\n }\n return _jsx(MsalProvider, { instance: msalInstance, children: children });\n};\nProvider.Callback = Callback;\nexport default Provider;\n","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useEffect } from \"react\";\nimport { useRouter } from \"next/router\";\nimport { clearStoredPath, getStoredPath } from \"../../storage\";\nimport { PageLoader } from \"@snokam/core\";\nexport const Callback = () => {\n const router = useRouter();\n useEffect(() => {\n const redirectUrl = getStoredPath();\n if (redirectUrl) {\n clearStoredPath();\n console.log(`Redirecting to ${redirectUrl} ...`);\n router.replace(redirectUrl);\n }\n else {\n router.replace(\"/\");\n }\n }, [router]);\n return _jsx(PageLoader, {});\n};\nexport default Callback;\n","import { Provider } from \"./components/Provider\";\nimport { Authenticate } from \"./components/Provider/Provider.Authenticate\";\nexport { useAuth } from \"./hooks\";\nexport { AuthenticatedTemplate as Authenticated, UnauthenticatedTemplate as Unauthenticated, } from \"@azure/msal-react\";\nexport default { Provider, Authenticate };\n"],"names":["root","factory","exports","module","define","amd","this","__webpack_require__","getter","__esModule","d","a","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","require","SessionStorageKey","storeCurrentPath","window","sessionStorage","setItem","location","pathname","useAuth","instance","inProgress","useMsal","account","getAllAccounts","getToken","scopes","acquireTokenSilent","then","accessToken","isAuthenticated","useIsAuthenticated","loginRequest","Container","Link","PopupLogin","popupError","setPopupError","useState","children","errorCode","target","href","rel","Button","sx","marginTop","onClick","loginPopup","assign","redirectUri","undefined","catch","error","Authenticate","props","loader","query","useRouter","username","interactionType","enforceLogin","InteractionType","Silent","Redirect","authRequest","loginHint","onRedirectNavigate","_","MsalAuthenticationTemplate","authenticationRequest","errorComponent","loadingComponent","PageLoader","color","Provider","msalInstanceRef","useRef","current","config","auth","clientId","authority","tenantId","postLogoutRedirectUri","navigateToLoginRequestUrl","system","allowRedirectInIframe","cache","storeAuthStateInCookie","cacheLocation","PublicClientApplication","initialize","msalInstance","MsalProvider","Callback","router","useEffect","redirectUrl","getItem","removeItem","console","log","replace"],"sourceRoot":""}
|
package/lib/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snokam/auth",
|
|
3
3
|
"description": "Snøkam auth components",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.44",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@emotion/react": "^11.14.0",
|
|
31
31
|
"@emotion/styled": "^11.14.0",
|
|
32
32
|
"@mui/material": "^6.4.0",
|
|
33
|
-
"@snokam/core": "^1.3.
|
|
33
|
+
"@snokam/core": "^1.3.35"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"next": "*",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
]
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "a363b49937818e4c05d42aae1b730851b069755c"
|
|
61
61
|
}
|