@snokam/auth 2.2.6 → 2.2.7

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 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.2.7](https://github.com/snokam/components/compare/@snokam/auth@2.2.6...@snokam/auth@2.2.7) (2025-06-02)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * specify cookie names ([0c48f4a](https://github.com/snokam/components/commit/0c48f4aad39522d43364e8c17b5ada4333d58c25))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [2.2.6](https://github.com/snokam/components/compare/@snokam/auth@2.2.5...@snokam/auth@2.2.6) (2025-06-02)
7
18
 
8
19
 
package/lib/middleware.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={d:(t,r)=>{for(var o in r)e.o(r,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[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,{buildAuthMiddleware:()=>i,config:()=>c,default:()=>u});const r=require("path-to-regexp"),o=require("next-auth/middleware");var n=function(e,t){var r={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(e);n<o.length;n++)t.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(e,o[n])&&(r[o[n]]=e[o[n]])}return r};const a=["/((?!api|_next/static|_next/image|favicon.ico|.*\\..*).*)"];function i(e={}){var t,{matcher:i=[],callbacks:l={},protectAllRoutes:c}=e,u=n(e,["matcher","callbacks","protectAllRoutes"]);const p="preview"===process.env.NEXT_PUBLIC_VERCEL_ENV;return{middleware:(0,o.withAuth)((e=>{}),Object.assign({pages:{signIn:"/auth/login"},callbacks:{authorized:null!==(t=l.authorized)&&void 0!==t?t:({req:e,token:t})=>{return o=e.nextUrl.pathname,!(p||c&&0===(null==i?void 0:i.length)||i.some((e=>{if(!e)return!1;if(e.endsWith(":path*")){const t=e.replace(/\/:path\*$/,"");return o.startsWith(t)}return!1!==(0,r.match)(e,{end:!0})(o)})))||!!t;var o}}},u)),config:p?{matcher:a}:(null==i?void 0:i.length)>0?{matcher:i}:void 0}}const{middleware:l,config:c}=i(),u=l;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={d:(t,o)=>{for(var n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},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,{buildAuthMiddleware:()=>i,config:()=>c,default:()=>l});const o=require("path-to-regexp"),n=require("next-auth/middleware");var r=function(e,t){var o={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++)t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(o[n[r]]=e[n[r]])}return o};const a=["/((?!api|_next/static|_next/image|favicon.ico|.*\\..*).*)"];function i(e={}){var t,{matcher:i=[],callbacks:s={},protectAllRoutes:c}=e,l=r(e,["matcher","callbacks","protectAllRoutes"]);const u="preview"===process.env.NEXT_PUBLIC_VERCEL_ENV,{name:d}=function(e){const{hostname:t,protocol:o}=new URL(e),n="https:"===o,r=n?"__Secure-":"",{tag:a,domain:i}=(()=>{if("localhost"===t||/^[\d.]+$/.test(t))return{tag:"local"};if(t.endsWith(".test.snokam.no"))return{tag:"test",domain:".test.snokam.no"};if(t.endsWith(".snokam.no"))return{tag:"prod",domain:".snokam.no"};const e=t.split(".");if(e.length>=2){const t=e.slice(-2).join(".");return{tag:t.replace(/\./g,"-"),domain:`.${t}`}}return{tag:"host"}})();return{name:`${r}next-auth.${a}.session-token`,domain:i,secure:n}}(`${process.env.NEXTAUTH_URL}`);return{middleware:(0,n.withAuth)((e=>{}),Object.assign({pages:{signIn:"/auth/login"},cookies:{sessionToken:{name:d}},callbacks:{authorized:null!==(t=s.authorized)&&void 0!==t?t:({req:e,token:t})=>{return n=e.nextUrl.pathname,!(u||c&&0===(null==i?void 0:i.length)||i.some((e=>{if(!e)return!1;if(e.endsWith(":path*")){const t=e.replace(/\/:path\*$/,"");return n.startsWith(t)}return!1!==(0,o.match)(e,{end:!0})(n)})))||!!t;var n}}},l)),config:u?{matcher:a}:(null==i?void 0:i.length)>0?{matcher:i}:void 0}}const{middleware:s,config:c}=i(),l=s;return t})()));
2
2
  //# sourceMappingURL=middleware.js.map
