orange-auth 1.2.0 → 1.3.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/COPYING +674 -0
- package/README.md +81 -124
- package/dist/IProvider-BH8TjziQ.d.mts +461 -0
- package/dist/IProvider-BH8TjziQ.d.mts.map +1 -0
- package/dist/client.d.ts +470 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +19 -0
- package/dist/client.js.map +1 -0
- package/dist/index-D-dMFhOD.d.mts +55 -0
- package/dist/index-D-dMFhOD.d.mts.map +1 -0
- package/dist/index-DjPz5vTX.d.mts +37 -0
- package/dist/index-DjPz5vTX.d.mts.map +1 -0
- package/dist/index.d.mts +70 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +19 -0
- package/dist/index.mjs.map +1 -0
- package/dist/providers.d.mts +20 -0
- package/dist/providers.mjs +19 -0
- package/dist/providers.mjs.map +1 -0
- package/dist/strategies.d.mts +20 -0
- package/dist/strategies.mjs +19 -0
- package/dist/strategies.mjs.map +1 -0
- package/package.json +53 -31
- package/LICENSE +0 -21
- package/dist/@types/globals.d.ts +0 -97
- package/dist/@types/globals.d.ts.map +0 -1
- package/dist/@types/globals.js +0 -1
- package/dist/@types/internals.d.ts +0 -13
- package/dist/@types/internals.d.ts.map +0 -1
- package/dist/@types/internals.js +0 -1
- package/dist/functions/index.d.ts +0 -3
- package/dist/functions/index.d.ts.map +0 -1
- package/dist/functions/index.js +0 -2
- package/dist/functions/jwt.d.ts +0 -11
- package/dist/functions/jwt.d.ts.map +0 -1
- package/dist/functions/jwt.js +0 -20
- package/dist/functions/urlencodedToJson.d.ts +0 -2
- package/dist/functions/urlencodedToJson.d.ts.map +0 -1
- package/dist/functions/urlencodedToJson.js +0 -8
- package/dist/index.d.ts +0 -5
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -4
- package/dist/lib.d.ts +0 -46
- package/dist/lib.d.ts.map +0 -1
- package/dist/lib.js +0 -161
- package/dist/providers/Credentials.d.ts +0 -33
- package/dist/providers/Credentials.d.ts.map +0 -1
- package/dist/providers/Credentials.js +0 -42
- package/dist/providers/IProvider.d.ts +0 -29
- package/dist/providers/IProvider.d.ts.map +0 -1
- package/dist/providers/IProvider.js +0 -20
- package/dist/providers/index.d.ts +0 -3
- package/dist/providers/index.d.ts.map +0 -1
- package/dist/providers/index.js +0 -2
- package/dist/strategies/IStrategy.d.ts +0 -48
- package/dist/strategies/IStrategy.d.ts.map +0 -1
- package/dist/strategies/IStrategy.js +0 -11
- package/dist/strategies/index.d.ts +0 -3
- package/dist/strategies/index.d.ts.map +0 -1
- package/dist/strategies/index.js +0 -2
- package/dist/strategies/jwt.d.ts +0 -19
- package/dist/strategies/jwt.d.ts.map +0 -1
- package/dist/strategies/jwt.js +0 -51
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../packages/orange-auth/lib.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAeA;;cAAa,UAAA,GAAU,MAAA,EAAA,QAAA;aA8FtB,SAAA;;;;;;;aAnDyC,MAAA;;;;;cAK0E,MAAA;;;;;;;EAmCtC;;;;;;;;;;;;;;;;;IAAlD,OAAA,EAAS,KAAA,CAAM,OAAA,GAAU,MAAA;EAAA,MAAyB,OAAA,CAAA,OAAA;AAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Orange Auth, a simple modular auth library
|
|
3
|
+
Copyright (C) 2026 Mathieu Dery
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License
|
|
16
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import{params as e}from"@universal-middleware/core";import{join as t}from"node:path/posix";import{getCookie as n,setCookie as r}from"@universal-middleware/core/cookie";var i=Object.defineProperty,a=(e,t)=>{let n={};for(var r in e)i(n,r,{get:e[r],enumerable:!0});return t&&i(n,Symbol.toStringTag,{value:`Module`}),n};const o=async({req:e,globalCfg:t,provider:n})=>{let i=await n.logIn(e,t).catch(()=>null);if(i==null)return new Response(null,{status:400});let a=await t.callbacks?.login?.({headers:e.headers,token:i.token,session:i.session});if(a===!1)return new Response(`Bad Request`,{status:400});if(typeof a==`string`){let e=new Headers;return e.set(`Location`,a),new Response(null,{status:308,headers:e})}let o=new Response(null,{status:200});return r(o,t.cookieName,i.token,t.cookieSettings),o};async function s(e,t){if(t.headers==null)return{session:null,token:null};let r=n(new Request(`http://localhost`,{headers:t.headers}),e.cookieName);if(r==null)return{session:null,token:null};let i=r.value;return{session:await e.strategy.deserialize(i,e),token:i}}const c=async({req:e,globalCfg:t})=>{let n=await s(t,e);n.session!=null&&n.token!=null&&await t.callbacks?.logout?.({headers:e.headers,token:n.token,session:n.session}),await t.strategy.logOut(e,t);let i=new Response(null,{status:200});return r(i,t.cookieName,`deleted`,{...t.cookieSettings,expires:new Date(0),maxAge:void 0}),i};var l=a({login:()=>o,logout:()=>c});const u=(n=>{let{secret:r,strategy:i,cookieName:a,providers:o,cookieSettings:c,basePath:u,callbacks:d}=n,f=t(u,`:action`,`:provider`);if(r==null)throw Error(`[ERROR]: Auth secret missing! Make sure to set the "secret" variable in the auth's config.`);if(i==null)throw Error(`[ERROR]: No strategy chosen! Make sure to set the "strategy" variable in the auth's config.`);let p={cookieName:a??`orange.auth`,providers:o??[],secret:r,strategy:i,cookieSettings:{path:`/`,httpOnly:!0,sameSite:`lax`,secure:!0,maxAge:3600,...c},callbacks:d};return{handler:()=>async(t,n,r)=>{if(t.method.toUpperCase()!==`POST`)return new Response(`Method Not Allowed`,{status:405});let i=e(t,r,f);if(i?.action==null||i.provider==null)throw Error(`[ERROR]: Base path is missing! Make sure to set the "basePath" variable in the auth's config.`);let a=i.provider,s=o.find(e=>e.ID===a);if(s==null)return new Response(`Page not found`,{status:404});let c=l[i.action];return c==null?new Response(`Page not found`,{status:404}):Promise.resolve(c({globalCfg:p,provider:s,req:t}))},clientConfig:{basePath:n.basePath,providers:p.providers.map(e=>e.ID),cookieName:p.cookieName},getSession:e=>s(p,e).then(e=>e.session)}});export{u as CreateAuth};
|
|
19
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["actions"],"sources":["../packages/orange-auth/actions/login.ts","../packages/orange-auth/functions/getSession.ts","../packages/orange-auth/actions/logout.ts","../packages/orange-auth/actions/index.ts","../packages/orange-auth/lib.ts"],"sourcesContent":["import { setCookie } from \"@universal-middleware/core/cookie\";\n\nimport type { IAction } from \"./IAction\";\n\nconst login: IAction = async ({ req, globalCfg, provider }) => {\n // Use the found provider to login\n const params = await provider.logIn(req, globalCfg).catch(() => null);\n\n // If failed, return Bad Request response\n if (params == null) return new Response(null, { status: 400 });\n\n // Run the login callback\n const customRes = await globalCfg.callbacks?.login?.({\n headers: req.headers,\n token: params.token,\n session: params.session,\n });\n\n // If the result is false, fail the login\n if (customRes === false) {\n return new Response(\"Bad Request\", { status: 400 });\n }\n\n // If the result is a string, assume it is a redirection path\n if (typeof customRes === \"string\") {\n const headers = new Headers();\n headers.set(\"Location\", customRes);\n\n return new Response(null, { status: 308, headers });\n }\n\n const res = new Response(null, { status: 200 });\n\n // Creates the set-cookie header\n setCookie(res, globalCfg.cookieName, params.token, globalCfg.cookieSettings);\n\n // And send it\n return res;\n};\n\nexport { login };\n","import { getCookie } from \"@universal-middleware/core/cookie\";\n\nimport type { ConfigOptions, Maybe } from \"../@types/internals\";\n\n/**\n * Deserialize a user's session based of the headers\n * @param globalCfg The global auth config\n * @param req An object having a headers field\n * @returns A user's token and session, if found and valid\n */\nasync function getSession(globalCfg: ConfigOptions, req: { headers: Maybe<Headers | Record<string, string>> }) {\n if (req.headers == null)\n return {\n session: null,\n token: null,\n };\n\n const r = new Request(\"http://localhost\", { headers: req.headers });\n\n // Tries to extract the specific cookie.\n const cookie = getCookie(r, globalCfg.cookieName);\n\n if (cookie == null)\n return {\n session: null,\n token: null,\n };\n\n const token = cookie.value;\n // Tries to deserialize it\n return {\n session: await globalCfg.strategy.deserialize(token, globalCfg),\n token,\n };\n}\n\nexport { getSession };\n","import { setCookie } from \"@universal-middleware/core/cookie\";\n\nimport { getSession } from \"../functions/index\";\nimport type { IAction } from \"./IAction\";\n\nconst logout: IAction = async ({ req, globalCfg }) => {\n const params = await getSession(globalCfg, req);\n\n // If there is no session, no need to call the callback\n if (params.session != null && params.token != null) {\n await globalCfg.callbacks?.logout?.({\n headers: req.headers,\n token: params.token,\n session: params.session,\n });\n }\n\n // Use the strategy to logout\n await globalCfg.strategy.logOut(req, globalCfg);\n\n const res = new Response(null, { status: 200 });\n // Clears the header.\n setCookie(res, globalCfg.cookieName, \"deleted\", {\n // Use the same cookie config, but make sure it is expired\n ...globalCfg.cookieSettings,\n expires: new Date(0),\n maxAge: undefined,\n });\n\n // And send it\n return res;\n};\n\nexport { logout };\n","export * from \"./login\";\nexport * from \"./logout\";\n","import { type Get, params, type UniversalHandler } from \"@universal-middleware/core\";\nimport { join } from \"node:path/posix\";\n\nimport type { ClientConfigOptions } from \"../client/@types/globals\";\nimport type { ConfigOptionsProps, Session } from \"./@types/globals\";\nimport type { ConfigOptions, Maybe } from \"./@types/internals\";\nimport * as actions from \"./actions/index\";\nimport { getSession } from \"./functions/index\";\nimport type { Actions } from \"./providers/IProvider\";\n\n/**\n * Initializes the auth. This should be called once per backend.\n * @param req Something that has a `headers` field; either a Headers instance, or just a plain object.\n * @returns A session if found and valid, or `null`.\n */\nexport const CreateAuth = ((config) => {\n const { secret, strategy, cookieName, providers, cookieSettings, basePath: basePathAsProp, callbacks } = config;\n\n // Adds the dynamic actions to the base url\n const basePath = join(basePathAsProp, \":action\", \":provider\");\n\n if (secret == null) {\n throw new Error('[ERROR]: Auth secret missing! Make sure to set the \"secret\" variable in the auth\\'s config.');\n }\n\n if (strategy == null) {\n throw new Error('[ERROR]: No strategy chosen! Make sure to set the \"strategy\" variable in the auth\\'s config.');\n }\n\n // We set the global config on startup, and not on the route handler,\n // otherwise a session cannot be accessed until someone logs in\n const globalCfg = {\n cookieName: cookieName ?? \"orange.auth\",\n providers: providers ?? [],\n secret,\n strategy,\n cookieSettings: {\n path: \"/\",\n httpOnly: true,\n sameSite: \"lax\",\n secure: true,\n maxAge: 3600,\n ...cookieSettings,\n },\n callbacks,\n } satisfies ConfigOptions;\n\n return {\n /**\n * Universal handler route. You can use this with the `createHandler()` method\n * @returns\n */\n handler: () => async (req, _, runtime) => {\n if (req.method.toUpperCase() !== \"POST\") {\n // Do not accept other methods\n return new Response(\"Method Not Allowed\", { status: 405 });\n }\n\n // Tries to get the action and provider info from the url\n const routeParams = params(req, runtime, basePath);\n\n if (routeParams?.[\"action\"] == null || routeParams[\"provider\"] == null) {\n throw new Error(\n '[ERROR]: Base path is missing! Make sure to set the \"basePath\" variable in the auth\\'s config.',\n );\n }\n\n // Finds the requested provider by name\n const path = routeParams[\"provider\"];\n const provider = providers.find((p) => p.ID === path);\n\n if (provider == null) {\n return new Response(\"Page not found\", { status: 404 });\n }\n\n const actionParam = routeParams[\"action\"] as Actions;\n\n const action = actions[actionParam];\n\n if (action == null) {\n // If a wrong action is requested, return a 404\n return new Response(\"Page not found\", { status: 404 });\n }\n\n // Handles each action independently\n return Promise.resolve(action({ globalCfg, provider, req }));\n },\n clientConfig: {\n basePath: config.basePath,\n providers: globalCfg.providers.map((p) => p.ID),\n cookieName: globalCfg.cookieName,\n },\n /**\n * Deserialize a user's session.\n * @param globalCfg The global auth config\n * @param req An object having a headers field\n * @returns A user's token and session, if found and valid\n */\n getSession: (req: { headers: Maybe<Headers | Record<string, string>> }) =>\n // Only returns the session\n getSession(globalCfg, req).then((doc) => doc.session),\n };\n}) satisfies Get<\n [config: ConfigOptionsProps],\n {\n clientConfig: ClientConfigOptions;\n handler: Get<[], UniversalHandler>;\n getSession: (req: { headers: Maybe<Headers | Record<string, string>> }) => Promise<Session | null>;\n }\n>;\n"],"mappings":"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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Orange Auth, a simple modular auth library
|
|
3
|
+
Copyright (C) 2026 Mathieu Dery
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License
|
|
16
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import { n as IProvider, t as Actions } from "./IProvider-BH8TjziQ.mjs";
|
|
19
|
+
import { n as CredentialsConfig, t as Credentials } from "./index-D-dMFhOD.mjs";
|
|
20
|
+
export { Actions, Credentials, CredentialsConfig, IProvider };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Orange Auth, a simple modular auth library
|
|
3
|
+
Copyright (C) 2026 Mathieu Dery
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License
|
|
16
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
function e(e){return Object.fromEntries(e.trim().split(`&`).map(e=>e.split(`=`)).filter(e=>e.length===2).map(e=>e.map(decodeURIComponent)))}var t=class{__ID;constructor(e){this.__ID=e}get ID(){return this.__ID}},n=class extends t{config;constructor(e){super(e.name??`credentials`),this.config=e}async logIn(t,n){let r=(t.headers.get(`Content-Type`)?.split(`;`)[0]??`text/plain`).toLowerCase(),i;switch(r){case`application/json`:i=await t.json();break;case`application/x-www-urlencoded`:i=await t.text().then(e);break;case`multipart/form-data`:{let e=await t.formData();i=Object.fromEntries(e)}break;default:return null}let a=await this.config.authorize(i);if(a==null)return null;let o=await n.strategy.serialize(a,n).catch(e=>(console.log(e),null));return o==null?null:{session:a,token:o}}};export{n as Credentials,t as IProvider};
|
|
19
|
+
//# sourceMappingURL=providers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.mjs","names":[],"sources":["../packages/orange-auth/functions/urlencodedToJson.ts","../packages/orange-auth/providers/IProvider.ts","../packages/orange-auth/providers/Credentials.ts"],"sourcesContent":["export function urlencodedToJson<T extends object = object>(value: string): T {\n return Object.fromEntries(\n value\n .trim()\n .split(\"&\")\n .map((s) => s.split(\"=\"))\n .filter((pair) => pair.length === 2)\n .map((pair) => pair.map(decodeURIComponent)),\n );\n}\n","import type { Session } from \"../@types/globals\";\nimport type { ConfigOptions } from \"../@types/internals\";\n\n/**\n * Available url callback actions.\n */\nexport type Actions = \"login\" | \"logout\";\n\n/**\n * Providers are used to implement certain services (E.g. facebook, github, credentials) as login methods.\n * Every provider should inherit from this.\n */\nabstract class IProvider {\n /**\n * This is used to map a callback to a provider.\n */\n private readonly __ID: string;\n\n constructor(ID: string) {\n this.__ID = ID;\n }\n\n /**\n * The provider ID.\n */\n public get ID(): string {\n return this.__ID;\n }\n\n /**\n * Login function. This is used to call all the login flows of each provider.\n * For now, the request's body **MUST** be JSON.\n * @param req The request object.\n * @param globalCfg The global auth config.\n */\n public abstract logIn(req: Request, globalCfg: ConfigOptions): Promise<{ session: Session; token: string } | null>;\n}\n\nexport { IProvider };\n","import type { MaybePromise, Session } from \"../@types/globals\";\nimport type { ConfigOptions } from \"../@types/internals\";\nimport { urlencodedToJson } from \"../functions/index\";\nimport { IProvider } from \"./IProvider\";\n\n/**\n * Configuration options of the Credentials provider\n */\nexport type CredentialsConfig<TCredentials extends string> = Readonly<{\n /**\n * The name of this provider, should not be changed unless you are\n * using multiple instance of the same provider.\n */\n name?: \"credentials\" | (string & {});\n /**\n * The available fields coming from the request containing credentials.\n */\n credentials: TCredentials[];\n /**\n * Function that gets called when a user tries to login.\n * This is where you should look inside your database for the user.\n * @param credentials An object containing the credentials from the request's body.\n * @returns A session object if a user is found, or `null`.\n */\n authorize: (credentials: Record<TCredentials, string>) => MaybePromise<Session | null>;\n}>;\n\n/**\n * Provider used to login a user using basic credentials.\n */\nexport class Credentials<TCredentials extends string = string> extends IProvider {\n private config: CredentialsConfig<TCredentials>;\n\n constructor(config: CredentialsConfig<TCredentials>) {\n super(config.name ?? \"credentials\");\n this.config = config;\n }\n\n public override async logIn(\n req: Request,\n globalCfg: ConfigOptions,\n ): Promise<{ session: Session; token: string } | null> {\n const contentType = (req.headers.get(\"Content-Type\")?.split(\";\")[0] ?? \"text/plain\").toLowerCase();\n\n let body: Record<TCredentials, string>;\n\n switch (contentType) {\n case \"application/json\":\n body = (await req.json()) as Record<TCredentials, string>;\n break;\n case \"application/x-www-urlencoded\":\n body = await req.text().then(urlencodedToJson<Record<TCredentials, string>>);\n break;\n case \"multipart/form-data\":\n {\n const data = await req.formData();\n body = Object.fromEntries(data) as Record<TCredentials, string>;\n }\n break;\n // fields should come from a form, so every un-supported types will be failing.\n case \"text/plain\":\n default:\n return null;\n }\n\n // Calls the user defined authorize callback\n const session = await this.config.authorize(body);\n if (session == null) return null;\n\n // Create a token\n const token = await globalCfg.strategy.serialize(session, globalCfg).catch((err) => {\n console.log(err);\n return null;\n });\n\n if (token == null) return null;\n\n return { session, token };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAgB,EAA4C,EAAkB,CAC1E,OAAO,OAAO,YACV,EACK,MAAM,CACN,MAAM,IAAI,CACV,IAAK,GAAM,EAAE,MAAM,IAAI,CAAC,CACxB,OAAQ,GAAS,EAAK,SAAW,EAAE,CACnC,IAAK,GAAS,EAAK,IAAI,mBAAmB,CAAC,CACnD,CCIL,IAAe,EAAf,KAAyB,CAIrB,KAEA,YAAY,EAAY,CACpB,KAAK,KAAO,EAMhB,IAAW,IAAa,CACpB,OAAO,KAAK,OCIP,EAAb,cAAuE,CAAU,CAC7E,OAEA,YAAY,EAAyC,CACjD,MAAM,EAAO,MAAQ,cAAc,CACnC,KAAK,OAAS,EAGlB,MAAsB,MAClB,EACA,EACmD,CACnD,IAAM,GAAe,EAAI,QAAQ,IAAI,eAAe,EAAE,MAAM,IAAI,CAAC,IAAM,cAAc,aAAa,CAE9F,EAEJ,OAAQ,EAAR,CACI,IAAK,mBACD,EAAQ,MAAM,EAAI,MAAM,CACxB,MACJ,IAAK,+BACD,EAAO,MAAM,EAAI,MAAM,CAAC,KAAK,EAA+C,CAC5E,MACJ,IAAK,sBACD,CACI,IAAM,EAAO,MAAM,EAAI,UAAU,CACjC,EAAO,OAAO,YAAY,EAAK,CAEnC,MAGJ,QACI,OAAO,KAIf,IAAM,EAAU,MAAM,KAAK,OAAO,UAAU,EAAK,CACjD,GAAI,GAAW,KAAM,OAAO,KAG5B,IAAM,EAAQ,MAAM,EAAU,SAAS,UAAU,EAAS,EAAU,CAAC,MAAO,IACxE,QAAQ,IAAI,EAAI,CACT,MACT,CAIF,OAFI,GAAS,KAAa,KAEnB,CAAE,UAAS,QAAO"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Orange Auth, a simple modular auth library
|
|
3
|
+
Copyright (C) 2026 Mathieu Dery
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License
|
|
16
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import { c as IStrategy, s as Callbacks } from "./IProvider-BH8TjziQ.mjs";
|
|
19
|
+
import { t as JWT } from "./index-DjPz5vTX.mjs";
|
|
20
|
+
export { Callbacks, IStrategy, JWT };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Orange Auth, a simple modular auth library
|
|
3
|
+
Copyright (C) 2026 Mathieu Dery
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License
|
|
16
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import{sign as e,verify as t}from"jsonwebtoken";function n(e,n,r){return new Promise(i=>{t(e,n,{...r,complete:!1},(e,t)=>{e?.cause&&i(null),i(t)})})}var r=class{callbacks;constructor(e){this.callbacks=e}},i=class extends r{signOptions;constructor(e={expiresIn:`1h`},t={}){super(t),this.signOptions=e}async serialize(t,n){return await Promise.resolve(this.callbacks.serialize?.(t)??!0)?Promise.resolve(e(t,n.secret,this.signOptions)):Promise.reject(`Serialize callback rejection`)}deserialize(e,t){return n(e,t.secret).then(async t=>t==null?null:await Promise.resolve(this.callbacks.deserialize?.(e,t)??!0)?t:null)}logOut(){return Promise.resolve()}};export{r as IStrategy,i as JWT};
|
|
19
|
+
//# sourceMappingURL=strategies.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategies.mjs","names":["verify","verify"],"sources":["../packages/orange-auth/functions/jwt.ts","../packages/orange-auth/strategies/IStrategy.ts","../packages/orange-auth/strategies/jwt.ts"],"sourcesContent":["import { verify as baseVerify, type JwtPayload, type PublicKey, type Secret, type VerifyOptions } from \"jsonwebtoken\";\n\n// The sign function is fine as-is\nexport { sign } from \"jsonwebtoken\";\n\n/**\n * Promisified version of the jwt's verify function.\n * @param token The user's token.\n * @param secretOrPublicKey Your secret key, or a public key.\n * @param options Jwt options.\n * @returns The user's payload, or null on errors.\n */\nexport function verify<T extends JwtPayload = JwtPayload>(\n token: string,\n secretOrPublicKey: Secret | PublicKey,\n options?: VerifyOptions,\n) {\n return new Promise<T | null>((resolve) => {\n baseVerify(token, secretOrPublicKey, { ...options, complete: false }, (err, payload) => {\n // In case of error, it is assumed as a malicious token, so we invalidate it.\n if (err?.cause) resolve(null);\n resolve(payload as T);\n });\n });\n}\n","import { type MaybePromise, type Session } from \"../@types/globals\";\nimport type { ConfigOptions } from \"../@types/internals\";\n\n/**\n * Strategies callbacks\n */\nexport type Callbacks = Partial<{\n /**\n * Pre-serialization callback. This can be used to add some steps to this process.\n * @param session The session to be serialized.\n * @returns A boolean representing if the serialization should occur.\n */\n serialize: (session: Session) => MaybePromise<boolean>;\n /**\n * Post-deserialization callback. This can be used to add some validation to this process.\n * @param session The token that was deserialized.\n * @returns A boolean representing if the deserialization is valid.\n */\n deserialize: (token: string, session: Session) => MaybePromise<boolean>;\n}>;\n\n/**\n * A strategy is used to handle the creation, validation and accessing a user's session.\n */\nabstract class IStrategy {\n protected callbacks: Callbacks;\n\n constructor(callbacks: Callbacks) {\n this.callbacks = callbacks;\n }\n\n /**\n * Handles how a session token is generated.\n * @param session The validated session object.\n * @param globalCfg The global auth config.\n * @returns A newly generated token that will be sent as a cookie.\n */\n public abstract serialize(session: Session, globalCfg: ConfigOptions): Promise<string>;\n\n /**\n * Handles how a token is validated and deserialized into a session object.\n * @param token A user's token.\n * @param globalCfg The global auth config.\n * @returns A user's session if validated and found, else `null`.\n */\n public abstract deserialize(token: string, globalCfg: ConfigOptions): Promise<Session | null>;\n\n /**\n * Handles how a session is destroyed when a user is logging out.\n * @param req The request object.\n * @param globalCfg The global auth config.\n */\n public abstract logOut(req: Request, globalCfg: ConfigOptions): Promise<void>;\n}\n\nexport { IStrategy };\n","import type { SignOptions } from \"jsonwebtoken\";\n\nimport type { Session } from \"../@types/globals\";\nimport type { ConfigOptions } from \"../@types/internals\";\nimport { sign, verify } from \"../functions/jwt\";\nimport { type Callbacks, IStrategy } from \"./IStrategy\";\n\n/**\n * Basic JWT strategy\n */\nclass JWT extends IStrategy {\n /**\n * Forwarded standard JWT options\n */\n private signOptions: SignOptions;\n\n constructor(options: SignOptions = { expiresIn: \"1h\" }, callbacks: Callbacks = {}) {\n super(callbacks);\n\n this.signOptions = options;\n }\n\n public override async serialize(session: Session, globalCfg: ConfigOptions): Promise<string> {\n // If there is no callback set, we can just run normally, so fallback to true.\n const shouldRun = await Promise.resolve(this.callbacks.serialize?.(session) ?? true);\n\n if (!shouldRun) {\n return Promise.reject(\"Serialize callback rejection\");\n }\n\n // Directly call the sign function, but make it async.\n return Promise.resolve(sign(session, globalCfg.secret, this.signOptions));\n }\n\n public override deserialize(token: string, globalCfg: ConfigOptions): Promise<Session | null> {\n // The verify function does everything for us, in this case.\n return verify<Session>(token, globalCfg.secret).then(async (session) => {\n if (session == null) return null;\n const isValid = await Promise.resolve(this.callbacks.deserialize?.(token, session) ?? true);\n return isValid ? session : null;\n });\n }\n\n public override logOut(): Promise<void> {\n // Since a JWT does not have any data in a DB, there is nothing to do here.\n return Promise.resolve();\n }\n}\n\nexport { JWT };\n"],"mappings":";;;;;;;;;;;;;;;;;gDAYA,SAAgBA,EACZ,EACA,EACA,EACF,CACE,OAAO,IAAI,QAAmB,GAAY,CACtC,EAAW,EAAO,EAAmB,CAAE,GAAG,EAAS,SAAU,GAAO,EAAG,EAAK,IAAY,CAEhF,GAAK,OAAO,EAAQ,KAAK,CAC7B,EAAQ,EAAa,EACvB,EACJ,CCCN,IAAe,EAAf,KAAyB,CACrB,UAEA,YAAY,EAAsB,CAC9B,KAAK,UAAY,IClBnB,EAAN,cAAkB,CAAU,CAIxB,YAEA,YAAY,EAAuB,CAAE,UAAW,KAAM,CAAE,EAAuB,EAAE,CAAE,CAC/E,MAAM,EAAU,CAEhB,KAAK,YAAc,EAGvB,MAAsB,UAAU,EAAkB,EAA2C,CASzF,OAPkB,MAAM,QAAQ,QAAQ,KAAK,UAAU,YAAY,EAAQ,EAAI,GAAK,CAO7E,QAAQ,QAAQ,EAAK,EAAS,EAAU,OAAQ,KAAK,YAAY,CAAC,CAJ9D,QAAQ,OAAO,+BAA+B,CAO7D,YAA4B,EAAe,EAAmD,CAE1F,OAAOC,EAAgB,EAAO,EAAU,OAAO,CAAC,KAAK,KAAO,IACpD,GAAW,KAAa,KACZ,MAAM,QAAQ,QAAQ,KAAK,UAAU,cAAc,EAAO,EAAQ,EAAI,GAAK,CAC1E,EAAU,KAC7B,CAGN,QAAwC,CAEpC,OAAO,QAAQ,SAAS"}
|
package/package.json
CHANGED
|
@@ -1,49 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orange-auth",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
5
6
|
"description": "Simple modular auth library",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
7
|
+
"author": "Mathieu Dery mathieu.dery@bananastreaming.ca",
|
|
8
|
+
"license": "GPL-3.0-or-later",
|
|
9
|
+
"repository": {
|
|
10
|
+
"url": "https://github.com/Unimat45/OrangeAuth.git"
|
|
11
|
+
},
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=20.0.0"
|
|
14
|
+
},
|
|
8
15
|
"files": [
|
|
9
16
|
"dist"
|
|
10
17
|
],
|
|
18
|
+
"types": "./dist/index.d.mts",
|
|
11
19
|
"exports": {
|
|
12
20
|
".": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
21
|
+
"types": "./dist/index.d.mts",
|
|
22
|
+
"import": "./dist/index.mjs"
|
|
23
|
+
},
|
|
24
|
+
"./client": {
|
|
25
|
+
"types": "./dist/client.d.ts",
|
|
26
|
+
"import": "./dist/client.js"
|
|
27
|
+
},
|
|
28
|
+
"./providers": {
|
|
29
|
+
"types": "./dist/providers.d.mts",
|
|
30
|
+
"import": "./dist/providers.mjs"
|
|
16
31
|
},
|
|
17
|
-
"./strategies":
|
|
18
|
-
|
|
19
|
-
|
|
32
|
+
"./strategies": {
|
|
33
|
+
"types": "./dist/strategies.d.mts",
|
|
34
|
+
"import": "./dist/strategies.mjs"
|
|
35
|
+
},
|
|
36
|
+
"./package.json": {
|
|
37
|
+
"import": "./package.json"
|
|
38
|
+
}
|
|
20
39
|
},
|
|
21
40
|
"scripts": {
|
|
22
|
-
"build": "
|
|
23
|
-
"test": "
|
|
41
|
+
"build": "tsdown",
|
|
42
|
+
"test": "bun test",
|
|
43
|
+
"lint": "eslint . --cache",
|
|
44
|
+
"check": "tsc --noEmit",
|
|
45
|
+
"prettier:fix": "prettier --write \"**/*.{ts,js}\" --cache",
|
|
46
|
+
"prettier:check": "prettier --check \"**/*.{ts,js}\" --cache"
|
|
24
47
|
},
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"url": "https://github.com/Unimat45/OrangeAuth.git"
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@universal-middleware/core": "^0.4.16",
|
|
50
|
+
"jsonwebtoken": "^9.0.3"
|
|
29
51
|
},
|
|
30
52
|
"devDependencies": {
|
|
31
|
-
"@
|
|
53
|
+
"@arethetypeswrong/cli": "^0.18.2",
|
|
54
|
+
"@eslint/js": "^9.39.2",
|
|
55
|
+
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
|
|
56
|
+
"@types/bun": "^1.3.8",
|
|
32
57
|
"@types/jsonwebtoken": "^9.0.10",
|
|
33
|
-
"@types/
|
|
34
|
-
"
|
|
35
|
-
"eslint-
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"jsonwebtoken": "^9.0.2",
|
|
46
|
-
"lodash-es": "^4.17.21",
|
|
47
|
-
"universal-cookie": "^8.0.1"
|
|
58
|
+
"@types/node": "^25.1.0",
|
|
59
|
+
"eslint": "^9.39.2",
|
|
60
|
+
"eslint-config-prettier": "^10.1.8",
|
|
61
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
62
|
+
"prettier": "^3.8.1",
|
|
63
|
+
"prettier-plugin-brace-style": "^0.9.0",
|
|
64
|
+
"prettier-plugin-merge": "^0.9.0",
|
|
65
|
+
"publint": "^0.3.17",
|
|
66
|
+
"tsdown": "^0.20.1",
|
|
67
|
+
"type-fest": "^5.4.3",
|
|
68
|
+
"typescript": "^5.9.3",
|
|
69
|
+
"typescript-eslint": "^8.54.0"
|
|
48
70
|
}
|
|
49
71
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) Mathieu Dery.
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE
|
package/dist/@types/globals.d.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import type { SerializeOptions } from "cookie";
|
|
2
|
-
import type { IProvider } from "../providers/IProvider";
|
|
3
|
-
import type { IStrategy } from "../strategies/IStrategy";
|
|
4
|
-
/**
|
|
5
|
-
* This is a Promise, or not...
|
|
6
|
-
*/
|
|
7
|
-
export type MaybePromise<T> = T | Promise<T>;
|
|
8
|
-
/**
|
|
9
|
-
* General session type. This should be augmented to include your session's fields.
|
|
10
|
-
*/
|
|
11
|
-
export interface Session extends Record<string, unknown> {
|
|
12
|
-
id: string;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Parameters for the custom callbacks
|
|
16
|
-
*/
|
|
17
|
-
type CallbackParams = {
|
|
18
|
-
/**
|
|
19
|
-
* The current token
|
|
20
|
-
*/
|
|
21
|
-
token: string;
|
|
22
|
-
/**
|
|
23
|
-
* The current deserialized token
|
|
24
|
-
*/
|
|
25
|
-
session: Session;
|
|
26
|
-
/**
|
|
27
|
-
* TThe request's headers
|
|
28
|
-
*/
|
|
29
|
-
headers: Headers;
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Auth Configuration props.
|
|
33
|
-
*/
|
|
34
|
-
export type ConfigOptionsProps = Readonly<{
|
|
35
|
-
/**
|
|
36
|
-
* All the available providers.
|
|
37
|
-
* If multiple instance of a single provider are used, the order does matter.
|
|
38
|
-
*/
|
|
39
|
-
providers: IProvider[];
|
|
40
|
-
/**
|
|
41
|
-
* Your secret key.
|
|
42
|
-
*/
|
|
43
|
-
secret: string | {
|
|
44
|
-
publicKey: string;
|
|
45
|
-
privateKey: string;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* A custom name for the cookie.
|
|
49
|
-
* Otherwise, the default name will be `orange.auth`
|
|
50
|
-
*/
|
|
51
|
-
cookieName?: string;
|
|
52
|
-
/**
|
|
53
|
-
* The strategy to be used.
|
|
54
|
-
*/
|
|
55
|
-
strategy: IStrategy;
|
|
56
|
-
/**
|
|
57
|
-
* This should be the url path that your auth is set up on, including the action and provider variables.
|
|
58
|
-
* @example
|
|
59
|
-
* ```js
|
|
60
|
-
* const app = express();
|
|
61
|
-
*
|
|
62
|
-
* const { handler } = CreateAuth({
|
|
63
|
-
* basePath: "/api/auth/:action/:provider",
|
|
64
|
-
* ...
|
|
65
|
-
* });
|
|
66
|
-
*
|
|
67
|
-
* app.all("/api/auth/{*auth}", createHandler(handler)());
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
basePath: string;
|
|
71
|
-
/**
|
|
72
|
-
* Cookie serialization options. see [MDN Cookie](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Cookies)
|
|
73
|
-
*/
|
|
74
|
-
cookieSettings?: SerializeOptions;
|
|
75
|
-
/**
|
|
76
|
-
* Custom callbacks
|
|
77
|
-
*/
|
|
78
|
-
callbacks?: {
|
|
79
|
-
/**
|
|
80
|
-
* Custom login callback. This is ran after logging in with the provider.
|
|
81
|
-
* This can accept 2 return types: a boolean that indicates if the login is valid,
|
|
82
|
-
* or a url which will redirect the user.
|
|
83
|
-
* @param params An object containing the token, session and headers of a request.
|
|
84
|
-
* @returns a boolean that indicates if the login is valid,
|
|
85
|
-
* or a url which will redirect the user.
|
|
86
|
-
*/
|
|
87
|
-
login?: (params: CallbackParams) => MaybePromise<boolean | string>;
|
|
88
|
-
/**
|
|
89
|
-
* Custom logout callback. This is ran before logging out with the strategy.
|
|
90
|
-
* @param params An object containing the token, session and headers of a request.
|
|
91
|
-
* @returns Nothing, or an empty promise.
|
|
92
|
-
*/
|
|
93
|
-
logout?: (params: CallbackParams) => MaybePromise<void>;
|
|
94
|
-
};
|
|
95
|
-
}>;
|
|
96
|
-
export {};
|
|
97
|
-
//# sourceMappingURL=globals.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../../src/@types/globals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,OAAQ,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACpD,EAAE,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,KAAK,cAAc,GAAG;IAClB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IACtC;;;OAGG;IACH,SAAS,EAAE,SAAS,EAAE,CAAC;IAEvB;;OAEG;IACH,MAAM,EAAE,MAAM,GAAG;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAE3D;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC;IAEpB;;;;;;;;;;;;;OAaG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,cAAc,CAAC,EAAE,gBAAgB,CAAC;IAElC;;OAEG;IACH,SAAS,CAAC,EAAE;QACR;;;;;;;WAOG;QACH,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,YAAY,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC;QAEnE;;;;WAIG;QACH,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;KAC3D,CAAC;CACL,CAAC,CAAC"}
|
package/dist/@types/globals.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { RequiredDeep } from "type-fest";
|
|
2
|
-
import type { ConfigOptionsProps } from "./globals";
|
|
3
|
-
/**
|
|
4
|
-
* Internally used version of the options
|
|
5
|
-
*/
|
|
6
|
-
export type ConfigOptions = Omit<RequiredDeep<Omit<ConfigOptionsProps, "basePath">>, "cookieSettings"> & {
|
|
7
|
-
cookieSettings: NonNullable<ConfigOptionsProps["cookieSettings"]>;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Maybe there is a value, maybe not 🤷♂️
|
|
11
|
-
*/
|
|
12
|
-
export type Maybe<T> = T | null | undefined;
|
|
13
|
-
//# sourceMappingURL=internals.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"internals.d.ts","sourceRoot":"","sources":["../../src/@types/internals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC,EAAE,gBAAgB,CAAC,GAAG;IAErG,cAAc,EAAE,WAAW,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAC,CAAC;CACrE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC"}
|
package/dist/@types/internals.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,oBAAoB,CAAC"}
|
package/dist/functions/index.js
DELETED
package/dist/functions/jwt.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type JwtPayload, type PublicKey, type Secret, type VerifyOptions } from "jsonwebtoken";
|
|
2
|
-
export { sign } from "jsonwebtoken";
|
|
3
|
-
/**
|
|
4
|
-
* Promisified version of the jwt's verify function.
|
|
5
|
-
* @param token The user's token.
|
|
6
|
-
* @param secretOrPublicKey Your secret key, or a public key.
|
|
7
|
-
* @param options Jwt options.
|
|
8
|
-
* @returns The user's payload, or null on errors.
|
|
9
|
-
*/
|
|
10
|
-
export declare function verify<T extends JwtPayload = JwtPayload>(token: string, secretOrPublicKey: Secret | PublicKey, options?: VerifyOptions): Promise<T | null>;
|
|
11
|
-
//# sourceMappingURL=jwt.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../src/functions/jwt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,KAAK,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAGtH,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EACpD,KAAK,EAAE,MAAM,EACb,iBAAiB,EAAE,MAAM,GAAG,SAAS,EACrC,OAAO,CAAC,EAAE,aAAa,qBAS1B"}
|
package/dist/functions/jwt.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { verify as baseVerify } from "jsonwebtoken";
|
|
2
|
-
// The sign function is fine as-is
|
|
3
|
-
export { sign } from "jsonwebtoken";
|
|
4
|
-
/**
|
|
5
|
-
* Promisified version of the jwt's verify function.
|
|
6
|
-
* @param token The user's token.
|
|
7
|
-
* @param secretOrPublicKey Your secret key, or a public key.
|
|
8
|
-
* @param options Jwt options.
|
|
9
|
-
* @returns The user's payload, or null on errors.
|
|
10
|
-
*/
|
|
11
|
-
export function verify(token, secretOrPublicKey, options) {
|
|
12
|
-
return new Promise((resolve) => {
|
|
13
|
-
baseVerify(token, secretOrPublicKey, { ...options, complete: false }, (err, payload) => {
|
|
14
|
-
// In case of error, it is assumed as a malicious token, so we invalidate it.
|
|
15
|
-
if (err?.cause)
|
|
16
|
-
resolve(null);
|
|
17
|
-
resolve(payload);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"urlencodedToJson.d.ts","sourceRoot":"","sources":["../../src/functions/urlencodedToJson.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,CAS5E"}
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,kBAAkB,CAAC;AACjC,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC"}
|
package/dist/index.js
DELETED
package/dist/lib.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { Maybe } from "./@types/internals";
|
|
2
|
-
import type { Session } from "./@types/globals";
|
|
3
|
-
/**
|
|
4
|
-
* Initializes the auth. This should be called once per backend.
|
|
5
|
-
* @param req Something that has a `headers` field; either a Headers instance, or just a plain object.
|
|
6
|
-
* @returns A session if found and valid, or `null`.
|
|
7
|
-
*/
|
|
8
|
-
export declare const CreateAuth: (config: Readonly<{
|
|
9
|
-
providers: import("./providers").IProvider[];
|
|
10
|
-
secret: string | {
|
|
11
|
-
publicKey: string;
|
|
12
|
-
privateKey: string;
|
|
13
|
-
};
|
|
14
|
-
cookieName?: string;
|
|
15
|
-
strategy: import("./strategies").IStrategy;
|
|
16
|
-
basePath: string;
|
|
17
|
-
cookieSettings?: import("cookie").SerializeOptions;
|
|
18
|
-
callbacks?: {
|
|
19
|
-
login?: (params: {
|
|
20
|
-
token: string;
|
|
21
|
-
session: Session;
|
|
22
|
-
headers: Headers;
|
|
23
|
-
}) => import(".").MaybePromise<boolean | string>;
|
|
24
|
-
logout?: (params: {
|
|
25
|
-
token: string;
|
|
26
|
-
session: Session;
|
|
27
|
-
headers: Headers;
|
|
28
|
-
}) => import(".").MaybePromise<void>;
|
|
29
|
-
};
|
|
30
|
-
}>) => {
|
|
31
|
-
/**
|
|
32
|
-
* Universal handler route. You can use this with the `createHandler()` method
|
|
33
|
-
* @returns
|
|
34
|
-
*/
|
|
35
|
-
handler: () => (req: Request, _: Universal.Context, runtime: import("@universal-middleware/core").RuntimeAdapter) => Promise<Response>;
|
|
36
|
-
/**
|
|
37
|
-
* Deserialize a user's session.
|
|
38
|
-
* @param globalCfg The global auth config
|
|
39
|
-
* @param req An object having a headers field
|
|
40
|
-
* @returns A user's token and session, if found and valid
|
|
41
|
-
*/
|
|
42
|
-
getSession: <T extends Session = Session>(req: {
|
|
43
|
-
headers: Maybe<Headers | Record<string, string>>;
|
|
44
|
-
}) => Promise<T | null>;
|
|
45
|
-
};
|
|
46
|
-
//# sourceMappingURL=lib.d.ts.map
|
package/dist/lib.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAiB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,KAAK,EAAsB,OAAO,EAAE,MAAM,kBAAkB,CAAC;AA4CpE;;;;GAIG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;aAYuB,CAAA;;;;;cAUvB,CAAC;;;;;;;IAOhB;;;OAGG;;IAwGH;;;;;OAKG;iBACU,CAAC,SAAS,OAAO,iBAAiB;QAAE,OAAO,EAAE,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;KAAE,KAEnC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;CAUxF,CAAC"}
|