@snokam/auth 2.1.4 → 2.2.0-alpha.1
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 +29 -0
- package/lib/components/Authenticated.d.ts +6 -0
- package/lib/components/Login.d.ts +2 -0
- package/lib/components/Provider/Authenticate.d.ts +2 -0
- package/lib/components/Provider/index.d.ts +2 -5
- package/lib/components/Unauthenticated.d.ts +6 -0
- package/lib/hooks.d.ts +3 -4
- package/lib/index.d.ts +10 -9
- package/lib/index.js +1 -9
- package/lib/index.js.map +1 -1
- package/lib/middleware.d.ts +2 -0
- package/lib/middleware.js +2 -0
- package/lib/middleware.js.map +1 -0
- package/lib/options.d.ts +16 -0
- package/lib/options.js +2 -0
- package/lib/options.js.map +1 -0
- package/lib/server/handler.d.ts +14 -0
- package/lib/server/token.d.ts +8 -0
- package/lib/server.d.ts +9 -8
- package/lib/server.js +1 -1
- package/lib/server.js.map +1 -1
- package/lib/{storage.d.ts → utils/storage.d.ts} +1 -1
- package/lib/utils/types.d.ts +25 -0
- package/package.json +12 -5
- package/lib/components/Provider/NavigationClient.d.ts +0 -15
- package/lib/components/Provider/Provider.Authenticate.d.ts +0 -2
- package/lib/components/Provider/Provider.LoginError.d.ts +0 -1
- package/lib/config.d.ts +0 -3
- package/lib/types.d.ts +0 -20
- /package/lib/components/{Provider/Provider.Callback.d.ts → Callback.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,35 @@
|
|
|
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.2.0-alpha.1](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.0...@snokam/auth@2.2.0-alpha.1) (2025-05-31)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* remove comment ([03d8c35](https://github.com/snokam/components/commit/03d8c35b2053164801619b76ebf627622246f7ca))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [2.2.0-alpha.0](https://github.com/snokam/components/compare/@snokam/auth@2.1.4...@snokam/auth@2.2.0-alpha.0) (2025-05-31)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* deploy new version ([f98bb5b](https://github.com/snokam/components/commit/f98bb5b6945aa22a18948da49ace315ede23254e))
|
|
23
|
+
* login bug ([4d7f908](https://github.com/snokam/components/commit/4d7f90829585c0afd7004a992c7b841e945b5baa))
|
|
24
|
+
* trigger new release ([3af8d1b](https://github.com/snokam/components/commit/3af8d1b1803ddacb2fc1130c3194cf7191502479))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Features
|
|
28
|
+
|
|
29
|
+
* **auth:** add authentication components and update dependencies ([ac51a67](https://github.com/snokam/components/commit/ac51a67fb5929df34abb04ceaa11618e0702916a))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
6
35
|
## [2.1.4](https://github.com/snokam/components/compare/@snokam/auth@2.1.3...@snokam/auth@2.1.4) (2025-05-30)
|
|
7
36
|
|
|
8
37
|
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { Auth } from "../../utils/types";
|
|
2
|
+
export declare const Authenticate: import("react").MemoExoticComponent<(props: Auth.Authenticate.Props) => string | number | bigint | boolean | import("react/jsx-runtime").JSX.Element | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode>>>;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { Auth } from "../../types";
|
|
2
|
-
export declare const Provider:
|
|
3
|
-
(props: Auth.Provider.Props): import("react/jsx-runtime").JSX.Element;
|
|
4
|
-
Callback: () => import("react/jsx-runtime").JSX.Element;
|
|
5
|
-
};
|
|
1
|
+
import { Auth } from "../../utils/types";
|
|
2
|
+
export declare const Provider: import("react").MemoExoticComponent<(props: Auth.Provider.Props) => import("react/jsx-runtime").JSX.Element>;
|
|
6
3
|
export default Provider;
|
package/lib/hooks.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
getToken: (scopes
|
|
1
|
+
export declare function useAuth(): {
|
|
2
|
+
getToken: (scopes: string[]) => Promise<string>;
|
|
3
3
|
isAuthenticated: boolean;
|
|
4
4
|
inProgress: boolean;
|
|
5
|
-
|
|
6
|
-
account: import("@azure/msal-browser").AccountInfo;
|
|
5
|
+
account: import("next-auth").Session;
|
|
7
6
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { Auth } from "./types";
|
|
1
|
+
import { Auth } from "./utils/types";
|
|
2
|
+
export { Unauthenticated } from "./components/Unauthenticated";
|
|
3
|
+
export { Authenticated } from "./components/Authenticated";
|
|
2
4
|
export { useAuth } from "./hooks";
|
|
3
|
-
export {
|
|
4
|
-
export
|
|
5
|
-
export type { Auth };
|
|
5
|
+
export { default as middleware } from "next-auth/middleware";
|
|
6
|
+
export { signIn } from "next-auth/react";
|
|
6
7
|
declare const _default: {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Authenticate: (props: Auth.Authenticate.Props) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
Login: () => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
Callback: () => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
Provider: import("react").MemoExoticComponent<(props: Auth.Provider.Props) => import("react/jsx-runtime").JSX.Element>;
|
|
11
|
+
Authenticate: import("react").MemoExoticComponent<(props: Auth.Authenticate.Props) => string | number | bigint | boolean | import("react/jsx-runtime").JSX.Element | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode>>>;
|
|
12
12
|
};
|
|
13
13
|
export default _default;
|
|
14
|
+
export type { Auth };
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
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:()=>
|
|
2
|
-
display: flex;
|
|
3
|
-
flex-direction: column;
|
|
4
|
-
justify-content: center;
|
|
5
|
-
align-items: center;
|
|
6
|
-
flex: 1;
|
|
7
|
-
`,Link:h().a`
|
|
8
|
-
text-decoration: "underline";
|
|
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="undefined"!=typeof window,y=f&&window.location.hostname.includes("test."),j=Object.assign(Object.assign(Object.assign(Object.assign({},p),d&&{loginHint:d}),f&&{domainHint:y?"test.snokam.no":"snokam.no"}),{onRedirectNavigate:()=>{s()}}),v=c===r.InteractionType.Silent?()=>t:m;return(0,n.jsx)(o.MsalAuthenticationTemplate,{interactionType:g||h,loadingComponent:()=>(0,n.jsx)(u.PageLoader,{}),authenticationRequest:j,errorComponent:v,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})()));
|
|
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:()=>h,Unauthenticated:()=>f,default:()=>m,middleware:()=>p(),signIn:()=>s.signIn,useAuth:()=>a});const n=require("react/jsx-runtime"),o=require("react"),r=require("next/router"),s=require("next-auth/react");var i=function(e,t,n,o){return new(n||(n=Promise))((function(r,s){function i(e){try{u(o.next(e))}catch(e){s(e)}}function a(e){try{u(o.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}u((o=o.apply(e,t||[])).next())}))};function a(){const{data:e,status:t}=(0,s.useSession)(),n=(0,o.useCallback)((t=>i(this,void 0,void 0,(function*(){if(!e)throw"Unable to fetch token";const n=t[0],o=yield fetch("/api/auth/token",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({scope:n})});if(401===o.status)return yield(0,s.signIn)("azure-ad"),null;if(!o.ok)throw new Error("token fetch failed");const r=yield o.json(),{accessToken:i}=r;return`Bearer ${i}`}))),[e]);return(0,o.useMemo)((()=>({getToken:n,isAuthenticated:"authenticated"===t,inProgress:"loading"===t,account:e})),[n,t,e])}const u=require("@snokam/core"),c=(0,o.memo)((e=>{const{children:t,provider:r}=e,{inProgress:i,isAuthenticated:c}=a();return(0,o.useEffect)((()=>{i||c||(0,s.signIn)(r)}),[i,c]),c?t:(0,n.jsx)(u.PageLoader,{})})),d=(0,o.memo)((e=>{const{session:t,children:o,enforceLogin:i}=e,a=(0,r.useRouter)(),u=null==a?void 0:a.query;return(null==u?void 0:u.enforceLogin)||i?(0,n.jsx)(s.SessionProvider,{session:t,children:(0,n.jsx)(c,Object.assign({provider:"azure-ad"},e,{children:o}))}):(0,n.jsx)(s.SessionProvider,{session:t,children:o})})),l="redirect",f=({children:e})=>{const{status:t}=(0,s.useSession)();return"unauthenticated"===t?e:null},h=({children:e})=>{const{status:t}=(0,s.useSession)();return"authenticated"===t?e:null},g=require("next-auth/middleware");var p=e.n(g);const m={Login:()=>{const{isAuthenticated:e}=a(),t=(0,r.useRouter)(),[i,c]=(0,o.useState)(null);return(0,o.useEffect)((()=>{const e=new URLSearchParams(window.location.search).get("callbackUrl");c(e)}),[]),(0,o.useEffect)((()=>{var n;i&&(e?t.replace("/"):(n=i,window.sessionStorage.setItem(l,n),(0,s.signIn)("azure-ad",{callbackUrl:null!=i?i:"/"})))}),[e,i]),(0,n.jsx)(u.PageLoader,{})},Callback:()=>{const e=(0,r.useRouter)();return(0,o.useEffect)((()=>{const t=window.sessionStorage.getItem(l);t?(window.sessionStorage.removeItem(l),console.log(`Redirecting to ${t} ...`),e.replace(t)):e.replace("/")}),[e]),(0,n.jsx)(u.PageLoader,{})},Provider:d,Authenticate:c};return t})()));
|
|
10
2
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"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XA,IAAAyE,YAAU,KACN,MAAMC,EXHH3H,OAAOC,eAAe2H,QAAQ9H,GWI7B6H,GXDR3H,OAAOC,eAAe4H,WAAW/H,GWGzBgI,QAAQC,IAAI,kBAAkBJ,SAC9B3E,EAAOmC,QAAQwC,IAGf3E,EAAOmC,QAAQ,IACnB,GACD,CAACnC,KACG,SAAK,EAAAqB,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 isBrowser = typeof window !== \"undefined\";\n const isTest = isBrowser && window.location.hostname.includes(\"test.\");\n const authRequest = Object.assign(Object.assign(Object.assign(Object.assign({}, loginRequest), (username && {\n loginHint: username,\n })), (isBrowser && {\n domainHint: isTest ? \"test.snokam.no\" : \"snokam.no\",\n })), { 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","isBrowser","isTest","hostname","includes","authRequest","loginHint","domainHint","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,kICL9D,MAAM,EAA+BC,QAAQ,qBCAvC,EAA+BA,QAAQ,SCAvC,EAA+BA,QAAQ,eCAvC,EAA+BA,QAAQ,mBCA7C,IAAIC,EAAwC,SAAUC,EAASC,EAAYC,EAAGC,GAE1E,OAAO,IAAKD,IAAMA,EAAIE,WAAU,SAAUC,EAASC,GAC/C,SAASC,EAAUV,GAA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IAAAC,aAYf,OAXA,IAAAN,YAAU,KACN,MAAM2B,ENJHR,OAAOK,eAAeI,QAAQlB,GMK7BiB,GNFRR,OAAOK,eAAeK,WAAWnB,GMIzBoB,QAAQC,IAAI,kBAAkBJ,SAC9BtB,EAAOkB,QAAQI,IAGftB,EAAOkB,QAAQ,IACnB,GACD,CAAClB,KACG,SAAK,EAAAJ,WAAY,CAAC,EAAE,EFP3BC,SAAQ,EACRP,aAAY,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 \"react\"","webpack://snokam/external commonjs \"next/router\"","webpack://snokam/external commonjs \"next-auth/react\"","webpack://snokam/./src/hooks.ts","webpack://snokam/external commonjs \"@snokam/core\"","webpack://snokam/./src/components/Provider/Authenticate.tsx","webpack://snokam/./src/components/Provider/index.tsx","webpack://snokam/./src/utils/storage.ts","webpack://snokam/./src/components/Unauthenticated.tsx","webpack://snokam/./src/components/Authenticated.tsx","webpack://snokam/external commonjs \"next-auth/middleware\"","webpack://snokam/./src/index.tsx","webpack://snokam/./src/components/Login.tsx","webpack://snokam/./src/components/Callback.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(\"react\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next/router\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/react\");","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 { useSession, signIn } from \"next-auth/react\";\nimport { useCallback, useMemo } from \"react\";\nexport function useAuth() {\n const { data: account, status } = useSession();\n const getToken = useCallback((scopes) => __awaiter(this, void 0, void 0, function* () {\n if (!account) {\n throw \"Unable to fetch token\";\n }\n const scope = scopes[0];\n const res = yield fetch(\"/api/auth/token\", {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n credentials: \"include\",\n body: JSON.stringify({ scope }),\n });\n if (res.status === 401) {\n yield signIn(\"azure-ad\");\n return null;\n }\n if (!res.ok)\n throw new Error(\"token fetch failed\");\n const token = yield res.json();\n const { accessToken } = token;\n return `Bearer ${accessToken}`;\n }), [account]);\n const value = useMemo(() => ({\n getToken,\n isAuthenticated: status === \"authenticated\",\n inProgress: status === \"loading\",\n account,\n }), [getToken, status, account]);\n return value;\n}\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@snokam/core\");","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { memo, useEffect } from \"react\";\nimport { signIn } from \"next-auth/react\";\nimport { useAuth } from \"../../hooks\";\nimport { PageLoader } from \"@snokam/core\";\nexport const Authenticate = memo((props) => {\n const { children, provider } = props;\n const { inProgress, isAuthenticated } = useAuth();\n useEffect(() => {\n if (!inProgress && !isAuthenticated) {\n signIn(provider);\n }\n }, [inProgress, isAuthenticated]);\n if (!isAuthenticated) {\n return _jsx(PageLoader, {});\n }\n return children;\n});\n","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { memo } from \"react\";\nimport { useRouter } from \"next/router\";\nimport { Authenticate } from \"./Authenticate\";\nimport { SessionProvider } from \"next-auth/react\";\nexport const Provider = memo((props) => {\n const { session, children, enforceLogin } = props;\n const router = useRouter();\n const query = router === null || router === void 0 ? void 0 : router.query;\n if ((query === null || query === void 0 ? void 0 : query.enforceLogin) || enforceLogin) {\n return (_jsx(SessionProvider, { session: session, children: _jsx(Authenticate, Object.assign({ provider: \"azure-ad\" }, props, { children: children })) }));\n }\n return _jsx(SessionProvider, { session: session, children: children });\n});\nexport default Provider;\n","const SessionStorageKey = \"redirect\";\nexport const storeCallbackUrl = (url) => {\n window.sessionStorage.setItem(SessionStorageKey, url);\n};\nexport const getStoredPath = () => {\n return window.sessionStorage.getItem(SessionStorageKey);\n};\nexport const clearStoredPath = () => {\n window.sessionStorage.removeItem(SessionStorageKey);\n};\n","import { useSession } from \"next-auth/react\";\nexport const Unauthenticated = ({ children }) => {\n const { status } = useSession();\n return status === \"unauthenticated\" ? children : null;\n};\n","import { useSession } from \"next-auth/react\";\nexport const Authenticated = ({ children }) => {\n const { status } = useSession();\n return status === \"authenticated\" ? children : null;\n};\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/middleware\");","import { Provider } from \"./components/Provider\";\nimport { Authenticate } from \"./components/Provider/Authenticate\";\nimport { Callback } from \"./components/Callback\";\nimport { Login } from \"./components/Login\";\nexport { Unauthenticated } from \"./components/Unauthenticated\";\nexport { Authenticated } from \"./components/Authenticated\";\nexport { useAuth } from \"./hooks\";\nexport { default as middleware } from \"next-auth/middleware\";\nexport { signIn } from \"next-auth/react\";\nexport default {\n Login,\n Callback,\n Provider,\n Authenticate,\n};\n","\"use client\";\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useEffect, useState } from \"react\";\nimport { useRouter } from \"next/router\";\nimport { useAuth } from \"../hooks\";\nimport { signIn } from \"next-auth/react\";\nimport { storeCallbackUrl } from \"../utils/storage\";\nimport { PageLoader } from \"@snokam/core\";\nexport const Login = () => {\n const { isAuthenticated } = useAuth();\n const router = useRouter();\n const [callbackUrl, setCallbackUrl] = useState(null);\n useEffect(() => {\n const params = new URLSearchParams(window.location.search);\n const cb = params.get(\"callbackUrl\");\n setCallbackUrl(cb);\n }, []);\n useEffect(() => {\n if (!callbackUrl) {\n return;\n }\n if (isAuthenticated) {\n router.replace(\"/\");\n }\n else {\n storeCallbackUrl(callbackUrl);\n signIn(\"azure-ad\", {\n callbackUrl: callbackUrl !== null && callbackUrl !== void 0 ? callbackUrl : \"/\",\n });\n }\n }, [isAuthenticated, callbackUrl]);\n return _jsx(PageLoader, {});\n};\nexport default Login;\n","\"use client\";\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useEffect } from \"react\";\nimport { useRouter } from \"next/router\";\nimport { clearStoredPath, getStoredPath } from \"../utils/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"],"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","__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","step","next","e","rejected","result","done","then","apply","useAuth","data","account","status","useSession","getToken","useCallback","scopes","scope","res","fetch","method","headers","credentials","body","JSON","stringify","signIn","ok","Error","token","json","accessToken","useMemo","isAuthenticated","inProgress","Authenticate","memo","props","children","provider","useEffect","PageLoader","Provider","session","enforceLogin","router","useRouter","query","SessionProvider","assign","SessionStorageKey","Unauthenticated","Authenticated","Login","callbackUrl","setCallbackUrl","useState","cb","URLSearchParams","window","location","search","url","replace","sessionStorage","setItem","Callback","redirectUrl","getItem","removeItem","console","log"],"sourceRoot":""}
|
|
@@ -0,0 +1,2 @@
|
|
|
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={d:(t,o)=>{for(var r in o)e.o(o,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:o[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,{default:()=>o});const o=(0,require("next-auth/middleware").withAuth)({pages:{signIn:"/auth/login"}});return t})()));
|
|
2
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.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,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAER,EAASO,IAC5EE,OAAOC,eAAeV,EAASO,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDF,EAAwB,CAACQ,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFT,EAAyBL,IACH,oBAAXkB,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeV,EAASkB,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeV,EAAS,aAAc,CAAEoB,OAAO,GAAO,G,mCCL9D,MCCA,GAAe,EDDsBC,QAAQ,wBCC9BC,UAAS,CACpBC,MAAO,CACHC,OAAQ,iB","sources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/webpack/bootstrap","webpack://snokam/webpack/runtime/define property getters","webpack://snokam/webpack/runtime/hasOwnProperty shorthand","webpack://snokam/webpack/runtime/make namespace object","webpack://snokam/external commonjs \"next-auth/middleware\"","webpack://snokam/./src/middleware.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","// 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(\"next-auth/middleware\");","import { withAuth } from \"next-auth/middleware\";\nexport default withAuth({\n pages: {\n signIn: \"/auth/login\",\n },\n});\n"],"names":["root","factory","exports","module","define","amd","this","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","require","withAuth","pages","signIn"],"sourceRoot":""}
|
package/lib/options.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Auth } from "./utils/types";
|
|
2
|
+
export declare const getNextAuthOptions: (config: Auth.Config) => {
|
|
3
|
+
secret: string;
|
|
4
|
+
pages: {
|
|
5
|
+
signIn: string;
|
|
6
|
+
};
|
|
7
|
+
providers: import("next-auth/providers").OAuthConfig<import("next-auth/providers/azure-ad").AzureADProfile>[];
|
|
8
|
+
callbacks: {
|
|
9
|
+
jwt({ token, account }: {
|
|
10
|
+
token: any;
|
|
11
|
+
account: any;
|
|
12
|
+
}): Promise<any>;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
declare const _default: (config: Auth.Config) => any;
|
|
16
|
+
export default _default;
|
package/lib/options.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
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={542:e=>{e.exports=require("next-auth")}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var a=t[o]={exports:{}};return e[o](a,a.exports,n),a.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};n.r(o),n.d(o,{default:()=>u,getNextAuthOptions:()=>s});var r=n(542),a=n.n(r);const c=require("next-auth/providers/azure-ad");var i=n.n(c);const s=e=>({secret:e.nextAuthSecret,pages:{signIn:"/auth/login"},providers:[i()({clientId:e.clientId,clientSecret:e.clientSecret,tenantId:e.tenantId,authorization:{params:{scope:"openid profile email offline_access https://graph.microsoft.com/User.Read"}}})],callbacks:{jwt(e){return t=this,n=arguments,r=function*({token:e,account:t}){return(null==t?void 0:t.access_token)&&(e.accessToken=t.access_token,e.refreshToken=t.refresh_token,e.expiresAt=t.expires_at),e},new((o=void 0)||(o=Promise))((function(e,a){function c(e){try{s(r.next(e))}catch(e){a(e)}}function i(e){try{s(r.throw(e))}catch(e){a(e)}}function s(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(c,i)}s((r=r.apply(t,n||[])).next())}));var t,n,o,r}}}),u=e=>a()(s(e));return o})()));
|
|
2
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.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,kCCT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C,EAAK,QAAEC,IAM1D,OALIA,aAAyC,EAASA,EAAQC,gBAC1DF,EAAMG,YAAcF,EAAQC,aAC5BF,EAAMI,aAAeH,EAAQI,cAC7BL,EAAMM,UAAYL,EAAQM,YAEvBP,CACX,EAnCD,KAFgEQ,OA8B7B,KA5BxBA,EAAIC,WAAU,SAAUC,EAASC,GAC/C,SAASC,EAAUjC,GAAS,IAAMkC,EAAKd,EAAUe,KAAKnC,GAAS,CAAE,MAAOoC,GAAKJ,EAAOI,EAAI,CAAE,CAC1F,SAASC,EAASrC,GAAS,IAAMkC,EAAKd,EAAiB,MAAEpB,GAAS,CAAE,MAAOoC,GAAKJ,EAAOI,EAAI,CAAE,CAC7F,SAASF,EAAKI,GAJlB,IAAetC,EAIasC,EAAOC,KAAOR,EAAQO,EAAOtC,QAJ1CA,EAIyDsC,EAAOtC,MAJhDA,aAAiB6B,EAAI7B,EAAQ,IAAI6B,GAAE,SAAUE,GAAWA,EAAQ/B,EAAQ,KAIjBwC,KAAKP,EAAWI,EAAW,CAC7GH,GAAMd,EAAYA,EAAUqB,MAAMxB,EAASC,GAAc,KAAKiB,OAClE,IAPwC,IAAUlB,EAASC,EAAYW,EAAGT,CAsCtE,KAGR,EAAgBlB,GAAW,IAASD,EAAmBC,I","sources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/external commonjs \"next-auth\"","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 \"next-auth/providers/azure-ad\"","webpack://snokam/./src/options.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 ","module.exports = require(\"next-auth\");","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\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(\"next-auth/providers/azure-ad\");","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 NextAuth from \"next-auth\";\nimport AzureADProvider from \"next-auth/providers/azure-ad\";\nexport const getNextAuthOptions = (config) => ({\n secret: config.nextAuthSecret,\n pages: {\n signIn: \"/auth/login\",\n },\n providers: [\n AzureADProvider({\n clientId: config.clientId,\n clientSecret: config.clientSecret,\n tenantId: config.tenantId,\n authorization: {\n params: {\n scope: \"openid profile email offline_access https://graph.microsoft.com/User.Read\",\n },\n },\n }),\n ],\n callbacks: {\n jwt(_a) {\n return __awaiter(this, arguments, void 0, function* ({ token, account }) {\n if (account === null || account === void 0 ? void 0 : account.access_token) {\n token.accessToken = account.access_token;\n token.refreshToken = account.refresh_token;\n token.expiresAt = account.expires_at;\n }\n return token;\n });\n },\n },\n});\nexport default (config) => NextAuth(getNextAuthOptions(config));\n"],"names":["root","factory","exports","module","define","amd","this","require","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","n","getter","__esModule","d","a","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag","value","getNextAuthOptions","config","secret","nextAuthSecret","pages","signIn","providers","clientId","clientSecret","tenantId","authorization","params","scope","callbacks","jwt","_a","thisArg","_arguments","arguments","generator","token","account","access_token","accessToken","refreshToken","refresh_token","expiresAt","expires_at","P","Promise","resolve","reject","fulfilled","step","next","e","rejected","result","done","then","apply"],"sourceRoot":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { NextApiRequest, NextApiResponse } from "next";
|
|
2
|
+
import { Auth } from "../utils/types";
|
|
3
|
+
export interface Props {
|
|
4
|
+
req: NextApiRequest;
|
|
5
|
+
res: NextApiResponse<{
|
|
6
|
+
accessToken: string;
|
|
7
|
+
expiresOn: number;
|
|
8
|
+
} | string>;
|
|
9
|
+
authConfig: Auth.Config;
|
|
10
|
+
}
|
|
11
|
+
export default function handler(props: Props): Promise<void | NextApiResponse<string | {
|
|
12
|
+
accessToken: string;
|
|
13
|
+
expiresOn: number;
|
|
14
|
+
}>>;
|
package/lib/server.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { getServerToken } from "./server/token";
|
|
2
|
+
import { default as Token } from "./server/handler";
|
|
3
|
+
export { getServerToken };
|
|
4
|
+
export { getServerSession } from "next-auth/next";
|
|
5
|
+
declare const _default: {
|
|
6
|
+
Routes: (config: import(".").Auth.Config) => any;
|
|
7
|
+
Token: typeof Token;
|
|
8
|
+
};
|
|
9
|
+
export default _default;
|
package/lib/server.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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={
|
|
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={345:(e,t,n)=>{n.d(t,{default:()=>s,getNextAuthOptions:()=>a});var o=n(542),r=n.n(o);const i=require("next-auth/providers/azure-ad");var c=n.n(i);const a=e=>({secret:e.nextAuthSecret,pages:{signIn:"/auth/login"},providers:[c()({clientId:e.clientId,clientSecret:e.clientSecret,tenantId:e.tenantId,authorization:{params:{scope:"openid profile email offline_access https://graph.microsoft.com/User.Read"}}})],callbacks:{jwt(e){return t=this,n=arguments,r=function*({token:e,account:t}){return(null==t?void 0:t.access_token)&&(e.accessToken=t.access_token,e.refreshToken=t.refresh_token,e.expiresAt=t.expires_at),e},new((o=void 0)||(o=Promise))((function(e,i){function c(e){try{s(r.next(e))}catch(e){i(e)}}function a(e){try{s(r.throw(e))}catch(e){i(e)}}function s(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(c,a)}s((r=r.apply(t,n||[])).next())}));var t,n,o,r}}}),s=e=>r()(a(e))},542:e=>{e.exports=require("next-auth")}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var i=t[o]={exports:{}};return e[o](i,i.exports,n),i.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};n.r(o),n.d(o,{default:()=>l,getServerSession:()=>u.getServerSession,getServerToken:()=>i});const r=require("@azure/msal-node");const i=e=>{return t=void 0,n=void 0,i=function*(){const{scopes:t}=e,n=new r.ConfidentialClientApplication({auth:{clientId:`${e.clientId}`,authority:`https://login.microsoftonline.com/${e.tenantId}/oauth2/v2.0`,clientSecret:`${e.secret}`}}),o=yield n.acquireTokenByClientCredential({scopes:t.map((e=>e.replace("user_impersonation",".default")))}).catch((e=>{throw console.error(e),e}));return`Bearer ${null==o?void 0:o.accessToken}`},new((o=void 0)||(o=Promise))((function(e,r){function c(e){try{s(i.next(e))}catch(e){r(e)}}function a(e){try{s(i.throw(e))}catch(e){r(e)}}function s(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(c,a)}s((i=i.apply(t,n||[])).next())}));var t,n,o,i};var c=n(345);const a=require("next-auth/jwt");var s=n(542);const u=require("next-auth/next"),l={Routes:c.default,Token:function(e){return t=this,n=void 0,i=function*(){const{req:t,res:n,authConfig:o}=e,i=yield(0,s.getServerSession)(t,n,(0,c.getNextAuthOptions)(o));if(!(null==i?void 0:i.user))return n.status(401).end("Not authenticated");if(!t.body.scope)return n.status(400).end("Invalid or missing scope");try{const{nextAuthSecret:e}=o,i=yield(0,a.getToken)({req:t,secret:e});if(!i)return n.status(500).end("Failed to get refetch token");const c=new r.ConfidentialClientApplication({auth:{clientId:o.clientId,clientSecret:o.clientSecret,authority:`https://login.microsoftonline.com/${o.tenantId}`}}),s=yield c.acquireTokenByRefreshToken({scopes:[t.body.scope],refreshToken:null==i?void 0:i.refreshToken});return s?n.status(200).json({accessToken:null==s?void 0:s.accessToken,expiresOn:Math.floor(s.expiresOn.getTime()/1e3)}):n.status(500).end("Failed to get access token")}catch(e){console.error("Token exchange error:",e),n.status(500).end("Token exchange failed")}},new((o=void 0)||(o=Promise))((function(e,r){function c(e){try{s(i.next(e))}catch(e){r(e)}}function a(e){try{s(i.throw(e))}catch(e){r(e)}}function s(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(c,a)}s((i=i.apply(t,n||[])).next())}));var t,n,o,i}};return o})()));
|
|
2
2
|
//# sourceMappingURL=server.js.map
|
package/lib/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.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,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAER,EAASO,IAC5EE,OAAOC,eAAeV,EAASO,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDF,EAAwB,CAACQ,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,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ources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/webpack/bootstrap","webpack://snokam/webpack/runtime/define property getters","webpack://snokam/webpack/runtime/hasOwnProperty shorthand","webpack://snokam/webpack/runtime/make namespace object","webpack://snokam/external commonjs \"@azure/msal-node\"","webpack://snokam/./src/server.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","// 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(\"@azure/msal-node\");","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 { ConfidentialClientApplication } from \"@azure/msal-node\";\nexport const getServerToken = (props) => __awaiter(void 0, void 0, void 0, function* () {\n const { scopes } = props;\n const config = {\n auth: {\n clientId: `${props.clientId}`,\n authority: `https://login.microsoftonline.com/${props.tenantId}/oauth2/v2.0`,\n clientSecret: `${props.secret}`,\n },\n };\n const cca = new ConfidentialClientApplication(config);\n const response = yield cca\n .acquireTokenByClientCredential({\n scopes: scopes.map((scope) => scope.replace(\"user_impersonation\", \".default\")),\n })\n .catch((e) => {\n console.error(e);\n throw e;\n });\n return `Bearer ${response === null || response === void 0 ? void 0 : response.accessToken}`;\n});\n"],"names":["root","factory","exports","module","define","amd","this","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","require","getServerToken","props","__awaiter","thisArg","_arguments","generator","scopes","config","auth","clientId","authority","tenantId","clientSecret","secret","cca","ConfidentialClientApplication","response","acquireTokenByClientCredential","map","scope","replace","catch","e","console","error","accessToken","P","Promise","resolve","reject","fulfilled","step","next","rejected","result","done","then","apply"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"server.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,8GCTT,MAAM,EAA+BC,QAAQ,gC,aCWtC,MAAMC,EAAsBC,IAAW,CAC1CC,OAAQD,EAAOE,eACfC,MAAO,CACHC,OAAQ,eAEZC,UAAW,CACP,IAAgB,CACZC,SAAUN,EAAOM,SACjBC,aAAcP,EAAOO,aACrBC,SAAUR,EAAOQ,SACjBC,cAAe,CACXC,OAAQ,CACJC,MAAO,iFAKvBC,UAAW,CACP,GAAAC,CAAIC,GACA,OA9B0CC,EA8BzBlB,KA9BkCmB,EA8B5BC,UA9B2CC,EA8BxB,WAAW,M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OAJvDhB,EAAIK,OAAO,KAAKC,IAAI,6BAMnC,CACA,MAAOxD,GACH6C,QAAQC,MAAM,wBAAyB9C,GACvCkD,EAAIK,OAAO,KAAKC,IAAI,wBACxB,CACJ,EAlDO,KAFgEhE,OAcxC,KAZbA,EAAIC,WAAU,SAAUC,EAASC,GAC/C,SAASC,EAAUC,GAAS,IAAMC,EAAKf,EAAUgB,KAAKF,GAAS,CAAE,MAAOG,GAAKL,EAAOK,EAAI,CAAE,CAC1F,SAASC,EAASJ,GAAS,IAAMC,EAAKf,EAAiB,MAAEc,GAAS,CAAE,MAAOG,GAAKL,EAAOK,EAAI,CAAE,CAC7F,SAASF,EAAKI,GAJlB,IAAeL,EAIaK,EAAOC,KAAOT,EAAQQ,EAAOL,QAJ1CA,EAIyDK,EAAOL,MAJhDA,aAAiBL,EAAIK,EAAQ,IAAIL,GAAE,SAAUE,GAAWA,EAAQG,EAAQ,KAIjBO,KAAKR,EAAWK,EAAW,CAC7GH,GAAMf,EAAYA,EAAUsB,MAAMzB,EAASC,GAAc,KAAKkB,OAClE,IAPwC,IAAUnB,EAASC,EAAYW,EAAGT,CAqD9E,G","sources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/external commonjs \"next-auth/providers/azure-ad\"","webpack://snokam/./src/options.tsx","webpack://snokam/external commonjs \"next-auth\"","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 \"@azure/msal-node\"","webpack://snokam/./src/server/token.tsx","webpack://snokam/external commonjs \"next-auth/jwt\"","webpack://snokam/external commonjs \"next-auth/next\"","webpack://snokam/./src/server.tsx","webpack://snokam/./src/server/handler.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 ","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/providers/azure-ad\");","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 NextAuth from \"next-auth\";\nimport AzureADProvider from \"next-auth/providers/azure-ad\";\nexport const getNextAuthOptions = (config) => ({\n secret: config.nextAuthSecret,\n pages: {\n signIn: \"/auth/login\",\n },\n providers: [\n AzureADProvider({\n clientId: config.clientId,\n clientSecret: config.clientSecret,\n tenantId: config.tenantId,\n authorization: {\n params: {\n scope: \"openid profile email offline_access https://graph.microsoft.com/User.Read\",\n },\n },\n }),\n ],\n callbacks: {\n jwt(_a) {\n return __awaiter(this, arguments, void 0, function* ({ token, account }) {\n if (account === null || account === void 0 ? void 0 : account.access_token) {\n token.accessToken = account.access_token;\n token.refreshToken = account.refresh_token;\n token.expiresAt = account.expires_at;\n }\n return token;\n });\n },\n },\n});\nexport default (config) => NextAuth(getNextAuthOptions(config));\n","module.exports = require(\"next-auth\");","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\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(\"@azure/msal-node\");","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 { ConfidentialClientApplication } from \"@azure/msal-node\";\nexport const getServerToken = (props) => __awaiter(void 0, void 0, void 0, function* () {\n const { scopes } = props;\n const cca = new ConfidentialClientApplication({\n auth: {\n clientId: `${props.clientId}`,\n authority: `https://login.microsoftonline.com/${props.tenantId}/oauth2/v2.0`,\n clientSecret: `${props.secret}`,\n },\n });\n const response = yield cca\n .acquireTokenByClientCredential({\n scopes: scopes.map((scope) => scope.replace(\"user_impersonation\", \".default\")),\n })\n .catch((e) => {\n console.error(e);\n throw e;\n });\n return `Bearer ${response === null || response === void 0 ? void 0 : response.accessToken}`;\n});\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/jwt\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/next\");","import { getServerToken } from \"./server/token\";\nimport { default as Routes } from \"./options\";\nimport { default as Token } from \"./server/handler\";\nexport { getServerToken };\nexport { getServerSession } from \"next-auth/next\";\nexport default {\n Routes,\n Token,\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 { getToken } from \"next-auth/jwt\";\nimport { ConfidentialClientApplication } from \"@azure/msal-node\";\nimport { getServerSession } from \"next-auth\";\nimport { getNextAuthOptions } from \"../options\";\nexport default function handler(props) {\n return __awaiter(this, void 0, void 0, function* () {\n const { req, res, authConfig } = props;\n const session = yield getServerSession(req, res, getNextAuthOptions(authConfig));\n if (!(session === null || session === void 0 ? void 0 : session.user)) {\n return res.status(401).end(\"Not authenticated\");\n }\n if (!req.body.scope) {\n return res.status(400).end(\"Invalid or missing scope\");\n }\n try {\n const { nextAuthSecret } = authConfig;\n const refetchTokenResult = yield getToken({ req, secret: nextAuthSecret });\n if (!refetchTokenResult) {\n return res.status(500).end(\"Failed to get refetch token\");\n }\n const cca = new ConfidentialClientApplication({\n auth: {\n clientId: authConfig.clientId,\n clientSecret: authConfig.clientSecret,\n authority: `https://login.microsoftonline.com/${authConfig.tenantId}`,\n },\n });\n const accessTokenResult = yield cca.acquireTokenByRefreshToken({\n scopes: [req.body.scope],\n refreshToken: refetchTokenResult === null || refetchTokenResult === void 0 ? void 0 : refetchTokenResult.refreshToken,\n });\n if (!accessTokenResult) {\n return res.status(500).end(\"Failed to get access token\");\n }\n return res.status(200).json({\n accessToken: accessTokenResult === null || accessTokenResult === void 0 ? void 0 : accessTokenResult.accessToken,\n expiresOn: Math.floor(accessTokenResult.expiresOn.getTime() / 1000),\n });\n }\n catch (e) {\n console.error(\"Token exchange error:\", e);\n res.status(500).end(\"Token exchange failed\");\n }\n });\n}\n"],"names":["root","factory","exports","module","define","amd","this","require","getNextAuthOptions","config","secret","nextAuthSecret","pages","signIn","providers","clientId","clientSecret","tenantId","authorization","params","scope","callbacks","jwt","_a","thisArg","_arguments","arguments","generator","token","account","access_token","accessToken","refreshToken","refresh_token","expiresAt","expires_at","P","Promise","resolve","reject","fulfilled","value","step","next","e","rejected","result","done","then","apply","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","n","getter","__esModule","d","a","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag","getServerToken","props","__awaiter","scopes","cca","ConfidentialClientApplication","auth","authority","response","acquireTokenByClientCredential","map","replace","catch","console","error","Routes","Token","req","res","authConfig","session","getServerSession","user","status","end","body","refetchTokenResult","getToken","accessTokenResult","acquireTokenByRefreshToken","json","expiresOn","Math","floor","getTime"],"sourceRoot":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Session } from "next-auth";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
export declare namespace Auth {
|
|
4
|
+
interface Config {
|
|
5
|
+
clientId: string;
|
|
6
|
+
clientSecret: string;
|
|
7
|
+
nextAuthSecret: string;
|
|
8
|
+
tenantId: string;
|
|
9
|
+
}
|
|
10
|
+
namespace Provider {
|
|
11
|
+
interface Props {
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
enforceLogin?: boolean;
|
|
14
|
+
showPageLoader?: boolean;
|
|
15
|
+
session: Session;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
namespace Authenticate {
|
|
19
|
+
interface Props {
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
provider: string;
|
|
22
|
+
showPageLoader?: boolean;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
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.2.0-alpha.1",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -24,13 +24,12 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@azure/msal-browser": "^4.12.0",
|
|
28
27
|
"@azure/msal-node": "^3.5.3",
|
|
29
|
-
"@azure/msal-react": "^3.0.12",
|
|
30
28
|
"@emotion/react": "^11.14.0",
|
|
31
29
|
"@emotion/styled": "^11.14.0",
|
|
32
30
|
"@mui/material": "^7.1.0",
|
|
33
|
-
"@snokam/core": "^1.4.0"
|
|
31
|
+
"@snokam/core": "^1.4.0",
|
|
32
|
+
"next-auth": "^4.24.11"
|
|
34
33
|
},
|
|
35
34
|
"peerDependencies": {
|
|
36
35
|
"next": "*",
|
|
@@ -47,6 +46,11 @@
|
|
|
47
46
|
"import": "./lib/server.js",
|
|
48
47
|
"require": "./lib/server.js",
|
|
49
48
|
"types": "./lib/server.d.ts"
|
|
49
|
+
},
|
|
50
|
+
"./middleware": {
|
|
51
|
+
"import": "./lib/middleware.js",
|
|
52
|
+
"require": "./lib/middleware.js",
|
|
53
|
+
"types": "./lib/middleware.d.ts"
|
|
50
54
|
}
|
|
51
55
|
},
|
|
52
56
|
"typesVersions": {
|
|
@@ -56,8 +60,11 @@
|
|
|
56
60
|
],
|
|
57
61
|
"server": [
|
|
58
62
|
"lib/server.d.ts"
|
|
63
|
+
],
|
|
64
|
+
"middleware": [
|
|
65
|
+
"lib/middleware.d.ts"
|
|
59
66
|
]
|
|
60
67
|
}
|
|
61
68
|
},
|
|
62
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "abb1bba0b4b99ee2bf09102b49d92f3fbea2751f"
|
|
63
70
|
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { NavigationClient } from "@azure/msal-browser";
|
|
2
|
-
/**
|
|
3
|
-
* This is an example for overriding the default function MSAL uses to navigate to other urls in your webpage
|
|
4
|
-
*/
|
|
5
|
-
export declare class CustomNavigationClient extends NavigationClient {
|
|
6
|
-
[x: string]: any;
|
|
7
|
-
constructor(router: any);
|
|
8
|
-
/**
|
|
9
|
-
* Navigates to other pages within the same web application
|
|
10
|
-
* You can use the useRouter hook provided by next.js to take advantage of client-side routing
|
|
11
|
-
* @param url
|
|
12
|
-
* @param options
|
|
13
|
-
*/
|
|
14
|
-
navigateInternal(url: any, options: any): Promise<boolean>;
|
|
15
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const LoginError: () => import("react/jsx-runtime").JSX.Element;
|
package/lib/config.d.ts
DELETED
package/lib/types.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { InteractionType } from "@azure/msal-browser";
|
|
2
|
-
import { ReactNode } from "react";
|
|
3
|
-
export declare namespace Auth {
|
|
4
|
-
namespace Provider {
|
|
5
|
-
interface Props {
|
|
6
|
-
children: ReactNode;
|
|
7
|
-
enforceLogin?: boolean;
|
|
8
|
-
config: {
|
|
9
|
-
tenantId: string;
|
|
10
|
-
clientId: string;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
namespace Authenticate {
|
|
15
|
-
interface Props {
|
|
16
|
-
children: ReactNode;
|
|
17
|
-
interactionType?: InteractionType;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
File without changes
|