@snokam/auth 2.1.1 → 2.1.2
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 +11 -0
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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.1.2](https://github.com/snokam/components/compare/@snokam/auth@2.1.1...@snokam/auth@2.1.2) (2025-05-28)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* hardcode snokam.no ([475d13f](https://github.com/snokam/components/commit/475d13f80128bbc68121bbd2a45bb0c97b514c35))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [2.1.1](https://github.com/snokam/components/compare/@snokam/auth@2.1.0...@snokam/auth@2.1.1) (2025-05-28)
|
|
7
18
|
|
|
8
19
|
|
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
|
|
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 o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},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:()=>o.AuthenticatedTemplate,Unauthenticated:()=>o.UnauthenticatedTemplate,default:()=>x,useAuth:()=>d});const n=require("react/jsx-runtime"),o=require("@azure/msal-react"),r=require("@azure/msal-browser"),i=require("next/router"),c=require("react"),a="redirect",s=()=>{window.sessionStorage.setItem(a,window.location.pathname)},u=require("@snokam/core"),l=require("@mui/material"),d=()=>{const{instance:e,inProgress:t}=(0,o.useMsal)(),n=e.getAllAccounts()[0];return{getToken:t=>e.acquireTokenSilent({scopes:t||[],account:n}).then((({accessToken:e})=>`Bearer ${e}`)),isAuthenticated:(0,o.useIsAuthenticated)(),inProgress:t===r.InteractionStatus.Startup||t===r.InteractionStatus.SsoSilent||t===r.InteractionStatus.Login,instance:e,account:n}},p={scopes:["openid"]},g=require("@emotion/styled");var h=e.n(g);const f={Container:h().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:h().a`
|
|
8
8
|
text-decoration: "underline";
|
|
9
|
-
`},m=()=>{const{instance:e}=(0,
|
|
9
|
+
`},m=()=>{const{instance:e}=(0,o.useMsal)(),{account:t}=d(),[r,i]=(0,c.useState)();return r?(0,n.jsxs)(f.Container,{children:[(0,n.jsxs)("p",{children:["En feil oppstod: ",r.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)(l.Button,{sx:{marginTop:"1rem",color:"inherit"},onClick:()=>{s(),e.loginPopup(Object.assign(Object.assign(Object.assign({},p),t&&{account:t}),{redirectUri:"/blank.html"})).then((()=>i(void 0))).catch((e=>i(e)))},children:"Fortsett"})]})},y=e=>{const{children:t,interactionType:c}=e,a=(0,i.useRouter)(),l=null==a?void 0:a.query,d=null==l?void 0:l.username,g=c,h=(null==l?void 0:l.enforceLogin)&&(null==l?void 0:l.username)?r.InteractionType.Silent:r.InteractionType.Redirect,f=Object.assign(Object.assign(Object.assign({},p),d&&{loginHint:d}),{domainHint:window.location.origin.includes("test.snokam.no")?"test.snokam.no":"snokam.no",onRedirectNavigate:e=>{s()}}),y=c===r.InteractionType.Silent?()=>t:m;return(0,n.jsx)(o.MsalAuthenticationTemplate,{interactionType:g||h,loadingComponent:()=>(0,n.jsx)(u.PageLoader,{}),authenticationRequest:f,errorComponent:y,children:t})};class j extends r.NavigationClient{constructor(e){super(),this.router=e}navigateInternal(e,t){return n=this,o=void 0,i=function*(){const n=e.replace(window.location.origin,"");return t.noHistory?this.router.replace(n):this.router.push(n),!1},new((r=void 0)||(r=Promise))((function(e,t){function c(e){try{s(i.next(e))}catch(e){t(e)}}function a(e){try{s(i.throw(e))}catch(e){t(e)}}function s(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r((function(e){e(n)}))).then(c,a)}s((i=i.apply(n,o||[])).next())}));var n,o,r,i}}const v=e=>{const{children:t,enforceLogin:a}=e,s=(0,i.useRouter)(),u=null==s?void 0:s.query,l=(0,c.useRef)(null),d=(0,c.useRef)(null);if(!l.current){const t={auth:{instanceAware:!0,clientId:e.config.clientId,authority:`https://login.microsoftonline.com/${e.config.tenantId}/`,postLogoutRedirectUri:"/",redirectUri:"/callback",navigateToLoginRequestUrl:!1},system:{allowRedirectInIframe:!0},cache:{cacheLocation:"localStorage"}};l.current=new r.PublicClientApplication(t),s&&(d.current=new j(s),l.current.setNavigationClient(d.current)),l.current.initialize()}const p=l.current;return(null==u?void 0:u.enforceLogin)||a?(0,n.jsx)(o.MsalProvider,{instance:p,children:(0,n.jsx)(y,Object.assign({},e,{children:t}))}):(0,n.jsx)(o.MsalProvider,{instance:p,children:(0,n.jsx)(y,{interactionType:r.InteractionType.Silent,children:t})})};v.Callback=()=>{const e=(0,i.useRouter)();return(0,c.useEffect)((()=>{const t=window.sessionStorage.getItem(a);t?(window.sessionStorage.removeItem(a),console.log(`Redirecting to ${t} ...`),e.replace(t)):e.replace("/")}),[e]),(0,n.jsx)(u.PageLoader,{})};const x={Provider:v,Authenticate:y};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,eAAed,EAAS,aAAc,CA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D,aAAqC,EAASA,EAAMI,eAAiBA,GAC9D,SAAK,EAAAgE,aAAc,CAAEhH,SAAU+G,EAAcxF,UAAU,SAAKgB,EAAc5D,OAAOuD,OAAO,CAAC,EAAGM,EAAO,CAAEjB,SAAUA,QAEnH,SAAK,EAAAyF,aAAc,CAAEhH,SAAU+G,EAAcxF,UAAU,SAAKgB,EAAc,CAAEE,gBAAiB,EAAAQ,gBAAgBC,OAAQ3B,SAAUA,KAAe,EAE1JoE,EAASsB,SCxCe,KACpB,MAAMvE,GAAS,IAAAC,aAYf,OAXA,IAAAuE,YAAU,KACN,MAAMC,EXHHzH,OAAOC,eAAeyH,QAAQ5H,GWI7B2H,GXDRzH,OAAOC,eAAe0H,WAAW7H,GWGzB8H,QAAQC,IAAI,kBAAkBJ,SAC9BzE,EAAOiC,QAAQwC,IAGfzE,EAAOiC,QAAQ,IACnB,GACD,CAACjC,KACG,SAAK,EAAAmB,WAAY,CAAC,EAAE,ED4B/B,ME1CA,GAAiB8B,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.LoginError.tsx","webpack://snokam/./src/components/Provider/Provider.Authenticate.tsx","webpack://snokam/./src/components/Provider/NavigationClient.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 { InteractionStatus } from \"@azure/msal-browser\";\nimport { 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 === InteractionStatus.Startup ||\n inProgress === InteractionStatus.SsoSilent ||\n inProgress === InteractionStatus.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 LoginError = () => {\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\", color: \"inherit\" }, 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 { storeCurrentPath } from \"../../storage\";\nimport { useRouter } from \"next/router\";\nimport { PageLoader } from \"@snokam/core\";\nimport { LoginError } from \"./Provider.LoginError\";\nimport { loginRequest } from \"../../config\";\nimport { InteractionType, } from \"@azure/msal-browser\";\nexport const Authenticate = (props) => {\n const { children, interactionType } = props;\n const router = useRouter();\n const query = router === null || router === void 0 ? void 0 : router.query;\n const username = query === null || query === void 0 ? void 0 : query.username;\n const manualInteractionType = interactionType;\n const autoInteractionType = (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 })), { domainHint: window.location.host, onRedirectNavigate: (_) => {\n storeCurrentPath();\n } });\n const Error = interactionType === InteractionType.Silent ? () => children : LoginError;\n return (_jsx(MsalAuthenticationTemplate, { interactionType: manualInteractionType || autoInteractionType, loadingComponent: () => _jsx(PageLoader, {}), authenticationRequest: authRequest, errorComponent: Error, children: children }));\n};\n","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport { NavigationClient } from \"@azure/msal-browser\";\n/**\n * This is an example for overriding the default function MSAL uses to navigate to other urls in your webpage\n */\nexport class CustomNavigationClient extends NavigationClient {\n constructor(router) {\n super();\n this.router = router;\n }\n /**\n * Navigates to other pages within the same web application\n * You can use the useRouter hook provided by next.js to take advantage of client-side routing\n * @param url\n * @param options\n */\n navigateInternal(url, options) {\n return __awaiter(this, void 0, void 0, function* () {\n const relativePath = url.replace(window.location.origin, \"\");\n if (options.noHistory) {\n this.router.replace(relativePath);\n }\n else {\n this.router.push(relativePath);\n }\n return false;\n });\n }\n}\n","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { MsalProvider } from \"@azure/msal-react\";\nimport { InteractionType, PublicClientApplication, } from \"@azure/msal-browser\";\nimport { useRouter } from \"next/router\";\nimport { useRef } from \"react\";\nimport { Authenticate } from \"./Provider.Authenticate\";\nimport Callback from \"./Provider.Callback\";\nimport { CustomNavigationClient } from \"./NavigationClient\";\nexport const Provider = (props) => {\n const { children, enforceLogin } = props;\n const router = useRouter();\n const query = router === null || router === void 0 ? void 0 : router.query;\n // Store msalInstance in a ref to ensure it initializes only once\n const msalInstanceRef = useRef(null);\n const navigationClientRef = useRef(null);\n if (!msalInstanceRef.current) {\n const config = {\n auth: {\n instanceAware: true,\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 cacheLocation: \"localStorage\",\n },\n };\n msalInstanceRef.current = new PublicClientApplication(config);\n if (router) {\n navigationClientRef.current = new CustomNavigationClient(router);\n msalInstanceRef.current.setNavigationClient(navigationClientRef.current);\n }\n msalInstanceRef.current.initialize();\n }\n const msalInstance = msalInstanceRef.current;\n if ((query === null || query === void 0 ? void 0 : 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: _jsx(Authenticate, { interactionType: InteractionType.Silent, 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","InteractionStatus","Startup","SsoSilent","Login","loginRequest","Container","Link","LoginError","popupError","setPopupError","useState","children","errorCode","target","href","rel","Button","sx","marginTop","color","onClick","loginPopup","assign","redirectUri","undefined","catch","error","Authenticate","props","interactionType","router","useRouter","query","username","manualInteractionType","autoInteractionType","enforceLogin","InteractionType","Silent","Redirect","authRequest","loginHint","domainHint","host","onRedirectNavigate","_","Error","MsalAuthenticationTemplate","loadingComponent","PageLoader","authenticationRequest","errorComponent","CustomNavigationClient","NavigationClient","constructor","super","navigateInternal","url","options","thisArg","_arguments","generator","relativePath","replace","origin","noHistory","push","P","Promise","resolve","reject","fulfilled","step","next","e","rejected","result","done","apply","Provider","msalInstanceRef","useRef","navigationClientRef","current","config","auth","instanceAware","clientId","authority","tenantId","postLogoutRedirectUri","navigateToLoginRequestUrl","system","allowRedirectInIframe","cache","cacheLocation","PublicClientApplication","setNavigationClient","initialize","msalInstance","MsalProvider","Callback","useEffect","redirectUrl","getItem","removeItem","console","log"],"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,CAAEC,MAAO,WAE7DX,OAAOC,eAAed,EAAS,aAAc,CAAEwB,OAAO,GAAO,G,yICL9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KnD,aAAqC,EAASA,EAAMI,eAAiBA,GAC9D,SAAK,EAAAgE,aAAc,CAAEhH,SAAU+G,EAAcxF,UAAU,SAAKgB,EAAc5D,OAAOuD,OAAO,CAAC,EAAGM,EAAO,CAAEjB,SAAUA,QAEnH,SAAK,EAAAyF,aAAc,CAAEhH,SAAU+G,EAAcxF,UAAU,SAAKgB,EAAc,CAAEE,gBAAiB,EAAAQ,gBAAgBC,OAAQ3B,SAAUA,KAAe,EAE1JoE,EAASsB,SCxCe,KACpB,MAAMvE,GAAS,IAAAC,aAYf,OAXA,IAAAuE,YAAU,KACN,MAAMC,EXHHzH,OAAOC,eAAeyH,QAAQ5H,GWI7B2H,GXDRzH,OAAOC,eAAe0H,WAAW7H,GWGzB8H,QAAQC,IAAI,kBAAkBJ,SAC9BzE,EAAOkC,QAAQuC,IAGfzE,EAAOkC,QAAQ,IACnB,GACD,CAAClC,KACG,SAAK,EAAAoB,WAAY,CAAC,EAAE,ED4B/B,ME1CA,GAAiB6B,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.LoginError.tsx","webpack://snokam/./src/components/Provider/Provider.Authenticate.tsx","webpack://snokam/./src/components/Provider/NavigationClient.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 { InteractionStatus } from \"@azure/msal-browser\";\nimport { 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 === InteractionStatus.Startup ||\n inProgress === InteractionStatus.SsoSilent ||\n inProgress === InteractionStatus.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 LoginError = () => {\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\", color: \"inherit\" }, 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 { storeCurrentPath } from \"../../storage\";\nimport { useRouter } from \"next/router\";\nimport { PageLoader } from \"@snokam/core\";\nimport { LoginError } from \"./Provider.LoginError\";\nimport { loginRequest } from \"../../config\";\nimport { InteractionType, } from \"@azure/msal-browser\";\nexport const Authenticate = (props) => {\n const { children, interactionType } = props;\n const router = useRouter();\n const query = router === null || router === void 0 ? void 0 : router.query;\n const username = query === null || query === void 0 ? void 0 : query.username;\n const manualInteractionType = interactionType;\n const autoInteractionType = (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 })), { domainHint: window.location.origin.includes(\"test.snokam.no\")\n ? \"test.snokam.no\"\n : \"snokam.no\", onRedirectNavigate: (_) => {\n storeCurrentPath();\n } });\n const Error = interactionType === InteractionType.Silent ? () => children : LoginError;\n return (_jsx(MsalAuthenticationTemplate, { interactionType: manualInteractionType || autoInteractionType, loadingComponent: () => _jsx(PageLoader, {}), authenticationRequest: authRequest, errorComponent: Error, children: children }));\n};\n","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport { NavigationClient } from \"@azure/msal-browser\";\n/**\n * This is an example for overriding the default function MSAL uses to navigate to other urls in your webpage\n */\nexport class CustomNavigationClient extends NavigationClient {\n constructor(router) {\n super();\n this.router = router;\n }\n /**\n * Navigates to other pages within the same web application\n * You can use the useRouter hook provided by next.js to take advantage of client-side routing\n * @param url\n * @param options\n */\n navigateInternal(url, options) {\n return __awaiter(this, void 0, void 0, function* () {\n const relativePath = url.replace(window.location.origin, \"\");\n if (options.noHistory) {\n this.router.replace(relativePath);\n }\n else {\n this.router.push(relativePath);\n }\n return false;\n });\n }\n}\n","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { MsalProvider } from \"@azure/msal-react\";\nimport { InteractionType, PublicClientApplication, } from \"@azure/msal-browser\";\nimport { useRouter } from \"next/router\";\nimport { useRef } from \"react\";\nimport { Authenticate } from \"./Provider.Authenticate\";\nimport Callback from \"./Provider.Callback\";\nimport { CustomNavigationClient } from \"./NavigationClient\";\nexport const Provider = (props) => {\n const { children, enforceLogin } = props;\n const router = useRouter();\n const query = router === null || router === void 0 ? void 0 : router.query;\n // Store msalInstance in a ref to ensure it initializes only once\n const msalInstanceRef = useRef(null);\n const navigationClientRef = useRef(null);\n if (!msalInstanceRef.current) {\n const config = {\n auth: {\n instanceAware: true,\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 cacheLocation: \"localStorage\",\n },\n };\n msalInstanceRef.current = new PublicClientApplication(config);\n if (router) {\n navigationClientRef.current = new CustomNavigationClient(router);\n msalInstanceRef.current.setNavigationClient(navigationClientRef.current);\n }\n msalInstanceRef.current.initialize();\n }\n const msalInstance = msalInstanceRef.current;\n if ((query === null || query === void 0 ? void 0 : 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: _jsx(Authenticate, { interactionType: InteractionType.Silent, 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","InteractionStatus","Startup","SsoSilent","Login","loginRequest","Container","Link","LoginError","popupError","setPopupError","useState","children","errorCode","target","href","rel","Button","sx","marginTop","color","onClick","loginPopup","assign","redirectUri","undefined","catch","error","Authenticate","props","interactionType","router","useRouter","query","username","manualInteractionType","autoInteractionType","enforceLogin","InteractionType","Silent","Redirect","authRequest","loginHint","domainHint","origin","includes","onRedirectNavigate","_","Error","MsalAuthenticationTemplate","loadingComponent","PageLoader","authenticationRequest","errorComponent","CustomNavigationClient","NavigationClient","constructor","super","navigateInternal","url","options","thisArg","_arguments","generator","relativePath","replace","noHistory","push","P","Promise","resolve","reject","fulfilled","step","next","e","rejected","result","done","apply","Provider","msalInstanceRef","useRef","navigationClientRef","current","config","auth","instanceAware","clientId","authority","tenantId","postLogoutRedirectUri","navigateToLoginRequestUrl","system","allowRedirectInIframe","cache","cacheLocation","PublicClientApplication","setNavigationClient","initialize","msalInstance","MsalProvider","Callback","useEffect","redirectUrl","getItem","removeItem","console","log"],"sourceRoot":""}
|
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.1.
|
|
4
|
+
"version": "2.1.2",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
]
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "8841667a2c29de39b382180f6a6efb2b353eb0ba"
|
|
63
63
|
}
|