@@ -1 +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,IA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,MAAO,CAC1DC,OAAQ,eACTZ,UAAW,CACVa,WAA4C,QAA/Bf,EAAKE,EAAUa,kBAA+B,IAAPf,EAAgBA,EAAK,EAAIgB,MAAKC,YAC9E,OAnBeC,EAmBUF,EAAIG,QAAQD,WAlBzCb,GAAcF,GAA2F,KAAtEF,aAAyC,EAASA,EAAQN,SAG1FM,EAAQmB,MAAMC,IACjB,IAAKA,EACD,OAAO,EAEX,GAAIA,EAAQC,SAAS,UAAW,CAC5B,MAAMC,EAAOF,EAAQG,QAAQ,aAAc,IAC3C,OAAON,EAASO,WAAWF,EAC/B,CACA,OAAmD,KAA5C,IAAAG,OAAML,EAAS,CAAEM,KAAK,GAAtB,CAA8BT,EAAmB,QAODD,EAnBrC,IAACC,CAoBlB,IACAd,IAOYwB,OALNvB,EACT,CAAEJ,QAASJ,IACVI,aAAyC,EAASA,EAAQN,QAAU,EACjE,CAAEM,gBACF4B,EAEd,CAEA,MAAM,WAAEpB,EAAU,OAAEmB,GAAW9B,IAE/B,I","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 \"path-to-regexp\"","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(\"path-to-regexp\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/middleware\");","var __rest = (this && this.__rest) || function (s, e) {\n var t = {};\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\n t[p] = s[p];\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\n t[p[i]] = s[p[i]];\n }\n return t;\n};\nimport { match } from \"path-to-regexp\";\nimport { withAuth } from \"next-auth/middleware\";\n// Catch-all matcher used in Vercel preview environments\nconst previewMatcher = [\n \"/((?!api|_next/static|_next/image|favicon.ico|.*\\\\..*).*)\",\n];\nexport function buildAuthMiddleware(_a = {}) {\n var _b;\n var { matcher = [], callbacks = {}, protectAllRoutes } = _a, rest = __rest(_a, [\"matcher\", \"callbacks\", \"protectAllRoutes\"]);\n const isPreview = process.env.NEXT_PUBLIC_VERCEL_ENV === \"preview\";\n // Decide at runtime whether the current path should be protected\n const shouldProtectPath = (pathname) => {\n if (isPreview || (protectAllRoutes && (matcher === null || matcher === void 0 ? void 0 : matcher.length) === 0)) {\n return true;\n }\n return matcher.some((pattern) => {\n if (!pattern) {\n return false;\n }\n if (pattern.endsWith(\":path*\")) {\n const base = pattern.replace(/\\/:path\\*$/, \"\");\n return pathname.startsWith(base);\n }\n return match(pattern, { end: true })(pathname) !== false;\n });\n };\n const middleware = withAuth((_req) => { }, Object.assign({ pages: {\n signIn: \"/auth/login\",\n }, callbacks: {\n authorized: (_b = callbacks.authorized) !== null && _b !== void 0 ? _b : (({ req, token }) => {\n return shouldProtectPath(req.nextUrl.pathname) ? !!token : true;\n }),\n } }, rest));\n // Only apply matcher config if needed (to avoid enabling middleware unnecessarily)\n const config = isPreview\n ? { matcher: previewMatcher }\n : (matcher === null || matcher === void 0 ? void 0 : matcher.length) > 0\n ? { matcher }\n : undefined;\n return { middleware, config };\n}\n// Default: protect all HTML pages in preview, do nothing in production\nconst { middleware, config } = buildAuthMiddleware();\nexport { config };\nexport default middleware;\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","__rest","s","e","t","p","indexOf","getOwnPropertySymbols","i","length","propertyIsEnumerable","previewMatcher","buildAuthMiddleware","_a","_b","matcher","callbacks","protectAllRoutes","rest","isPreview","process","env","NEXT_PUBLIC_VERCEL_ENV","middleware","withAuth","_req","assign","pages","signIn","authorized","req","token","pathname","nextUrl","some","pattern","endsWith","base","replace","startsWith","match","end","config","undefined"],"sourceRoot":""}
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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/webpack/runtime/define property getters","webpack://snokam/webpack/runtime/hasOwnProperty shorthand","webpack://snokam/webpack/runtime/make namespace object","webpack://snokam/external commonjs \"path-to-regexp\"","webpack://snokam/external commonjs \"next-auth/middleware\"","webpack://snokam/./src/middleware.tsx","webpack://snokam/./src/utils/cookies.ts"],"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(\"path-to-regexp\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/middleware\");","var __rest = (this && this.__rest) || function (s, e) {\n var t = {};\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\n t[p] = s[p];\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\n t[p[i]] = s[p[i]];\n }\n return t;\n};\nimport { match } from \"path-to-regexp\";\nimport { withAuth } from \"next-auth/middleware\";\nimport { getSessionCookieSettings } from \"./utils/cookies\";\n// Catch-all matcher used in Vercel preview environments\nconst previewMatcher = [\n \"/((?!api|_next/static|_next/image|favicon.ico|.*\\\\..*).*)\",\n];\nexport function buildAuthMiddleware(_a = {}) {\n var _b;\n var { matcher = [], callbacks = {}, protectAllRoutes } = _a, rest = __rest(_a, [\"matcher\", \"callbacks\", \"protectAllRoutes\"]);\n const isPreview = process.env.NEXT_PUBLIC_VERCEL_ENV === \"preview\";\n const { name } = getSessionCookieSettings(`${process.env.NEXTAUTH_URL}`);\n // Decide at runtime whether the current path should be protected\n const shouldProtectPath = (pathname) => {\n if (isPreview || (protectAllRoutes && (matcher === null || matcher === void 0 ? void 0 : matcher.length) === 0)) {\n return true;\n }\n return matcher.some((pattern) => {\n if (!pattern) {\n return false;\n }\n if (pattern.endsWith(\":path*\")) {\n const base = pattern.replace(/\\/:path\\*$/, \"\");\n return pathname.startsWith(base);\n }\n return match(pattern, { end: true })(pathname) !== false;\n });\n };\n const middleware = withAuth((_req) => { }, Object.assign({ pages: {\n signIn: \"/auth/login\",\n }, cookies: {\n sessionToken: {\n name,\n },\n }, callbacks: {\n authorized: (_b = callbacks.authorized) !== null && _b !== void 0 ? _b : (({ req, token }) => {\n return shouldProtectPath(req.nextUrl.pathname) ? !!token : true;\n }),\n } }, rest));\n // Only apply matcher config if needed (to avoid enabling middleware unnecessarily)\n const config = isPreview\n ? { matcher: previewMatcher }\n : (matcher === null || matcher === void 0 ? void 0 : matcher.length) > 0\n ? { matcher }\n : undefined;\n return { middleware, config };\n}\n// Default: protect all HTML pages in preview, do nothing in production\nconst { middleware, config } = buildAuthMiddleware();\nexport { config };\nexport default middleware;\n","export function getSessionCookieSettings(nextAuthUrl) {\n const { hostname, protocol } = new URL(nextAuthUrl);\n const secure = protocol === \"https:\";\n const prefix = secure ? \"__Secure-\" : \"\";\n const getTagAndDomain = () => {\n if (hostname === \"localhost\" || /^[\\d.]+$/.test(hostname)) {\n return { tag: \"local\" };\n }\n if (hostname.endsWith(\".test.snokam.no\")) {\n return { tag: \"test\", domain: \".test.snokam.no\" };\n }\n if (hostname.endsWith(\".snokam.no\")) {\n return { tag: \"prod\", domain: \".snokam.no\" };\n }\n const parts = hostname.split(\".\");\n if (parts.length >= 2) {\n const base = parts.slice(-2).join(\".\");\n return { tag: base.replace(/\\./g, \"-\"), domain: `.${base}` };\n }\n return { tag: \"host\" };\n };\n const { tag, domain } = getTagAndDomain();\n const name = `${prefix}next-auth.${tag}.session-token`;\n return { name, domain, secure };\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","__rest","s","e","t","p","indexOf","getOwnPropertySymbols","i","length","propertyIsEnumerable","previewMatcher","buildAuthMiddleware","_a","_b","matcher","callbacks","protectAllRoutes","rest","isPreview","process","env","NEXT_PUBLIC_VERCEL_ENV","name","nextAuthUrl","hostname","protocol","URL","secure","prefix","tag","domain","test","endsWith","parts","split","base","slice","join","replace","getTagAndDomain","getSessionCookieSettings","NEXTAUTH_URL","middleware","withAuth","_req","assign","pages","signIn","cookies","sessionToken","authorized","req","token","pathname","nextUrl","some","pattern","startsWith","match","end","config","undefined"],"sourceRoot":""}
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={542:e=>{e.exports=require("next-auth")},672:e=>{e.exports=require("@azure/msal-node")},983:(e,t,n)=>{n.d(t,{default:()=>d,getNextAuthOptions:()=>l});var o=n(542),r=n.n(o);const i=require("next-auth/providers/azure-ad");var s=n.n(i);const c=()=>{const e="undefined"!=typeof window,t=e&&window.location.hostname.includes("test."),n={scope:"openid profile email offline_access https://graph.microsoft.com/User.Read"};return e&&(n.domain_hint=t?"test.snokam.no":"snokam.no"),n};var a=n(672),u=function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{a(o.next(e))}catch(e){i(e)}}function c(e){try{a(o.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((o=o.apply(e,t||[])).next())}))};const l=e=>{const{name:t,domain:n,secure:o}=function(e){const{hostname:t,protocol:n}=new URL(e),o="https:"===n,r=o?"__Secure-":"",{tag:i,domain:s}=(()=>{if("localhost"===t||/^[\d.]+$/.test(t))return{tag:"local"};if(t.endsWith(".test.snokam.no"))return{tag:"test",domain:".test.snokam.no"};if(t.endsWith(".snokam.no"))return{tag:"prod",domain:".snokam.no"};const e=t.split(".");if(e.length>=2){const t=e.slice(-2).join(".");return{tag:t.replace(/\./g,"-"),domain:`.${t}`}}return{tag:"host"}})();return{name:`${r}next-auth.${i}.session-token`,domain:s,secure:o}}(process.env.NEXTAUTH_URL);return{secret:e.nextAuthSecret,pages:{signIn:"/auth/login"},providers:[s()({clientId:e.clientId,clientSecret:e.clientSecret,tenantId:e.tenantId,authorization:{params:c()}})],cookies:{sessionToken:{name:t,options:{path:"/",httpOnly:!0,sameSite:"lax",secure:o,domain:n}}},callbacks:{signIn(t){return u(this,arguments,void 0,(function*({account:t}){if("production"===process.env.NEXT_PUBLIC_VERCEL_ENV)return!0;const n=new a.ConfidentialClientApplication({auth:{clientId:e.clientId,clientSecret:e.clientSecret,authority:`https://login.microsoftonline.com/${e.tenantId}`}}),{accessToken:o}=yield n.acquireTokenByRefreshToken({scopes:[`${process.env.NEXT_PUBLIC_EMPLOYEES_API_SCOPE}`],refreshToken:null==t?void 0:t.refresh_token});return 200===(yield fetch(`${process.env.NEXT_PUBLIC_EMPLOYEES_API_BASE_URL}/v1.0/protected/me`,{headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json","Cache-Control":"no-cache, no-transform"}})).status||"/auth/login?error=true"}))},jwt(e){return u(this,arguments,void 0,(function*({token:e,account:t}){return(null==t?void 0:t.access_token)&&(e.refreshToken=t.refresh_token,e.expiresAt=t.expires_at),e}))}}}},d=e=>r()(l(e))}},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});var r=n(672);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 s(e){try{a(i.next(e))}catch(e){r(e)}}function c(e){try{a(i.throw(e))}catch(e){r(e)}}function a(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(s,c)}a((i=i.apply(t,n||[])).next())}));var t,n,o,i};var s=n(983);const c=require("next-auth/jwt");var a=n(542);const u=require("next-auth/next"),l={Routes:s.default,Token:function(e){return t=this,n=void 0,i=function*(){const{req:t,res:n,authConfig:o}=e,i=yield(0,a.getServerSession)(t,n,(0,s.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,c.getToken)({req:t,secret:e});if(!i)return n.status(500).end("Failed to get refetch token");const s=new r.ConfidentialClientApplication({auth:{clientId:o.clientId,clientSecret:o.clientSecret,authority:`https://login.microsoftonline.com/${o.tenantId}`}}),a=yield s.acquireTokenByRefreshToken({scopes:[t.body.scope],refreshToken:null==i?void 0:i.refreshToken});return a?n.status(200).json({accessToken:null==a?void 0:a.accessToken,expiresOn:Math.floor(a.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 s(e){try{a(i.next(e))}catch(e){r(e)}}function c(e){try{a(i.throw(e))}catch(e){r(e)}}function a(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(s,c)}a((i=i.apply(t,n||[])).next())}));var t,n,o,i}};return o})()));
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")},672:e=>{e.exports=require("@azure/msal-node")},983:(e,t,n)=>{n.d(t,{default:()=>d,getNextAuthOptions:()=>l});var o=n(542),r=n.n(o);const i=require("next-auth/providers/azure-ad");var s=n.n(i);const c=()=>{const e="undefined"!=typeof window,t=e&&window.location.hostname.includes("test."),n={scope:"openid profile email offline_access https://graph.microsoft.com/User.Read"};return e&&(n.domain_hint=t?"test.snokam.no":"snokam.no"),n};var a=n(672),u=function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{a(o.next(e))}catch(e){i(e)}}function c(e){try{a(o.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((o=o.apply(e,t||[])).next())}))};const l=e=>{const{name:t,domain:n,secure:o}=function(e){const{hostname:t,protocol:n}=new URL(e),o="https:"===n,r=o?"__Secure-":"",{tag:i,domain:s}=(()=>{if("localhost"===t||/^[\d.]+$/.test(t))return{tag:"local"};if(t.endsWith(".test.snokam.no"))return{tag:"test",domain:".test.snokam.no"};if(t.endsWith(".snokam.no"))return{tag:"prod",domain:".snokam.no"};const e=t.split(".");if(e.length>=2){const t=e.slice(-2).join(".");return{tag:t.replace(/\./g,"-"),domain:`.${t}`}}return{tag:"host"}})();return{name:`${r}next-auth.${i}.session-token`,domain:s,secure:o}}(process.env.NEXTAUTH_URL);return{secret:e.nextAuthSecret,pages:{signIn:"/auth/login"},providers:[s()({clientId:e.clientId,clientSecret:e.clientSecret,tenantId:e.tenantId,authorization:{params:c()}})],cookies:{sessionToken:{name:t,options:{path:"/",httpOnly:!0,sameSite:"lax",secure:o,domain:n}}},callbacks:{signIn(t){return u(this,arguments,void 0,(function*({account:t}){if("production"===process.env.NEXT_PUBLIC_VERCEL_ENV)return!0;const n=new a.ConfidentialClientApplication({auth:{clientId:e.clientId,clientSecret:e.clientSecret,authority:`https://login.microsoftonline.com/${e.tenantId}`}}),{accessToken:o}=yield n.acquireTokenByRefreshToken({scopes:[`${process.env.NEXT_PUBLIC_EMPLOYEES_API_SCOPE}`],refreshToken:null==t?void 0:t.refresh_token});return 200===(yield fetch(`${process.env.NEXT_PUBLIC_EMPLOYEES_API_BASE_URL}/v1.0/protected/me`,{headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json","Cache-Control":"no-cache, no-transform"}})).status||"/auth/login?error=true"}))},jwt(e){return u(this,arguments,void 0,(function*({token:e,account:t}){return(null==t?void 0:t.access_token)&&(e.refreshToken=t.refresh_token,e.expiresAt=t.expires_at),e}))}}}},d=e=>r()(l(e))}},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});var r=n(672);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 s(e){try{a(i.next(e))}catch(e){r(e)}}function c(e){try{a(i.throw(e))}catch(e){r(e)}}function a(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(s,c)}a((i=i.apply(t,n||[])).next())}));var t,n,o,i};var s=n(983);const c=require("next-auth/jwt");var a=n(542);const u=require("next-auth/next"),l={Routes:s.default,Token:function(e){return t=this,n=void 0,i=function*(){const{req:t,res:n,authConfig:o}=e,i=(0,s.getNextAuthOptions)(o),u=yield(0,a.getServerSession)(t,n,i);if(!(null==u?void 0:u.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,s=yield(0,c.getToken)({req:t,secret:e,cookieName:i.cookies.sessionToken.name});if(!s)return n.status(500).end("Failed to get refetch token");const a=new r.ConfidentialClientApplication({auth:{clientId:o.clientId,clientSecret:o.clientSecret,authority:`https://login.microsoftonline.com/${o.tenantId}`}}),u=yield a.acquireTokenByRefreshToken({scopes:[t.body.scope],refreshToken:null==s?void 0:s.refreshToken});return u?n.status(200).json({accessToken:null==u?void 0:u.accessToken,expiresOn:Math.floor(u.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 s(e){try{a(i.next(e))}catch(e){r(e)}}function c(e){try{a(i.throw(e))}catch(e){r(e)}}function a(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(s,c)}a((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,kCCTTH,EAAOD,QAAUK,QAAQ,Y,UCAzBJ,EAAOD,QAAUK,QAAQ,mB,sFCAzB,MAAM,EAA+BA,QAAQ,gC,aCAtC,MAAMC,EAAuB,KAChC,MAAMC,EAA8B,oBAAXC,OACnBC,EAASF,GAAaC,OAAOE,SAASC,SAASC,SAAS,SACxDC,EAAS,CACXC,MAAO,6EAKX,OAHIP,IACAM,EAAOE,YAAcN,EAAS,iBAAmB,aAE9CI,CAAM,E,aCTbG,EAAwC,SAAUC,EAASC,EAAYC,EAAGC,GAE1E,OAAO,IAAKD,IAAMA,EAAIE,WAAU,SAAUC,EAASC,GAC/C,SAASC,EAAUC,GAAS,IAAMC,EAAKN,EAAUO,KAAKF,GAAS,CAAE,MAAOG,GAAKL,EAAOK,EAAI,CAAE,CAC1F,SAASC,EAASJ,GAAS,IAAMC,EAAKN,EAAiB,MAAEK,GAAS,CAAE,MAAOG,GAAKL,EAAOK,EAAI,CAAE,C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D,YACrGgE,UAAWC,KAAKC,MAAMJ,EAAkBE,UAAUG,UAAY,OAJvDd,EAAI3C,OAAO,KAAKgD,IAAI,6BAMnC,CACA,MAAOhH,GACHsG,QAAQC,MAAM,wBAAyBvG,GACvC2G,EAAI3C,OAAO,KAAKgD,IAAI,wBACxB,CACJ,EAlDO,KAFgEzH,OAcxC,KAZbA,EAAIE,WAAU,SAAUC,EAASC,GAC/C,SAASC,EAAUC,GAAS,IAAMC,EAAKN,EAAUO,KAAKF,GAAS,CAAE,MAAOG,GAAKL,EAAOK,EAAI,CAAE,CAC1F,SAASC,EAASJ,GAAS,IAAMC,EAAKN,EAAiB,MAAEK,GAAS,CAAE,MAAOG,GAAKL,EAAOK,EAAI,CAAE,CAC7F,SAASF,EAAKI,GAJlB,IAAeL,EAIaK,EAAOC,KAAOT,EAAQQ,EAAOL,QAJ1CA,EAIyDK,EAAOL,MAJhDA,aAAiBN,EAAIM,EAAQ,IAAIN,GAAE,SAAUG,GAAWA,EAAQG,EAAQ,KAIjBO,KAAKR,EAAWK,EAAW,CAC7GH,GAAMN,EAAYA,EAAUa,MAAMhB,EAASC,GAAc,KAAKS,OAClE,IAPwC,IAAUV,EAASC,EAAYC,EAAGC,CAqD9E,G","sources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/external commonjs \"next-auth\"","webpack://snokam/external commonjs \"@azure/msal-node\"","webpack://snokam/external commonjs \"next-auth/providers/azure-ad\"","webpack://snokam/./src/utils/params.ts","webpack://snokam/./src/options.tsx","webpack://snokam/./src/utils/cookies.ts","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/./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 ","module.exports = require(\"next-auth\");","module.exports = require(\"@azure/msal-node\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/providers/azure-ad\");","export const getDefaultAuthParams = () => {\n const isBrowser = typeof window !== \"undefined\";\n const isTest = isBrowser && window.location.hostname.includes(\"test.\");\n const params = {\n scope: `openid profile email offline_access https://graph.microsoft.com/User.Read`,\n };\n if (isBrowser) {\n params.domain_hint = isTest ? \"test.snokam.no\" : \"snokam.no\";\n }\n return params;\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 NextAuth from \"next-auth\";\nimport AzureADProvider from \"next-auth/providers/azure-ad\";\nimport { getDefaultAuthParams } from \"./utils/params\";\nimport { ConfidentialClientApplication } from \"@azure/msal-node\";\nimport { getSessionCookieSettings } from \"./utils/cookies\";\nexport const getNextAuthOptions = (config) => {\n const { name, domain, secure } = getSessionCookieSettings(process.env.NEXTAUTH_URL);\n return {\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: getDefaultAuthParams(),\n },\n }),\n ],\n cookies: {\n sessionToken: {\n name,\n options: {\n path: \"/\",\n httpOnly: true,\n sameSite: \"lax\",\n secure,\n domain,\n },\n },\n },\n callbacks: {\n signIn(_a) {\n return __awaiter(this, arguments, void 0, function* ({ account }) {\n const isProd = process.env.NEXT_PUBLIC_VERCEL_ENV === \"production\";\n if (isProd) {\n return true;\n }\n const cca = new ConfidentialClientApplication({\n auth: {\n clientId: config.clientId,\n clientSecret: config.clientSecret,\n authority: `https://login.microsoftonline.com/${config.tenantId}`,\n },\n });\n const { accessToken } = yield cca.acquireTokenByRefreshToken({\n scopes: [`${process.env.NEXT_PUBLIC_EMPLOYEES_API_SCOPE}`],\n refreshToken: account === null || account === void 0 ? void 0 : account.refresh_token,\n });\n const res = yield fetch(`${process.env.NEXT_PUBLIC_EMPLOYEES_API_BASE_URL}/v1.0/protected/me`, {\n headers: {\n Authorization: `Bearer ${accessToken}`,\n \"Content-Type\": \"application/json\",\n \"Cache-Control\": \"no-cache, no-transform\",\n },\n });\n if (res.status === 200) {\n return true;\n }\n return \"/auth/login?error=true\";\n });\n },\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.refreshToken = account.refresh_token;\n token.expiresAt = account.expires_at;\n }\n return token;\n });\n },\n },\n };\n};\nexport default (config) => NextAuth(getNextAuthOptions(config));\n","export function getSessionCookieSettings(nextAuthUrl) {\n const { hostname, protocol } = new URL(nextAuthUrl);\n const secure = protocol === \"https:\";\n const prefix = secure ? \"__Secure-\" : \"\";\n const getTagAndDomain = () => {\n if (hostname === \"localhost\" || /^[\\d.]+$/.test(hostname)) {\n return { tag: \"local\" };\n }\n if (hostname.endsWith(\".test.snokam.no\")) {\n return { tag: \"test\", domain: \".test.snokam.no\" };\n }\n if (hostname.endsWith(\".snokam.no\")) {\n return { tag: \"prod\", domain: \".snokam.no\" };\n }\n const parts = hostname.split(\".\");\n if (parts.length >= 2) {\n const base = parts.slice(-2).join(\".\");\n return { tag: base.replace(/\\./g, \"-\"), domain: `.${base}` };\n }\n return { tag: \"host\" };\n };\n const { tag, domain } = getTagAndDomain();\n const name = `${prefix}next-auth.${tag}.session-token`;\n return { name, domain, secure };\n}\n","// 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};","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","getDefaultAuthParams","isBrowser","window","isTest","location","hostname","includes","params","scope","domain_hint","__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","value","step","next","e","rejected","result","done","then","apply","getNextAuthOptions","config","name","domain","secure","nextAuthUrl","protocol","URL","prefix","tag","test","endsWith","parts","split","length","base","slice","join","replace","getTagAndDomain","getSessionCookieSettings","process","env","NEXTAUTH_URL","secret","nextAuthSecret","pages","signIn","providers","clientId","clientSecret","tenantId","authorization","cookies","sessionToken","options","path","httpOnly","sameSite","callbacks","_a","arguments","account","NEXT_PUBLIC_VERCEL_ENV","cca","ConfidentialClientApplication","auth","authority","accessToken","acquireTokenByRefreshToken","scopes","NEXT_PUBLIC_EMPLOYEES_API_SCOPE","refreshToken","refresh_token","fetch","NEXT_PUBLIC_EMPLOYEES_API_BASE_URL","headers","Authorization","status","jwt","token","access_token","expiresAt","expires_at","__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","response","acquireTokenByClientCredential","map","catch","console","error","Routes","Token","req","res","authConfig","session","getServerSession","user","end","body","refetchTokenResult","getToken","accessTokenResult","json","expiresOn","Math","floor","getTime"],"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,kCCTTH,EAAOD,QAAUK,QAAQ,Y,UCAzBJ,EAAOD,QAAUK,QAAQ,mB,sFCAzB,MAAM,EAA+BA,QAAQ,gC,aCAtC,MAAMC,EAAuB,KAChC,MAAMC,EAA8B,oBAAXC,OACnBC,EAASF,GAAaC,OAAOE,SAASC,SAASC,SAAS,SACxDC,EAAS,CACXC,MAAO,6EAKX,OAHIP,IACAM,EAAOE,YAAcN,EAAS,iBAAmB,aAE9CI,CAAM,E,aCTbG,EAAwC,SAAUC,EAASC,EAAYC,EAAGC,GAE1E,OAAO,IAAKD,IAAMA,EAAIE,WAAU,SAAUC,EAASC,GAC/C,SAASC,EAAUC,GAAS,IAAMC,EAAKN,EAAUO,KAAKF,GAAS,CAAE,MAAOG,GAAKL,EAAOK,EAAI,CAAE,CAC1F,SAASC,EAASJ,GAAS,IAAMC,EAAKN,EAAiB,MAAEK,GAAS,CAAE,MAAOG,GAAKL,EAAOK,EAAI,CAAE,CAC7F,SAASF,EAAKI,GAJlB,IAAeL,EAIaK,EAAOC,KAAOT,EAAQQ,EAAOL,QAJ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C,KAAKC,MAAMJ,EAAkBE,UAAUG,UAAY,OAJvDf,EAAI3C,OAAO,KAAKgD,IAAI,6BAMnC,CACA,MAAOhH,GACHsG,QAAQC,MAAM,wBAAyBvG,GACvC2G,EAAI3C,OAAO,KAAKgD,IAAI,wBACxB,CACJ,EAvDO,KAFgEzH,OAcxC,KAZbA,EAAIE,WAAU,SAAUC,EAASC,GAC/C,SAASC,EAAUC,GAAS,IAAMC,EAAKN,EAAUO,KAAKF,GAAS,CAAE,MAAOG,GAAKL,EAAOK,EAAI,CAAE,CAC1F,SAASC,EAASJ,GAAS,IAAMC,EAAKN,EAAiB,MAAEK,GAAS,CAAE,MAAOG,GAAKL,EAAOK,EAAI,CAAE,CAC7F,SAASF,EAAKI,GAJlB,IAAeL,EAIaK,EAAOC,KAAOT,EAAQQ,EAAOL,QAJ1CA,EAIyDK,EAAOL,MAJhDA,aAAiBN,EAAIM,EAAQ,IAAIN,GAAE,SAAUG,GAAWA,EAAQG,EAAQ,KAIjBO,KAAKR,EAAWK,EAAW,CAC7GH,GAAMN,EAAYA,EAAUa,MAAMhB,EAASC,GAAc,KAAKS,OAClE,IAPwC,IAAUV,EAASC,EAAYC,EAAGC,CA0D9E,G","sources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/external commonjs \"next-auth\"","webpack://snokam/external commonjs \"@azure/msal-node\"","webpack://snokam/external commonjs \"next-auth/providers/azure-ad\"","webpack://snokam/./src/utils/params.ts","webpack://snokam/./src/options.tsx","webpack://snokam/./src/utils/cookies.ts","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/./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 ","module.exports = require(\"next-auth\");","module.exports = require(\"@azure/msal-node\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/providers/azure-ad\");","export const getDefaultAuthParams = () => {\n const isBrowser = typeof window !== \"undefined\";\n const isTest = isBrowser && window.location.hostname.includes(\"test.\");\n const params = {\n scope: `openid profile email offline_access https://graph.microsoft.com/User.Read`,\n };\n if (isBrowser) {\n params.domain_hint = isTest ? \"test.snokam.no\" : \"snokam.no\";\n }\n return params;\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 NextAuth from \"next-auth\";\nimport AzureADProvider from \"next-auth/providers/azure-ad\";\nimport { getDefaultAuthParams } from \"./utils/params\";\nimport { ConfidentialClientApplication } from \"@azure/msal-node\";\nimport { getSessionCookieSettings } from \"./utils/cookies\";\nexport const getNextAuthOptions = (config) => {\n const { name, domain, secure } = getSessionCookieSettings(process.env.NEXTAUTH_URL);\n return {\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: getDefaultAuthParams(),\n },\n }),\n ],\n cookies: {\n sessionToken: {\n name,\n options: {\n path: \"/\",\n httpOnly: true,\n sameSite: \"lax\",\n secure,\n domain,\n },\n },\n },\n callbacks: {\n signIn(_a) {\n return __awaiter(this, arguments, void 0, function* ({ account }) {\n const isProd = process.env.NEXT_PUBLIC_VERCEL_ENV === \"production\";\n if (isProd) {\n return true;\n }\n const cca = new ConfidentialClientApplication({\n auth: {\n clientId: config.clientId,\n clientSecret: config.clientSecret,\n authority: `https://login.microsoftonline.com/${config.tenantId}`,\n },\n });\n const { accessToken } = yield cca.acquireTokenByRefreshToken({\n scopes: [`${process.env.NEXT_PUBLIC_EMPLOYEES_API_SCOPE}`],\n refreshToken: account === null || account === void 0 ? void 0 : account.refresh_token,\n });\n const res = yield fetch(`${process.env.NEXT_PUBLIC_EMPLOYEES_API_BASE_URL}/v1.0/protected/me`, {\n headers: {\n Authorization: `Bearer ${accessToken}`,\n \"Content-Type\": \"application/json\",\n \"Cache-Control\": \"no-cache, no-transform\",\n },\n });\n if (res.status === 200) {\n return true;\n }\n return \"/auth/login?error=true\";\n });\n },\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.refreshToken = account.refresh_token;\n token.expiresAt = account.expires_at;\n }\n return token;\n });\n },\n },\n };\n};\nexport default (config) => NextAuth(getNextAuthOptions(config));\n","export function getSessionCookieSettings(nextAuthUrl) {\n const { hostname, protocol } = new URL(nextAuthUrl);\n const secure = protocol === \"https:\";\n const prefix = secure ? \"__Secure-\" : \"\";\n const getTagAndDomain = () => {\n if (hostname === \"localhost\" || /^[\\d.]+$/.test(hostname)) {\n return { tag: \"local\" };\n }\n if (hostname.endsWith(\".test.snokam.no\")) {\n return { tag: \"test\", domain: \".test.snokam.no\" };\n }\n if (hostname.endsWith(\".snokam.no\")) {\n return { tag: \"prod\", domain: \".snokam.no\" };\n }\n const parts = hostname.split(\".\");\n if (parts.length >= 2) {\n const base = parts.slice(-2).join(\".\");\n return { tag: base.replace(/\\./g, \"-\"), domain: `.${base}` };\n }\n return { tag: \"host\" };\n };\n const { tag, domain } = getTagAndDomain();\n const name = `${prefix}next-auth.${tag}.session-token`;\n return { name, domain, secure };\n}\n","// 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};","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 options = getNextAuthOptions(authConfig);\n const session = yield getServerSession(req, res, options);\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({\n req,\n secret: nextAuthSecret,\n cookieName: options.cookies.sessionToken.name,\n });\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","getDefaultAuthParams","isBrowser","window","isTest","location","hostname","includes","params","scope","domain_hint","__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","value","step","next","e","rejected","result","done","then","apply","getNextAuthOptions","config","name","domain","secure","nextAuthUrl","protocol","URL","prefix","tag","test","endsWith","parts","split","length","base","slice","join","replace","getTagAndDomain","getSessionCookieSettings","process","env","NEXTAUTH_URL","secret","nextAuthSecret","pages","signIn","providers","clientId","clientSecret","tenantId","authorization","cookies","sessionToken","options","path","httpOnly","sameSite","callbacks","_a","arguments","account","NEXT_PUBLIC_VERCEL_ENV","cca","ConfidentialClientApplication","auth","authority","accessToken","acquireTokenByRefreshToken","scopes","NEXT_PUBLIC_EMPLOYEES_API_SCOPE","refreshToken","refresh_token","fetch","NEXT_PUBLIC_EMPLOYEES_API_BASE_URL","headers","Authorization","status","jwt","token","access_token","expiresAt","expires_at","__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","response","acquireTokenByClientCredential","map","catch","console","error","Routes","Token","req","res","authConfig","session","getServerSession","user","end","body","refetchTokenResult","getToken","cookieName","accessTokenResult","json","expiresOn","Math","floor","getTime"],"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.2.6",
4
+ "version": "2.2.7",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -67,5 +67,5 @@
67
67
  ]
68
68
  }
69
69
  },
70
- "gitHead": "948f4893d93c1ee8f854d5732f96a3eaa4d98729"
70
+ "gitHead": "8ba7e08c42b1815a9d93483c2e717753bb2cede0"
71
71
  }