passport-descope 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Descope
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/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # <a title="Descope passport strategy" href="https://passportjs.org/"><img width="64" alt="WordPress blue logo" src="https://images.ctfassets.net/vwq10xzbe6iz/tnwT7PN9aBmT7vgkTtGhV/940f001eb249a42904cd40e64d13c7e9/passportJS-300x300.png"></a> Strategy by Descope
2
+
3
+ [![License](https://img.shields.io/:license-MIT-blue.svg?style=flat)](https://opensource.org/licenses/MIT)
4
+
5
+
6
+ ## Overview
7
+ This strategy is designed to help manage authentication and sessions in your express-based applications. This strategy authenticates users by validating the JWT in either Authorization Bearer or cookie, and provides additional user management features.
8
+
9
+ ## Getting started
10
+
11
+ ### Requirements
12
+
13
+ - [Node 12.0.0+](https://nodejs.org/en)
14
+
15
+ ### Installation
16
+
17
+ The Descope Passport strategy can be installed with npm.
18
+
19
+ ```
20
+ npm i passport-descope
21
+ ```
22
+
23
+ ## Using the Strategy
24
+
25
+ In order to utilize the authentication functions, you will need to initialize a `DescopeStrategy` object. You will need to define a retrieve your Descope Project ID and define a verify callback function to be able to authenticate using the `DescopeStrategy` object,
26
+
27
+ ```
28
+ var DescopeStrategy = require('passport-descope');
29
+
30
+ passport.use(new DescopeStrategy({
31
+ projectId: '<Your project ID>',
32
+ managementKey: '<OPTIONAL management key>'
33
+ verify: (jwtDetails, cb) => cb(null, {id: jwtDetails.token.sub})
34
+ }));
35
+ ```
36
+
37
+ **Required**
38
+
39
+ 1. `projectId` - The project ID you can retrieve from the Descope Console [here](https://app.descope.com/settings/project).
40
+
41
+ 2. `verify` - The verify function is specific to the `passport-descope` strategy, and the exact argument it receives `(jwtDetails, cb)` and the parameter it yields `{id: jwtDetails.token.sub}` is dependent on our Descope authentication strategy.
42
+
43
+ **Optional**
44
+
45
+ 3. `managementKey` - If you would like to also return user information as part of the verifyCallback function, you will need to include a Descope Management Key when you initialize your `DescopeStrategy` object. You can create one in the Company Settings portal [here](https://app.descope.com/settings/company/settings).
46
+
47
+ ---
48
+
49
+ If you would like to learn more about Passport JS Strategies, please visit their [website](https://www.passportjs.org/concepts/authentication/strategies/).
50
+
51
+ ## Code Samples
52
+
53
+ - [TODO List Sample App]()
54
+
55
+ ## Feedback
56
+
57
+ ### Contributing
58
+
59
+ We appreciate feedback and contribution to this repository!
60
+
61
+ ### Raise an issue
62
+
63
+ To provide feedback or report a bug, please [raise an issue on our issue tracker](https://github.com/descope/passport-descope/issues).
64
+
65
+
66
+ This project is licensed under the MIT license. See the <a href="./LICENSE"> LICENSE</a> file for more info.</p>
@@ -0,0 +1,2 @@
1
+ "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=e(require("@descope/node-sdk"));module.exports=class{constructor(e){this._options=e,this.name="descope",this._descopeClient=r.default({projectId:e.projectId,managementKey:e.managementKey}),this._realm=e.realm||"Users",e.scope&&(this._scope=Array.isArray(e.scope)?e.scope:[e.scope])}async authenticate(e,t){const o=this,s=(e=>{var r;const t=null===(r=e.headers)||void 0===r?void 0:r.authorization;if(!t)return null;const o=t.split(" ");if(2==o.length){const e=o[0],r=o[1];if(/^Bearer$/i.test(e))return r}return null})(e)||(e=>{var t;const o={},s=null===(t=e.headers)||void 0===t?void 0:t.cookie;return s?(s.split(";").forEach((e=>{let[r,...t]=e.split("=");if(r=null==r?void 0:r.trim(),!r)return;const s=t.join("=").trim();s&&(o[r]=decodeURIComponent(s))})),o[r.default.SessionTokenCookieName]):null})(e);let n=null;try{n=await o._descopeClient.validateJwt(s)}catch(e){const r="No valid token provided",t=e instanceof Error?e.message:r;return o.fail(o._challenge(401,t))}o._options.verify(n,(async(e,r,t)=>{if(e)return o.error(e);if(!r)return"string"==typeof t&&(t={message:t}),t=t||{},o.fail(o._challenge(401,"invalid_token",t.message));if(t&&t.userDetails){const e=await o._descopeClient.management.user.loadByUserId(n.token.sub);if(console.log(e),!e.ok)return o.fail(o._challenge(401,e.error.errorDescription,e.error.errorMessage));r=e.data}return o.success(r,t)}),e)}_challenge(e,r,t){let o='Bearer realm="'+this._realm+'"';return this._scope&&(o+=', scope="'+this._scope.join(" ")+'"'),e&&(o+=', error="'+e+'"'),r&&(o+=', error_description="'+r+'"'),t&&(o+=', error_uri="'+t+'"'),o}};
2
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../../src/index.ts","../../src/token.ts"],"sourcesContent":["/* eslint-disable no-console */\n/* eslint-disable no-underscore-dangle */\nimport { Request, Response } from 'express';\nimport { StrategyCreatedStatic } from 'passport';\nimport { tokenFromHeader, tokenFromCookie } from './token';\nimport DescopeClient from '@descope/node-sdk';\nimport { Verify } from 'crypto';\n\ntype VerifyCallback = (\n payload: any,\n verifyCallback: (err?: Error | null, user?: Object, info?: any) => void,\n req: Request,\n) => void;\n\ninterface Options {\n /** Descope project id to use */\n projectId: string;\n /** Descope optional management key to retrieve extra user details */\n managementKey?: string;\n /** The callback to load the user details if stored outside of Descope */\n verify: VerifyCallback;\n /** The realm for the challenge */\n realm?: string;\n /** The scopes for the challenge */\n scope?: [string] | string;\n}\n\ntype DescopeSdk = ReturnType<typeof DescopeClient>;\ntype ValidateSessionRes = ReturnType<DescopeSdk[\"validateJwt\"]>;\ntype AuthenticationInfo = Awaited<ValidateSessionRes>;\n\n/**\n * DescopeStrategy for PassportJS verifies that the given JWT token in either Authorization Bearer or DS cookie is valid.\n * It requires the Descope project ID and a verify function is there to allow the app to manipulate user details.\n */\nclass DescopeStrategy {\n name: string = 'descope';\n _descopeClient: DescopeSdk;\n _realm: string;\n _scope: [string];\n\n constructor(private _options: Options) {\n this._descopeClient = DescopeClient({ projectId: _options.projectId, managementKey: _options.managementKey });\n this._realm = _options.realm || 'Users';\n if (_options.scope) {\n this._scope = (Array.isArray(_options.scope)) ? _options.scope : [ _options.scope ];\n }\n }\n\n async authenticate(this: StrategyCreatedStatic & DescopeStrategy, req: Request, options?: any): Promise<void> {\n const self = this;\n const token = tokenFromHeader(req) || tokenFromCookie(req);\n let authInfo: AuthenticationInfo = null;\n try {\n authInfo = await self._descopeClient.validateJwt(token);\n } catch (error) {\n const defaultMessage = 'No valid token provided';\n const message = error instanceof Error ? error.message : defaultMessage;\n return self.fail(self._challenge(401, message));\n }\n\n const verifyCallback = async (err?: Error | null, user?: Object, info?: any) => {\n if (err) {\n return self.error(err);\n }\n if (!user) {\n if (typeof info == 'string') {\n info = { message: info };\n }\n info = info || {};\n return self.fail(self._challenge(401, 'invalid_token', info.message)); \n }\n if (info && info.userDetails) {\n // Retrieve user details if requested\n const userDetails = await self._descopeClient.management.user.loadByUserId(authInfo.token.sub);\n console.log(userDetails);\n if (!userDetails.ok) {\n return self.fail(self._challenge(401, userDetails.error.errorDescription, userDetails.error.errorMessage)); \n } else {\n user = userDetails.data;\n }\n }\n return self.success(user, info);\n };\n\n self._options.verify(authInfo, verifyCallback, req);\n }\n\n /**\n * Generate a challenge response in case of failure\n * @param this the Descope strategy\n * @param code error code\n * @param desc error description\n * @param uri relevant uri for the error\n * @returns the challenge string\n */\n _challenge(this: StrategyCreatedStatic & DescopeStrategy, code?: number, desc?: string, uri?: string) {\n let challenge = 'Bearer realm=\"' + this._realm + '\"';\n if (this._scope) {\n challenge += ', scope=\"' + this._scope.join(' ') + '\"';\n }\n if (code) {\n challenge += ', error=\"' + code + '\"';\n }\n if (desc) {\n challenge += ', error_description=\"' + desc + '\"';\n }\n if (uri) {\n challenge += ', error_uri=\"' + uri + '\"';\n }\n return challenge;\n }\n}\n\nexport default DescopeStrategy;\n","/* eslint-disable no-console */\nimport { Request } from 'express';\nimport DescopeClient from '@descope/node-sdk';\n\nexport const tokenFromCookie = (request: Request) => {\n const list: { [key: string]: string } = {};\n const cookieHeader = request.headers?.cookie;\n if (!cookieHeader) return null;\n\n cookieHeader.split(`;`).forEach((cookie: string) => {\n let [name, ...rest] = cookie.split(`=`);\n name = name?.trim();\n if (!name) return;\n const value = rest.join(`=`).trim();\n if (!value) return;\n list[name] = decodeURIComponent(value);\n });\n\n return list[DescopeClient.SessionTokenCookieName];\n};\n\nexport const tokenFromHeader = (request: Request) => {\n const authHeader = request.headers?.authorization;\n if (!authHeader) return null;\n\n const parts = authHeader.split(' ');\n if (parts.length == 2) {\n const scheme = parts[0], credentials = parts[1];\n if (/^Bearer$/i.test(scheme)) {\n return credentials;\n }\n }\n return null\n};"],"names":["constructor","_options","this","name","_descopeClient","DescopeClient","projectId","managementKey","_realm","realm","scope","_scope","Array","isArray","async","req","options","self","token","request","authHeader","_a","headers","authorization","parts","split","length","scheme","credentials","test","tokenFromHeader","list","cookieHeader","cookie","forEach","rest","trim","value","join","decodeURIComponent","SessionTokenCookieName","tokenFromCookie","authInfo","validateJwt","error","defaultMessage","message","Error","fail","_challenge","verify","err","user","info","userDetails","management","loadByUserId","sub","console","log","ok","errorDescription","errorMessage","data","success","code","desc","uri","challenge"],"mappings":"0IAmCA,MAMEA,YAAoBC,GAAAC,KAAQD,SAARA,EALpBC,KAAIC,KAAW,UAMbD,KAAKE,eAAiBC,UAAc,CAAEC,UAAWL,EAASK,UAAWC,cAAeN,EAASM,gBAC7FL,KAAKM,OAASP,EAASQ,OAAS,QAC5BR,EAASS,QACXR,KAAKS,OAAUC,MAAMC,QAAQZ,EAASS,OAAUT,EAASS,MAAQ,CAAET,EAASS,OAE/E,CAEDI,mBAAkEC,EAAcC,GAC9E,MAAMC,EAAOf,KACPgB,EC9BqB,CAACC,UAC9B,MAAMC,EAA4B,QAAfC,EAAAF,EAAQG,eAAO,IAAAD,OAAA,EAAAA,EAAEE,cACpC,IAAKH,EAAY,OAAO,KAExB,MAAMI,EAAQJ,EAAWK,MAAM,KAC/B,GAAoB,GAAhBD,EAAME,OAAa,CACrB,MAAMC,EAASH,EAAM,GAAII,EAAcJ,EAAM,GAC7C,GAAI,YAAYK,KAAKF,GACnB,OAAOC,CAEV,CACD,OAAO,IAAI,EDmBKE,CAAgBf,IC/CH,CAACI,UAC9B,MAAMY,EAAkC,CAAA,EAClCC,EAA8B,QAAfX,EAAAF,EAAQG,eAAO,IAAAD,OAAA,EAAAA,EAAEY,OACtC,OAAKD,GAELA,EAAaP,MAAM,KAAKS,SAASD,IAC/B,IAAK9B,KAASgC,GAAQF,EAAOR,MAAM,KAEnC,GADAtB,EAAOA,eAAAA,EAAMiC,QACRjC,EAAM,OACX,MAAMkC,EAAQF,EAAKG,KAAK,KAAKF,OACxBC,IACLN,EAAK5B,GAAQoC,mBAAmBF,GAAM,IAGjCN,EAAK1B,UAAcmC,yBAXA,IAWuB,EDiCTC,CAAgB1B,GACtD,IAAI2B,EAA+B,KACnC,IACEA,QAAiBzB,EAAKb,eAAeuC,YAAYzB,EAClD,CAAC,MAAO0B,GACP,MAAMC,EAAiB,0BACjBC,EAAUF,aAAiBG,MAAQH,EAAME,QAAUD,EACzD,OAAO5B,EAAK+B,KAAK/B,EAAKgC,WAAW,IAAKH,GACvC,CA0BD7B,EAAKhB,SAASiD,OAAOR,GAxBE5B,MAAOqC,EAAoBC,EAAeC,KAC/D,GAAIF,EACF,OAAOlC,EAAK2B,MAAMO,GAEpB,IAAKC,EAKH,MAJmB,iBAARC,IACTA,EAAO,CAAEP,QAASO,IAEpBA,EAAOA,GAAQ,GACRpC,EAAK+B,KAAK/B,EAAKgC,WAAW,IAAK,gBAAiBI,EAAKP,UAE9D,GAAIO,GAAQA,EAAKC,YAAa,CAE5B,MAAMA,QAAoBrC,EAAKb,eAAemD,WAAWH,KAAKI,aAAad,EAASxB,MAAMuC,KAE1F,GADAC,QAAQC,IAAIL,IACPA,EAAYM,GACf,OAAO3C,EAAK+B,KAAK/B,EAAKgC,WAAW,IAAKK,EAAYV,MAAMiB,iBAAkBP,EAAYV,MAAMkB,eAE5FV,EAAOE,EAAYS,IAEtB,CACD,OAAO9C,EAAK+C,QAAQZ,EAAMC,EAAK,GAGctC,EAChD,CAUDkC,WAA0DgB,EAAeC,EAAeC,GACtF,IAAIC,EAAY,iBAAmBlE,KAAKM,OAAS,IAajD,OAZIN,KAAKS,SACPyD,GAAa,YAAclE,KAAKS,OAAO2B,KAAK,KAAO,KAEjD2B,IACFG,GAAa,YAAcH,EAAO,KAEhCC,IACFE,GAAa,wBAA0BF,EAAO,KAE5CC,IACFC,GAAa,gBAAkBD,EAAM,KAEhCC,CACR"}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,42 @@
1
+ import { Request } from 'express';
2
+ import { StrategyCreatedStatic } from 'passport';
3
+ import DescopeClient from '@descope/node-sdk';
4
+
5
+ type VerifyCallback = (payload: any, verifyCallback: (err?: Error | null, user?: Object, info?: any) => void, req: Request) => void;
6
+ interface Options {
7
+ /** Descope project id to use */
8
+ projectId: string;
9
+ /** Descope optional management key to retrieve extra user details */
10
+ managementKey?: string;
11
+ /** The callback to load the user details if stored outside of Descope */
12
+ verify: VerifyCallback;
13
+ /** The realm for the challenge */
14
+ realm?: string;
15
+ /** The scopes for the challenge */
16
+ scope?: [string] | string;
17
+ }
18
+ type DescopeSdk = ReturnType<typeof DescopeClient>;
19
+ /**
20
+ * DescopeStrategy for PassportJS verifies that the given JWT token in either Authorization Bearer or DS cookie is valid.
21
+ * It requires the Descope project ID and a verify function is there to allow the app to manipulate user details.
22
+ */
23
+ declare class DescopeStrategy {
24
+ private _options;
25
+ name: string;
26
+ _descopeClient: DescopeSdk;
27
+ _realm: string;
28
+ _scope: [string];
29
+ constructor(_options: Options);
30
+ authenticate(this: StrategyCreatedStatic & DescopeStrategy, req: Request, options?: any): Promise<void>;
31
+ /**
32
+ * Generate a challenge response in case of failure
33
+ * @param this the Descope strategy
34
+ * @param code error code
35
+ * @param desc error description
36
+ * @param uri relevant uri for the error
37
+ * @returns the challenge string
38
+ */
39
+ _challenge(this: StrategyCreatedStatic & DescopeStrategy, code?: number, desc?: string, uri?: string): string;
40
+ }
41
+
42
+ export { DescopeStrategy as default };
@@ -0,0 +1,2 @@
1
+ import e from"@descope/node-sdk";class r{constructor(r){this._options=r,this.name="descope",this._descopeClient=e({projectId:r.projectId,managementKey:r.managementKey}),this._realm=r.realm||"Users",r.scope&&(this._scope=Array.isArray(r.scope)?r.scope:[r.scope])}async authenticate(r,t){const o=this,s=(e=>{var r;const t=null===(r=e.headers)||void 0===r?void 0:r.authorization;if(!t)return null;const o=t.split(" ");if(2==o.length){const e=o[0],r=o[1];if(/^Bearer$/i.test(e))return r}return null})(r)||(r=>{var t;const o={},s=null===(t=r.headers)||void 0===t?void 0:t.cookie;return s?(s.split(";").forEach((e=>{let[r,...t]=e.split("=");if(r=null==r?void 0:r.trim(),!r)return;const s=t.join("=").trim();s&&(o[r]=decodeURIComponent(s))})),o[e.SessionTokenCookieName]):null})(r);let n=null;try{n=await o._descopeClient.validateJwt(s)}catch(e){const r="No valid token provided",t=e instanceof Error?e.message:r;return o.fail(o._challenge(401,t))}o._options.verify(n,(async(e,r,t)=>{if(e)return o.error(e);if(!r)return"string"==typeof t&&(t={message:t}),t=t||{},o.fail(o._challenge(401,"invalid_token",t.message));if(t&&t.userDetails){const e=await o._descopeClient.management.user.loadByUserId(n.token.sub);if(console.log(e),!e.ok)return o.fail(o._challenge(401,e.error.errorDescription,e.error.errorMessage));r=e.data}return o.success(r,t)}),r)}_challenge(e,r,t){let o='Bearer realm="'+this._realm+'"';return this._scope&&(o+=', scope="'+this._scope.join(" ")+'"'),e&&(o+=', error="'+e+'"'),r&&(o+=', error_description="'+r+'"'),t&&(o+=', error_uri="'+t+'"'),o}}export{r as default};
2
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":["../src/index.ts","../src/token.ts"],"sourcesContent":["/* eslint-disable no-console */\n/* eslint-disable no-underscore-dangle */\nimport { Request, Response } from 'express';\nimport { StrategyCreatedStatic } from 'passport';\nimport { tokenFromHeader, tokenFromCookie } from './token';\nimport DescopeClient from '@descope/node-sdk';\nimport { Verify } from 'crypto';\n\ntype VerifyCallback = (\n payload: any,\n verifyCallback: (err?: Error | null, user?: Object, info?: any) => void,\n req: Request,\n) => void;\n\ninterface Options {\n /** Descope project id to use */\n projectId: string;\n /** Descope optional management key to retrieve extra user details */\n managementKey?: string;\n /** The callback to load the user details if stored outside of Descope */\n verify: VerifyCallback;\n /** The realm for the challenge */\n realm?: string;\n /** The scopes for the challenge */\n scope?: [string] | string;\n}\n\ntype DescopeSdk = ReturnType<typeof DescopeClient>;\ntype ValidateSessionRes = ReturnType<DescopeSdk[\"validateJwt\"]>;\ntype AuthenticationInfo = Awaited<ValidateSessionRes>;\n\n/**\n * DescopeStrategy for PassportJS verifies that the given JWT token in either Authorization Bearer or DS cookie is valid.\n * It requires the Descope project ID and a verify function is there to allow the app to manipulate user details.\n */\nclass DescopeStrategy {\n name: string = 'descope';\n _descopeClient: DescopeSdk;\n _realm: string;\n _scope: [string];\n\n constructor(private _options: Options) {\n this._descopeClient = DescopeClient({ projectId: _options.projectId, managementKey: _options.managementKey });\n this._realm = _options.realm || 'Users';\n if (_options.scope) {\n this._scope = (Array.isArray(_options.scope)) ? _options.scope : [ _options.scope ];\n }\n }\n\n async authenticate(this: StrategyCreatedStatic & DescopeStrategy, req: Request, options?: any): Promise<void> {\n const self = this;\n const token = tokenFromHeader(req) || tokenFromCookie(req);\n let authInfo: AuthenticationInfo = null;\n try {\n authInfo = await self._descopeClient.validateJwt(token);\n } catch (error) {\n const defaultMessage = 'No valid token provided';\n const message = error instanceof Error ? error.message : defaultMessage;\n return self.fail(self._challenge(401, message));\n }\n\n const verifyCallback = async (err?: Error | null, user?: Object, info?: any) => {\n if (err) {\n return self.error(err);\n }\n if (!user) {\n if (typeof info == 'string') {\n info = { message: info };\n }\n info = info || {};\n return self.fail(self._challenge(401, 'invalid_token', info.message)); \n }\n if (info && info.userDetails) {\n // Retrieve user details if requested\n const userDetails = await self._descopeClient.management.user.loadByUserId(authInfo.token.sub);\n console.log(userDetails);\n if (!userDetails.ok) {\n return self.fail(self._challenge(401, userDetails.error.errorDescription, userDetails.error.errorMessage)); \n } else {\n user = userDetails.data;\n }\n }\n return self.success(user, info);\n };\n\n self._options.verify(authInfo, verifyCallback, req);\n }\n\n /**\n * Generate a challenge response in case of failure\n * @param this the Descope strategy\n * @param code error code\n * @param desc error description\n * @param uri relevant uri for the error\n * @returns the challenge string\n */\n _challenge(this: StrategyCreatedStatic & DescopeStrategy, code?: number, desc?: string, uri?: string) {\n let challenge = 'Bearer realm=\"' + this._realm + '\"';\n if (this._scope) {\n challenge += ', scope=\"' + this._scope.join(' ') + '\"';\n }\n if (code) {\n challenge += ', error=\"' + code + '\"';\n }\n if (desc) {\n challenge += ', error_description=\"' + desc + '\"';\n }\n if (uri) {\n challenge += ', error_uri=\"' + uri + '\"';\n }\n return challenge;\n }\n}\n\nexport default DescopeStrategy;\n","/* eslint-disable no-console */\nimport { Request } from 'express';\nimport DescopeClient from '@descope/node-sdk';\n\nexport const tokenFromCookie = (request: Request) => {\n const list: { [key: string]: string } = {};\n const cookieHeader = request.headers?.cookie;\n if (!cookieHeader) return null;\n\n cookieHeader.split(`;`).forEach((cookie: string) => {\n let [name, ...rest] = cookie.split(`=`);\n name = name?.trim();\n if (!name) return;\n const value = rest.join(`=`).trim();\n if (!value) return;\n list[name] = decodeURIComponent(value);\n });\n\n return list[DescopeClient.SessionTokenCookieName];\n};\n\nexport const tokenFromHeader = (request: Request) => {\n const authHeader = request.headers?.authorization;\n if (!authHeader) return null;\n\n const parts = authHeader.split(' ');\n if (parts.length == 2) {\n const scheme = parts[0], credentials = parts[1];\n if (/^Bearer$/i.test(scheme)) {\n return credentials;\n }\n }\n return null\n};"],"names":["DescopeStrategy","constructor","_options","this","name","_descopeClient","DescopeClient","projectId","managementKey","_realm","realm","scope","_scope","Array","isArray","async","req","options","self","token","request","authHeader","_a","headers","authorization","parts","split","length","scheme","credentials","test","tokenFromHeader","list","cookieHeader","cookie","forEach","rest","trim","value","join","decodeURIComponent","SessionTokenCookieName","tokenFromCookie","authInfo","validateJwt","error","defaultMessage","message","Error","fail","_challenge","verify","err","user","info","userDetails","management","loadByUserId","sub","console","log","ok","errorDescription","errorMessage","data","success","code","desc","uri","challenge"],"mappings":"iCAmCA,MAAMA,EAMJC,YAAoBC,GAAAC,KAAQD,SAARA,EALpBC,KAAIC,KAAW,UAMbD,KAAKE,eAAiBC,EAAc,CAAEC,UAAWL,EAASK,UAAWC,cAAeN,EAASM,gBAC7FL,KAAKM,OAASP,EAASQ,OAAS,QAC5BR,EAASS,QACXR,KAAKS,OAAUC,MAAMC,QAAQZ,EAASS,OAAUT,EAASS,MAAQ,CAAET,EAASS,OAE/E,CAEDI,mBAAkEC,EAAcC,GAC9E,MAAMC,EAAOf,KACPgB,EC9BqB,CAACC,UAC9B,MAAMC,EAA4B,QAAfC,EAAAF,EAAQG,eAAO,IAAAD,OAAA,EAAAA,EAAEE,cACpC,IAAKH,EAAY,OAAO,KAExB,MAAMI,EAAQJ,EAAWK,MAAM,KAC/B,GAAoB,GAAhBD,EAAME,OAAa,CACrB,MAAMC,EAASH,EAAM,GAAII,EAAcJ,EAAM,GAC7C,GAAI,YAAYK,KAAKF,GACnB,OAAOC,CAEV,CACD,OAAO,IAAI,EDmBKE,CAAgBf,IC/CH,CAACI,UAC9B,MAAMY,EAAkC,CAAA,EAClCC,EAA8B,QAAfX,EAAAF,EAAQG,eAAO,IAAAD,OAAA,EAAAA,EAAEY,OACtC,OAAKD,GAELA,EAAaP,MAAM,KAAKS,SAASD,IAC/B,IAAK9B,KAASgC,GAAQF,EAAOR,MAAM,KAEnC,GADAtB,EAAOA,eAAAA,EAAMiC,QACRjC,EAAM,OACX,MAAMkC,EAAQF,EAAKG,KAAK,KAAKF,OACxBC,IACLN,EAAK5B,GAAQoC,mBAAmBF,GAAM,IAGjCN,EAAK1B,EAAcmC,yBAXA,IAWuB,EDiCTC,CAAgB1B,GACtD,IAAI2B,EAA+B,KACnC,IACEA,QAAiBzB,EAAKb,eAAeuC,YAAYzB,EAClD,CAAC,MAAO0B,GACP,MAAMC,EAAiB,0BACjBC,EAAUF,aAAiBG,MAAQH,EAAME,QAAUD,EACzD,OAAO5B,EAAK+B,KAAK/B,EAAKgC,WAAW,IAAKH,GACvC,CA0BD7B,EAAKhB,SAASiD,OAAOR,GAxBE5B,MAAOqC,EAAoBC,EAAeC,KAC/D,GAAIF,EACF,OAAOlC,EAAK2B,MAAMO,GAEpB,IAAKC,EAKH,MAJmB,iBAARC,IACTA,EAAO,CAAEP,QAASO,IAEpBA,EAAOA,GAAQ,GACRpC,EAAK+B,KAAK/B,EAAKgC,WAAW,IAAK,gBAAiBI,EAAKP,UAE9D,GAAIO,GAAQA,EAAKC,YAAa,CAE5B,MAAMA,QAAoBrC,EAAKb,eAAemD,WAAWH,KAAKI,aAAad,EAASxB,MAAMuC,KAE1F,GADAC,QAAQC,IAAIL,IACPA,EAAYM,GACf,OAAO3C,EAAK+B,KAAK/B,EAAKgC,WAAW,IAAKK,EAAYV,MAAMiB,iBAAkBP,EAAYV,MAAMkB,eAE5FV,EAAOE,EAAYS,IAEtB,CACD,OAAO9C,EAAK+C,QAAQZ,EAAMC,EAAK,GAGctC,EAChD,CAUDkC,WAA0DgB,EAAeC,EAAeC,GACtF,IAAIC,EAAY,iBAAmBlE,KAAKM,OAAS,IAajD,OAZIN,KAAKS,SACPyD,GAAa,YAAclE,KAAKS,OAAO2B,KAAK,KAAO,KAEjD2B,IACFG,GAAa,YAAcH,EAAO,KAEhCC,IACFE,GAAa,wBAA0BF,EAAO,KAE5CC,IACFC,GAAa,gBAAkBD,EAAM,KAEhCC,CACR"}
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "passport-descope",
3
+ "version": "1.0.0",
4
+ "description": "Passport strategy for Descope authentication service",
5
+ "typings": "dist/index.d.ts",
6
+ "main": "dist/cjs/index.cjs.js",
7
+ "module": "./dist/index.esm.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ "require": "./dist/cjs/index.cjs.js",
11
+ "import": "./dist/index.esm.js"
12
+ },
13
+ "type": "module",
14
+ "files": [
15
+ "dist/**/*"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git://github.com/descope/passport-descope.git"
20
+ },
21
+ "engines": {
22
+ "node": ">= 12.0.0"
23
+ },
24
+ "scripts": {
25
+ "build": "rimraf dist && rollup -c",
26
+ "test": "jest",
27
+ "lint": "eslint src/**/*.ts --fix",
28
+ "format": "prettier . --write --ignore-path .gitignore",
29
+ "leaks": "bash gitleaks/gitleaks.sh"
30
+ },
31
+ "author": "Descope",
32
+ "bugs": {
33
+ "url": "git://github.com/descope/passport-descope/issues"
34
+ },
35
+ "license": "MIT",
36
+ "keywords": [
37
+ "descope",
38
+ "authentication",
39
+ "passport",
40
+ "node"
41
+ ],
42
+ "devDependencies": {
43
+ "@rollup/plugin-commonjs": "^24.0.0",
44
+ "@rollup/plugin-node-resolve": "^13.3.0",
45
+ "@rollup/plugin-typescript": "^8.3.0",
46
+ "@types/express": "^4.17.11",
47
+ "@types/jest": "^29.0.0",
48
+ "@types/jsonwebtoken": "^9.0.0",
49
+ "@types/passport": "^1.0.5",
50
+ "@types/node": "^15.14.9",
51
+ "@types/node-fetch": "^2.6.1",
52
+ "@typescript-eslint/eslint-plugin": "^5.25.0",
53
+ "@typescript-eslint/parser": "^5.27.0",
54
+ "eslint": "^8.15.0",
55
+ "eslint-config-airbnb-base": "^15.0.0",
56
+ "eslint-config-airbnb-typescript": "^17.0.0",
57
+ "eslint-config-prettier": "^8.5.0",
58
+ "eslint-import-resolver-typescript": "^3.0.0",
59
+ "eslint-plugin-import": "^2.26.0",
60
+ "eslint-plugin-jest": "^27.0.0",
61
+ "eslint-plugin-jest-dom": "^4.0.2",
62
+ "eslint-plugin-jest-formatting": "^3.1.0",
63
+ "eslint-plugin-no-only-tests": "^3.0.0",
64
+ "eslint-plugin-prefer-arrow": "^1.2.3",
65
+ "eslint-plugin-prettier": "^4.0.0",
66
+ "jest": "^29.0.0",
67
+ "prettier": "^2.7.1",
68
+ "rollup": "^2.62.0",
69
+ "rollup-plugin-delete": "^2.0.0",
70
+ "rollup-plugin-dts": "^4.2.2",
71
+ "rollup-plugin-terser": "^7.0.2",
72
+ "ts-jest": "^29.0.0",
73
+ "ts-node": "^10.8.2",
74
+ "typescript": "^4.6.4"
75
+ },
76
+ "dependencies": {
77
+ "@descope/node-sdk": "1.1.1"
78
+ },
79
+ "peerDependencies": {
80
+ "tslib": ">=1.14.1"
81
+ }
82
+ }