@midwayjs/passport 3.0.3 → 3.0.6
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/package.json +10 -11
- package/dist/config/config.default.js.map +0 -1
- package/dist/configuration.js.map +0 -1
- package/dist/decorator/strategy.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/interface.js.map +0 -1
- package/dist/proxy/framework/koa.js.map +0 -1
- package/dist/proxy/framework/request.js.map +0 -1
- package/dist/proxy/index.js.map +0 -1
- package/dist/service/passport.js.map +0 -1
- package/dist/util.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/passport",
|
|
3
3
|
"description": "midway passport component",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.6",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist/**/*.js",
|
|
9
9
|
"dist/**/*.d.ts",
|
|
10
|
-
"index.d.ts"
|
|
11
|
-
"dist/**/*.js.map"
|
|
10
|
+
"index.d.ts"
|
|
12
11
|
],
|
|
13
12
|
"scripts": {
|
|
14
13
|
"build": "tsc",
|
|
@@ -23,13 +22,13 @@
|
|
|
23
22
|
"author": "Nawbc",
|
|
24
23
|
"license": "MIT",
|
|
25
24
|
"devDependencies": {
|
|
26
|
-
"@midwayjs/core": "^3.0.
|
|
27
|
-
"@midwayjs/decorator": "^3.0.
|
|
28
|
-
"@midwayjs/express": "^3.0.
|
|
29
|
-
"@midwayjs/jwt": "^3.0.
|
|
30
|
-
"@midwayjs/koa": "^3.0.
|
|
31
|
-
"@midwayjs/mock": "^3.0.
|
|
32
|
-
"@midwayjs/web": "^3.0.
|
|
25
|
+
"@midwayjs/core": "^3.0.6",
|
|
26
|
+
"@midwayjs/decorator": "^3.0.6",
|
|
27
|
+
"@midwayjs/express": "^3.0.6",
|
|
28
|
+
"@midwayjs/jwt": "^3.0.6",
|
|
29
|
+
"@midwayjs/koa": "^3.0.6",
|
|
30
|
+
"@midwayjs/mock": "^3.0.6",
|
|
31
|
+
"@midwayjs/web": "^3.0.6",
|
|
33
32
|
"@types/passport": "1.0.7",
|
|
34
33
|
"@types/passport-local": "1.0.34",
|
|
35
34
|
"express-session": "1.17.2",
|
|
@@ -40,5 +39,5 @@
|
|
|
40
39
|
"peerDependencies": {
|
|
41
40
|
"passport": "^0.5.0"
|
|
42
41
|
},
|
|
43
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "afaa5b59a2be85e915233a9268c0e05965dd5c61"
|
|
44
43
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.default.js","sourceRoot":"","sources":["../../src/config/config.default.ts"],"names":[],"mappings":";;;AAAa,QAAA,QAAQ,GAAG;IACtB,OAAO,EAAE,IAAI;IACb,YAAY,EAAE,MAAM;CACrB,CAAC","sourcesContent":["export const passport = {\n session: true,\n userProperty: 'user',\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAA4D;AAC5D,yDAAyD;AACzD,iCAAqC;AACrC,yCAIwB;AAUxB,IAAa,qBAAqB,GAAlC,MAAa,qBAAqB;IAOhC,KAAK,CAAC,OAAO,CAAC,SAA2B;QACvC,MAAM,cAAc,GAAG,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;QACvE,MAAM,QAAQ,GAAG,IAAA,kBAAW,GAAE,CAAC;QAC/B,IAAI,CAAC,kBAAkB;aACpB,eAAe,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;aAClD,OAAO,CAAC,GAAG,CAAC,EAAE;YACb,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;YACzC,IAAI,cAAc,CAAC,OAAO,EAAE;gBAC1B,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;aACvC;QACH,CAAC,CAAC,CAAC;IACP,CAAC;CACF,CAAA;AAjBC;IADC,IAAA,kBAAM,GAAE;8BACW,+BAAwB;iEAAC;AAG7C;IADC,IAAA,kBAAM,GAAE;8BACM,0BAAmB;4DAAC;AALxB,qBAAqB;IARjC,IAAA,yBAAa,EAAC;QACb,SAAS,EAAE,UAAU;QACrB,aAAa,EAAE;YACb;gBACE,OAAO,EAAE,aAAa;aACvB;SACF;KACF,CAAC;GACW,qBAAqB,CAmBjC;AAnBY,sDAAqB","sourcesContent":["import { Inject, Configuration } from '@midwayjs/decorator';\nimport * as DefaultConfig from './config/config.default';\nimport { getPassport } from './util';\nimport {\n IMidwayContainer,\n MidwayApplicationManager,\n MidwayConfigService,\n} from '@midwayjs/core';\n\n@Configuration({\n namespace: 'passport',\n importConfigs: [\n {\n default: DefaultConfig,\n },\n ],\n})\nexport class PassportConfiguration {\n @Inject()\n applicationManager: MidwayApplicationManager;\n\n @Inject()\n configService: MidwayConfigService;\n\n async onReady(container: IMidwayContainer) {\n const passportConfig = this.configService.getConfiguration('passport');\n const passport = getPassport();\n this.applicationManager\n .getApplications(['express', 'koa', 'egg', 'faas'])\n .forEach(app => {\n app.useMiddleware(passport.initialize());\n if (passportConfig.session) {\n app.useMiddleware(passport.session());\n }\n });\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"strategy.js","sourceRoot":"","sources":["../../src/decorator/strategy.ts"],"names":[],"mappings":";;;AAAA,mDAAgE;AAEhE,SAAgB,cAAc;IAC5B,OAAO,MAAM,CAAC,EAAE;QACd,IAAA,iBAAK,EAAC,qBAAS,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;QACnC,IAAA,mBAAO,GAAE,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC;AALD,wCAKC","sourcesContent":["import { Provide, Scope, ScopeEnum } from '@midwayjs/decorator';\n\nexport function CustomStrategy(): ClassDecorator {\n return target => {\n Scope(ScopeEnum.Singleton)(target);\n Provide()(target);\n };\n}\n"]}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,iDAAyE;AAAhE,8GAAA,qBAAqB,OAAiB;AAC/C,uDAAqC;AACrC,qDAAmC","sourcesContent":["export { PassportConfiguration as Configuration } from './configuration';\nexport * from './decorator/strategy';\nexport * from './service/passport';\n"]}
|
package/dist/interface.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":";;;AAUA,MAAsB,gBAAgB;CAGrC;AAHD,4CAGC;AAMD,MAAsB,0BAA0B;CAG/C;AAHD,gEAGC","sourcesContent":["import * as passport from 'passport';\n\nexport interface IPassportStrategy {\n validate(...args): any;\n getStrategyOptions(): any;\n serializeUser?(user: any, done: (err: any, id?: any) => void): void;\n deserializeUser?(id: any, done: (err: any, user?: any) => void): void;\n transformAuthInfo?(info: any, done: (err: any, info: any) => void): void;\n}\n\nexport abstract class AbstractStrategy implements IPassportStrategy {\n abstract validate(...args): any;\n abstract getStrategyOptions(): any;\n}\n\nexport interface IPassportMiddleware {\n authenticate?(options: passport.AuthenticateOptions, callback: Function);\n}\n\nexport abstract class AbstractPassportMiddleware implements IPassportMiddleware {\n abstract getAuthenticateOptions(): Promise<passport.AuthenticateOptions> | passport.AuthenticateOptions;\n authenticate?(options: passport.AuthenticateOptions, callback?: Function);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"koa.js","sourceRoot":"","sources":["../../../src/proxy/framework/koa.ts"],"names":[],"mappings":"AAAA,YAAY,CA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S,SAAS,CAAC,iBAAiB;IAClC,OAAO,UAAU,GAAG,EAAE,GAAG;QACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;gBAC1C,IAAI,GAAG;oBAAE,MAAM,CAAC,GAAG,CAAC,CAAC;;oBAChB,OAAO,CAAC,MAAM,CAAC,CAAC;YACvB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["'use strict';\n\n/**\n * Module dependencies.\n */\nconst passport = require('passport');\n\n/**\n * Passport's default/connect middleware.\n */\nconst _initialize = require('passport/lib/middleware/initialize');\nconst _authenticate = require('passport/lib/middleware/authenticate');\nconst createReqMock = require('./request').create;\n\n/**\n * Passport's initialization middleware for Koa.\n *\n * @return {GeneratorFunction}\n * @api private\n */\nfunction initialize(passport) {\n const middleware = promisify(_initialize(passport));\n return function passportInitialize(ctx, next) {\n // koa <-> connect compatibility:\n const userProperty = passport._userProperty || 'user';\n // check ctx.req has the userProperty\n // eslint-disable-next-line no-prototype-builtins\n if (!ctx.req.hasOwnProperty(userProperty)) {\n Object.defineProperty(ctx.req, userProperty, {\n enumerable: true,\n get: function () {\n return ctx.state[userProperty];\n },\n set: function (val) {\n ctx.state[userProperty] = val;\n },\n });\n }\n\n // create mock object for express' req object\n const req = createReqMock(ctx, userProperty);\n\n // add Promise-based login method\n const login = req.login;\n ctx.login = ctx.logIn = function (user, options) {\n return new Promise<void>((resolve, reject) => {\n // fix session manager missing\n if (!req._sessionManager) {\n req._sessionManager = passport._sm;\n }\n login.call(req, user, options, err => {\n if (err) reject(err);\n else resolve();\n });\n });\n };\n\n // add aliases for passport's request extensions to Koa's context\n ctx.logout = ctx.logOut = req.logout.bind(req);\n ctx.isAuthenticated = req.isAuthenticated.bind(req);\n ctx.isUnauthenticated = req.isUnauthenticated.bind(req);\n\n return middleware(req, ctx).then(() => {\n return next();\n });\n };\n}\n\n/**\n * Passport's authenticate middleware for Koa.\n *\n * @param {String|Array} name\n * @param {Object} options\n * @param {GeneratorFunction} callback\n * @return {GeneratorFunction}\n * @api private\n */\nfunction authenticate(passport, name, options, callback) {\n // normalize arguments\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n options = options || {};\n\n if (callback) {\n // When the callback is set, neither `next`, `res.redirect` or `res.end`\n // are called. That is, a workaround to catch the `callback` is required.\n // The `passportAuthenticate()` method below will therefore set\n // `callback.resolve` and `callback.reject`. Then, once the authentication\n // finishes, the modified callback calls the original one and afterwards\n // triggers either `callback.resolve` or `callback.reject` to inform\n // `passportAuthenticate()` that we are ready.\n const _callback = callback;\n callback = function (err, user, info, status) {\n try {\n Promise.resolve(_callback(err, user, info, status))\n .then(() => callback.resolve(false))\n .catch(err => callback.reject(err));\n } catch (err) {\n callback.reject(err);\n }\n };\n }\n\n const middleware = promisify(\n _authenticate(passport, name, options, callback)\n );\n\n return function passportAuthenticate(ctx, next) {\n // this functions wraps the connect middleware\n // to catch `next`, `res.redirect` and `res.end` calls\n const p = new Promise((resolve, reject) => {\n // mock the `req` object\n const req = createReqMock(\n ctx,\n options.assignProperty || passport._userProperty || 'user'\n );\n\n function setBodyAndResolve(content) {\n if (content) ctx.body = content;\n resolve(false);\n }\n\n // mock the `res` object\n const res = {\n redirect: function (url) {\n ctx.redirect(url);\n resolve(false);\n },\n set: ctx.set.bind(ctx),\n setHeader: ctx.set.bind(ctx),\n end: setBodyAndResolve,\n send: setBodyAndResolve,\n set statusCode(status) {\n ctx.status = status;\n },\n get statusCode() {\n return ctx.status;\n },\n };\n\n req.res = res;\n\n // update the custom callback above\n if (callback) {\n callback.resolve = resolve;\n callback.reject = reject;\n }\n\n // call the connect middleware\n middleware(req, res).then(resolve, reject);\n });\n\n return p.then(cont => {\n // cont equals `false` when `res.redirect` or `res.end` got called\n // in this case, call next to continue through Koa's middleware stack\n if (cont !== false) {\n return next();\n }\n });\n };\n}\n\n/**\n * Passport's authorize middleware for Koa.\n *\n * @param {String|Array} name\n * @param {Object} options\n * @param {GeneratorFunction} callback\n * @return {GeneratorFunction}\n * @api private\n */\nfunction authorize(passport, name, options, callback) {\n options = options || {};\n options.assignProperty = 'account';\n\n return authenticate(passport, name, options, callback);\n}\n\n/**\n * Framework support for Koa.\n *\n * This module provides support for using Passport with Koa. It exposes\n * middleware that conform to the `fn*(next)` signature and extends\n * Node's built-in HTTP request object with useful authentication-related\n * functions.\n *\n * @return {Object}\n * @api protected\n */\nmodule.exports = function () {\n return {\n initialize: initialize,\n authenticate: authenticate,\n authorize: authorize,\n };\n};\n\nfunction promisify(expressMiddleware) {\n return function (req, res) {\n return new Promise((resolve, reject) => {\n expressMiddleware(req, res, (err, result) => {\n if (err) reject(err);\n else resolve(result);\n });\n });\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/proxy/framework/request.ts"],"names":[],"mappings":"AAAA,oBAAoB;AAEpB,6EAA6E;AAC7E,2BAA2B;AAC3B,2EAA2E;AAC3E,uEAAuE;AACvE,2EAA2E;AAC3E,2EAA2E;AAC3E,yEAAyE;AACzE,6EAA6E;AAC7E,4BAA4B;AAC5B,EAAE;AACF,gCAAgC;AAChC,uEAAuE;AACvE,4EAA4E;AAC5E,4BAA4B;AAC5B,gDAAgD;AAChD,qCAAqC;AACrC,iFAAiF;AACjF,QAAQ;AACR,QAAQ;AACR,IAAI;AACJ,EAAE;AACF,sEAAsE;AACtE,uDAAuD;AACvD,EAAE;AACF,8EAA8E;AAC9E,wBAAwB;AAExB,wCAAwC;AACxC,IAAI,IAAI,GAAG;IACT,WAAW;IACX,WAAW;IACX,UAAU;IAEV,uBAAuB;IACvB,aAAa;IACb,SAAS;IACT,UAAU;IACV,YAAY;IACZ,QAAQ;IACR,KAAK;IACL,YAAY;IACZ,QAAQ;IACR,YAAY;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EAAE,KAAK,EAAE;QAChC,UAAU,EAAE,IAAI;QAChB,GAAG,EAAE;YACH,OAAO,GAAG,CAAC;QACb,CAAC;KACF,CAAC,CAAC;IAEH,+CAA+C;IAC/C,GAAG,CAAC,KAAK,GAAG,kBAAkB,CAAC,KAAK,CAAC;IACrC,GAAG,CAAC,KAAK,GAAG,kBAAkB,CAAC,KAAK,CAAC;IACrC,GAAG,CAAC,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC;IACvC,GAAG,CAAC,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC;IACvC,GAAG,CAAC,eAAe,GAAG,kBAAkB,CAAC,eAAe,CAAC;IACzD,GAAG,CAAC,iBAAiB,GAAG,kBAAkB,CAAC,iBAAiB,CAAC;IAE7D,OAAO,GAAG,CAAC;AACb,CAAC,CAAC","sourcesContent":["/* eslint-disable */\n\n// Koa and Express are fundamental different in how they deal with extensions\n// to the incoming request.\n// Express pollutes Node's IncomingRequest directly, while Koa keeps Node's\n// IncomingRequest untouched and adds is own high-level request object.\n// These both approaches are not directly compatible with each other, since\n// properties/methods found in Express' `req` object are now spread between\n// Koa's context, Koa's request object and the original incoming request.\n// This makes moking the Express `req` object an ugly task. With ES6 we could\n// simply use a Proxy, e.g.:\n//\n// function createReqMock(ctx) {\n// // Use a proxy that forwards `req` reads to either `ctx.passport`,\n// // Node's request, Koa's request or Koa's context. Writes are persistet\n// // into `ctx.passport`.\n// return Proxy.create(handler(ctx.passport, {\n// get: function(receiver, key) {\n// return ctx.passport[key] || ctx.req[key] || ctx.request[key] || ctx[key]\n// }\n// }))\n// }\n//\n// However, the current Proxy implementation does not allow debugging.\n// See: https://github.com/rkusa/koa-passport/issues/17\n//\n// Until this is fixed, koa-passport tries to properly delegate every possible\n// used property/method.\n\n// Property/Method names to be delegated\nlet keys = [\n // passport\n '_passport',\n 'authInfo',\n\n // http.IncomingMessage\n 'httpVersion',\n 'headers',\n 'trailers',\n 'setTimeout',\n 'method',\n 'url',\n 'statusCode',\n 'socket',\n 'connection',\n 'protocol',\n\n // Koa's context\n 'cookies',\n 'throw',\n 'ip',\n\n // Others. Are not supported directly - require proper plugins/middlewares.\n 'param',\n 'params',\n 'route',\n 'xhr',\n 'baseUrl',\n 'session',\n 'body',\n 'flash',\n];\n\n// remove duplicates\nkeys = keys.filter((key, i, self) => {\n return self.indexOf(key) === i;\n});\n\n// create a delegate for each key\nconst properties = {\n // mock express' .get('trust proxy')\n app: {\n // getter returning a mock for `req.app` containing\n // the `.get()` method\n get: function () {\n const ctx = this.ctx;\n return {\n get: function (key) {\n if (key === 'trust proxy') {\n return ctx.app.proxy;\n }\n\n return undefined;\n },\n };\n },\n },\n};\n\nkeys.forEach(key => {\n properties[key] = {\n get: function () {\n const obj = getObject(this.ctx, key);\n if (!obj) return undefined;\n\n // if its a function, call with the proper context\n if (typeof obj[key] === 'function') {\n return function () {\n return obj[key].apply(obj, arguments);\n };\n }\n\n // otherwise, simply return it\n return obj[key];\n },\n set: function (value) {\n const obj = getObject(this.ctx, key) || this.ctx.state;\n obj[key] = value;\n },\n };\n});\n\n// test where the key is available, either in `ctx.state`, Node's request,\n// Koa's request or Koa's context\nfunction getObject(ctx, key) {\n if (ctx.state && key in ctx.state) {\n return ctx.state;\n }\n\n if (key in ctx.request) {\n return ctx.request;\n }\n\n if (key in ctx.req) {\n return ctx.req;\n }\n\n if (key in ctx) {\n return ctx;\n }\n\n return undefined;\n}\n\nconst IncomingMessageExt = require('passport/lib/http/request');\n\nexports.create = function (ctx, userProperty) {\n const req = Object.create(ctx.request, properties);\n\n Object.defineProperty(req, userProperty, {\n enumerable: true,\n get: function () {\n return ctx.state[userProperty];\n },\n set: function (val) {\n ctx.state[userProperty] = val;\n },\n });\n\n Object.defineProperty(req, 'ctx', {\n enumerable: true,\n get: function () {\n return ctx;\n },\n });\n\n // add passport http.IncomingMessage extensions\n req.login = IncomingMessageExt.logIn;\n req.logIn = IncomingMessageExt.logIn;\n req.logout = IncomingMessageExt.logOut;\n req.logOut = IncomingMessageExt.logOut;\n req.isAuthenticated = IncomingMessageExt.isAuthenticated;\n req.isUnauthenticated = IncomingMessageExt.isUnauthenticated;\n\n return req;\n};\n"]}
|
package/dist/proxy/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/proxy/index.ts"],"names":[],"mappings":";;;AAAA,wCAAwC;AACxC,MAAM,OAAO,GAAG,OAAO,CAAC,gCAAgC,CAAC,CAAC;AAC1D,OAAO,CAAC,iBAAiB,GAAG,cAAa,CAAC,CAAC;AAE3C,0CAA0C;AAC1C,MAAM,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAC3C,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC;AAC9C,MAAM,SAAS,GAAG,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;AAE/C,cAAc,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AAEpC,MAAa,WAAY,SAAQ,QAAQ;IACvC;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAC5B,CAAC;CACF;AALD,kCAKC;AAED,4BAA4B;AACf,QAAA,QAAQ,GAAG,cAAc,CAAC","sourcesContent":["// prevent passport from monkey patching\nconst connect = require('passport/lib/framework/connect');\nconnect.__monkeypatchNode = function () {};\n\n// load passport and add the koa framework\nconst originPassport = require('passport');\nconst Passport = require('passport').Passport;\nconst framework = require('./framework/koa')();\n\noriginPassport.framework(framework);\n\nexport class KoaPassport extends Passport {\n constructor() {\n super();\n this.framework(framework);\n }\n}\n\n// Export default singleton.\nexport const passport = originPassport;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"passport.js","sourceRoot":"","sources":["../../src/service/passport.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,mDAAwD;AACxD,kCAAqD;AACrD,4CAA4E;AAC5E,yCAA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C;6BACF;4BACD,MAAM,IAAI,EAAE,CAAC;yBACd;wBAAC,OAAO,GAAG,EAAE;4BACZ,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;yBAChB;qBACF;gBACH,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aACd;QACH,CAAC;QAED,MAAM,CAAC,OAAO;YACZ,OAAO,UAAU,CAAC;QACpB,CAAC;KACF;IAtKC;QADC,IAAA,kBAAM,EAAC,UAAU,CAAC;;mEACJ;IAGf;QADC,IAAA,eAAG,GAAE;;wDACF;IAoKN,OAAO,uBAA8B,CAAC;AACxC,CAAC;AA7KD,gDA6KC","sourcesContent":["import * as passport from 'passport';\nimport { App, Config, Init } from '@midwayjs/decorator';\nimport { getPassport, isExpressMode } from '../util';\nimport { AbstractPassportMiddleware, AbstractStrategy } from '../interface';\nimport { httpError } from '@midwayjs/core';\n\nexport function PassportStrategy(\n Strategy: new (...args) => passport.Strategy,\n name?: string\n): new (...args) => AbstractStrategy {\n abstract class InnerStrategyAbstractClass extends AbstractStrategy {\n private strategy;\n\n @Init()\n async init() {\n const cb = async (...params: any[]) => {\n const done = params[params.length - 1];\n try {\n const result = await this.validate(...params);\n if (Array.isArray(result)) {\n done(null, ...result);\n } else {\n done(null, result);\n }\n } catch (err) {\n done(err, null);\n }\n };\n\n this.strategy = new Strategy(this.getStrategyOptions(), cb);\n\n const passport = getPassport() as passport.PassportStatic;\n if (name) {\n passport.use(name, this.strategy);\n } else {\n passport.use(this.strategy);\n }\n if (this['serializeUser']) {\n passport.serializeUser(this['serializeUser']);\n }\n\n if (this['deserializeUser']) {\n passport.deserializeUser(this['deserializeUser']);\n }\n\n if (this['transformAuthInfo']) {\n passport.transformAuthInfo(this['transformAuthInfo']);\n }\n }\n\n getStrategy() {\n return this.strategy;\n }\n }\n return InnerStrategyAbstractClass as any;\n}\n\nexport type StrategyClass = new (...args) => AbstractStrategy;\n\nexport function PassportMiddleware(\n strategy: StrategyClass | StrategyClass[]\n): new (...args) => AbstractPassportMiddleware {\n abstract class InnerPassportMiddleware extends AbstractPassportMiddleware {\n @Config('passport')\n passportConfig;\n\n @App()\n app;\n\n resolve() {\n if (isExpressMode()) {\n return async function passportMiddleware(req, res, next) {\n return this.authenticate(await this.getAuthenticateOptions())(\n req,\n res,\n next\n );\n }.bind(this);\n } else {\n return async function passportMiddleware(ctx, next) {\n return this.authenticate(await this.getAuthenticateOptions())(\n ctx,\n next\n );\n }.bind(this);\n }\n }\n\n getAuthenticateOptions():\n | Promise<passport.AuthenticateOptions>\n | passport.AuthenticateOptions {\n return undefined;\n }\n\n authenticate(options: passport.AuthenticateOptions): any {\n if (!Array.isArray(strategy)) {\n strategy = [strategy];\n }\n\n if (isExpressMode()) {\n return async (req, res, next) => {\n // merge options with default options\n const authOptions = {\n ...this.passportConfig,\n ...options,\n };\n\n if (authOptions.session && req.session[authOptions.userProperty]) {\n req[authOptions.userProperty] =\n req.session[authOptions.userProperty];\n }\n // ignore user has exists\n if (req[authOptions.userProperty]) {\n next();\n } else {\n const passport = getPassport() as passport.PassportStatic;\n const strategyList = [];\n for (const strategySingle of strategy as StrategyClass[]) {\n // got strategy\n const strategyInstance = await this.app\n .getApplicationContext()\n .getAsync(strategySingle);\n strategyList.push(strategyInstance.getStrategy());\n }\n\n const user = await new Promise<any>((resolve, reject) => {\n // authenticate\n passport.authenticate(\n strategyList,\n authOptions,\n (err, user, info, status) => {\n if (err) {\n reject(err);\n } else {\n resolve(user);\n }\n }\n )(req, res, err => (err ? reject(err) : resolve(0)));\n });\n if (user) {\n req[authOptions.userProperty] = user;\n if (authOptions.session) {\n req.logIn(user, options, next);\n return;\n }\n } else {\n if (options.failureRedirect) {\n res.redirect(options.failureRedirect);\n return;\n } else {\n throw new httpError.UnauthorizedError();\n }\n }\n next();\n }\n };\n } else {\n return async function bbb(ctx, next) {\n // merge options with default options\n const authOptions = {\n ...this.passportConfig,\n ...options,\n };\n\n if (\n authOptions.session &&\n ctx.session.passport &&\n ctx.session.passport[authOptions.userProperty]\n ) {\n ctx.state[authOptions.userProperty] =\n ctx.session.passport[authOptions.userProperty];\n }\n // ignore user has exists\n if (ctx.state[authOptions.userProperty]) {\n await next();\n } else {\n const passport = getPassport() as passport.PassportStatic;\n const strategyList = [];\n for (const strategySingle of strategy as StrategyClass[]) {\n // got strategy\n const strategyInstance = await this.app\n .getApplicationContext()\n .getAsync(strategySingle);\n strategyList.push(strategyInstance.getStrategy());\n }\n try {\n const user = await new Promise<any>((resolve, reject) => {\n // authenticate\n passport.authenticate(\n strategyList,\n authOptions,\n (err, user, info, status) => {\n if (err) {\n reject(err);\n } else {\n resolve(user);\n }\n }\n )(ctx, err => (err ? reject(err) : resolve(0)));\n });\n if (user) {\n ctx.state[authOptions.userProperty] = user;\n if (authOptions.session) {\n // save to ctx.session.passport\n await ctx.login(user, options);\n }\n if (options.successRedirect) {\n ctx.redirect(options.successRedirect);\n return;\n }\n } else {\n if (options.failureRedirect) {\n ctx.redirect(options.failureRedirect);\n return;\n } else {\n throw new httpError.UnauthorizedError();\n }\n }\n await next();\n } catch (err) {\n ctx.throw(err);\n }\n }\n }.bind(this);\n }\n }\n\n static getName() {\n return 'passport';\n }\n }\n return InnerPassportMiddleware as any;\n}\n"]}
|
package/dist/util.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;AAAA,yCAA6C;AAE7C,SAAgB,WAAW;IACzB,OAAO,aAAa,EAAE;QACpB,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;QACrB,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC;AACxC,CAAC;AAJD,kCAIC;AAED,SAAgB,aAAa;;IAC3B,OAAO,CAAC,CAAC,CACP,MAAA,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,KAAK,SAAS,mCACjD,IAAA,kBAAW,EAAC,mBAAmB,CAAC,CACjC,CAAC;AACJ,CAAC;AALD,sCAKC","sourcesContent":["import { safeRequire } from '@midwayjs/core';\n\nexport function getPassport() {\n return isExpressMode()\n ? require('passport')\n : require('./proxy/index').passport;\n}\n\nexport function isExpressMode(): boolean {\n return !!(\n process.env['MIDWAY_PASSPORT_MODE'] === 'express' ??\n safeRequire('@midwayjs/express')\n );\n}\n"]}
|