@midwayjs/passport 3.4.0 → 3.4.4
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.
|
@@ -61,7 +61,7 @@ export declare class PassportAuthenticator {
|
|
|
61
61
|
}>;
|
|
62
62
|
};
|
|
63
63
|
}>;
|
|
64
|
-
serializeUser(
|
|
64
|
+
serializeUser(user: any, req: any, done: any): void;
|
|
65
65
|
/**
|
|
66
66
|
* Registers a function used to deserialize user objects out of the session.
|
|
67
67
|
*
|
|
@@ -75,7 +75,7 @@ export declare class PassportAuthenticator {
|
|
|
75
75
|
*
|
|
76
76
|
* @api public
|
|
77
77
|
*/
|
|
78
|
-
deserializeUser(
|
|
78
|
+
deserializeUser(obj: any, req: any, done: any): void;
|
|
79
79
|
/**
|
|
80
80
|
* Registers a function used to transform auth info.
|
|
81
81
|
*
|
|
@@ -114,12 +114,15 @@ export declare class PassportAuthenticator {
|
|
|
114
114
|
*
|
|
115
115
|
* @api public
|
|
116
116
|
*/
|
|
117
|
-
transformAuthInfo(
|
|
117
|
+
transformAuthInfo(info: any, req: any, done: any): void;
|
|
118
118
|
logInToSession(req: IncomingMessage & {
|
|
119
119
|
session: any;
|
|
120
120
|
}, user: any): Promise<void>;
|
|
121
121
|
logOutFromSession(req: any, options?: {
|
|
122
122
|
keepSessionInfo?: boolean;
|
|
123
123
|
}): Promise<void>;
|
|
124
|
+
addSerializer(fn: any): void;
|
|
125
|
+
addDeserializer(fn: any): void;
|
|
126
|
+
addInfoTransformer(fn: any): void;
|
|
124
127
|
}
|
|
125
128
|
//# sourceMappingURL=authenticator.d.ts.map
|
|
@@ -198,18 +198,7 @@ let PassportAuthenticator = class PassportAuthenticator {
|
|
|
198
198
|
};
|
|
199
199
|
};
|
|
200
200
|
}
|
|
201
|
-
serializeUser(
|
|
202
|
-
if (typeof fn === 'function') {
|
|
203
|
-
return this._serializers.push(fn);
|
|
204
|
-
}
|
|
205
|
-
// private implementation that traverses the chain of serializers, attempting
|
|
206
|
-
// to serialize a user
|
|
207
|
-
const user = fn;
|
|
208
|
-
// For backwards compatibility
|
|
209
|
-
if (typeof req === 'function') {
|
|
210
|
-
done = req;
|
|
211
|
-
req = undefined;
|
|
212
|
-
}
|
|
201
|
+
serializeUser(user, req, done) {
|
|
213
202
|
const stack = this._serializers;
|
|
214
203
|
(function pass(i, err, obj) {
|
|
215
204
|
// serializers use 'pass' as an error to skip processing
|
|
@@ -254,18 +243,7 @@ let PassportAuthenticator = class PassportAuthenticator {
|
|
|
254
243
|
*
|
|
255
244
|
* @api public
|
|
256
245
|
*/
|
|
257
|
-
deserializeUser(
|
|
258
|
-
if (typeof fn === 'function') {
|
|
259
|
-
return this._deserializers.push(fn);
|
|
260
|
-
}
|
|
261
|
-
// private implementation that traverses the chain of deserializers,
|
|
262
|
-
// attempting to deserialize a user
|
|
263
|
-
const obj = fn;
|
|
264
|
-
// For backwards compatibility
|
|
265
|
-
if (typeof req === 'function') {
|
|
266
|
-
done = req;
|
|
267
|
-
req = undefined;
|
|
268
|
-
}
|
|
246
|
+
deserializeUser(obj, req, done) {
|
|
269
247
|
const stack = this._deserializers;
|
|
270
248
|
(function pass(i, err, user) {
|
|
271
249
|
// deserializers use 'pass' as an error to skip processing
|
|
@@ -340,18 +318,7 @@ let PassportAuthenticator = class PassportAuthenticator {
|
|
|
340
318
|
*
|
|
341
319
|
* @api public
|
|
342
320
|
*/
|
|
343
|
-
transformAuthInfo(
|
|
344
|
-
if (typeof fn === 'function') {
|
|
345
|
-
return this._infoTransformers.push(fn);
|
|
346
|
-
}
|
|
347
|
-
// private implementation that traverses the chain of transformers,
|
|
348
|
-
// attempting to transform auth info
|
|
349
|
-
const info = fn;
|
|
350
|
-
// For backwards compatibility
|
|
351
|
-
if (typeof req === 'function') {
|
|
352
|
-
done = req;
|
|
353
|
-
req = undefined;
|
|
354
|
-
}
|
|
321
|
+
transformAuthInfo(info, req, done) {
|
|
355
322
|
const stack = this._infoTransformers;
|
|
356
323
|
(function pass(i, err, tinfo) {
|
|
357
324
|
// transformers use 'pass' as an error to skip processing
|
|
@@ -440,6 +407,15 @@ let PassportAuthenticator = class PassportAuthenticator {
|
|
|
440
407
|
});
|
|
441
408
|
});
|
|
442
409
|
}
|
|
410
|
+
addSerializer(fn) {
|
|
411
|
+
this._serializers.push(fn);
|
|
412
|
+
}
|
|
413
|
+
addDeserializer(fn) {
|
|
414
|
+
this._deserializers.push(fn);
|
|
415
|
+
}
|
|
416
|
+
addInfoTransformer(fn) {
|
|
417
|
+
this._infoTransformers.push(fn);
|
|
418
|
+
}
|
|
443
419
|
};
|
|
444
420
|
__decorate([
|
|
445
421
|
(0, decorator_1.ApplicationContext)(),
|
|
@@ -34,6 +34,9 @@ function PassportStrategy(Strategy, name) {
|
|
|
34
34
|
done(err, null);
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
+
Object.defineProperty(cb, 'length', {
|
|
38
|
+
value: this.validate.length + 1,
|
|
39
|
+
});
|
|
37
40
|
this.strategy = new Strategy(this.getStrategyOptions(), cb);
|
|
38
41
|
if (name) {
|
|
39
42
|
this.passport.use(name, this.strategy);
|
|
@@ -42,13 +45,13 @@ function PassportStrategy(Strategy, name) {
|
|
|
42
45
|
this.passport.use(this.strategy);
|
|
43
46
|
}
|
|
44
47
|
if (this['serializeUser']) {
|
|
45
|
-
this.passport.
|
|
48
|
+
this.passport.addSerializer(this['serializeUser']);
|
|
46
49
|
}
|
|
47
50
|
if (this['deserializeUser']) {
|
|
48
|
-
this.passport.
|
|
51
|
+
this.passport.addDeserializer(this['deserializeUser']);
|
|
49
52
|
}
|
|
50
53
|
if (this['transformAuthInfo']) {
|
|
51
|
-
this.passport.
|
|
54
|
+
this.passport.addInfoTransformer(this['transformAuthInfo']);
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
getStrategy() {
|
|
@@ -99,7 +102,19 @@ function PassportMiddleware(strategy) {
|
|
|
99
102
|
}
|
|
100
103
|
// authenticate
|
|
101
104
|
const authenticate = this.passport.authenticate(strategyList, authOptions);
|
|
102
|
-
|
|
105
|
+
let authenticateResult;
|
|
106
|
+
try {
|
|
107
|
+
authenticateResult = await authenticate(req);
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
if (err instanceof core_1.MidwayHttpError) {
|
|
111
|
+
throw err;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
// 如果验证流程里有错误,抛出一个 500 错误
|
|
115
|
+
throw new core_1.httpError.InternalServerErrorError(err);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
103
118
|
// success
|
|
104
119
|
if (authenticateResult.successResult) {
|
|
105
120
|
const breakNext = await this.onceSucceed(options, authenticateResult.successResult.user, authenticateResult.successResult.info, req, res);
|
|
@@ -166,7 +181,19 @@ function PassportMiddleware(strategy) {
|
|
|
166
181
|
}
|
|
167
182
|
// authenticate
|
|
168
183
|
const authenticate = this.passport.authenticate(strategyList, authOptions);
|
|
169
|
-
|
|
184
|
+
let authenticateResult;
|
|
185
|
+
try {
|
|
186
|
+
authenticateResult = await authenticate(req);
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
if (err instanceof core_1.MidwayHttpError) {
|
|
190
|
+
throw err;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
// 如果验证流程里有错误,抛出一个 500 错误
|
|
194
|
+
throw new core_1.httpError.InternalServerErrorError(err);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
170
197
|
// success
|
|
171
198
|
if (authenticateResult.successResult) {
|
|
172
199
|
const breakNext = await this.onceSucceed(options, authenticateResult.successResult.user, authenticateResult.successResult.info, req, ctx);
|
|
@@ -29,6 +29,6 @@ export declare class SessionStrategy extends Strategy {
|
|
|
29
29
|
* @param {Object} options
|
|
30
30
|
* @api protected
|
|
31
31
|
*/
|
|
32
|
-
authenticate(req: any, options: any):
|
|
32
|
+
authenticate(req: any, options: any): void;
|
|
33
33
|
}
|
|
34
34
|
//# sourceMappingURL=session.stratey.d.ts.map
|
|
@@ -31,7 +31,7 @@ class SessionStrategy extends strategy_1.Strategy {
|
|
|
31
31
|
*/
|
|
32
32
|
authenticate(req, options) {
|
|
33
33
|
if (!req.session) {
|
|
34
|
-
|
|
34
|
+
throw new core_1.httpError.UnauthorizedError('Login sessions require session support,please enable it.');
|
|
35
35
|
}
|
|
36
36
|
options = options || {};
|
|
37
37
|
let su;
|
|
@@ -45,7 +45,7 @@ class SessionStrategy extends strategy_1.Strategy {
|
|
|
45
45
|
const paused = options.pauseStream ? (0, pause_1.pause)(req) : null;
|
|
46
46
|
this._deserializeUser(su, req, (err, user) => {
|
|
47
47
|
if (err) {
|
|
48
|
-
|
|
48
|
+
throw new core_1.httpError.UnauthorizedError(err.message);
|
|
49
49
|
}
|
|
50
50
|
if (!user) {
|
|
51
51
|
delete req.session[this.options.sessionUserProperty].user;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/passport",
|
|
3
3
|
"description": "midway passport component",
|
|
4
|
-
"version": "3.4.
|
|
4
|
+
"version": "3.4.4",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -22,18 +22,18 @@
|
|
|
22
22
|
"author": "Nawbc",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@midwayjs/core": "^3.4.
|
|
26
|
-
"@midwayjs/decorator": "^3.4.
|
|
27
|
-
"@midwayjs/express": "^3.4.
|
|
28
|
-
"@midwayjs/jwt": "^3.4.
|
|
29
|
-
"@midwayjs/koa": "^3.4.
|
|
30
|
-
"@midwayjs/mock": "^3.4.
|
|
31
|
-
"@midwayjs/web": "^3.4.
|
|
25
|
+
"@midwayjs/core": "^3.4.4",
|
|
26
|
+
"@midwayjs/decorator": "^3.4.4",
|
|
27
|
+
"@midwayjs/express": "^3.4.4",
|
|
28
|
+
"@midwayjs/jwt": "^3.4.4",
|
|
29
|
+
"@midwayjs/koa": "^3.4.4",
|
|
30
|
+
"@midwayjs/mock": "^3.4.4",
|
|
31
|
+
"@midwayjs/web": "^3.4.4",
|
|
32
32
|
"@types/passport-local": "1.0.34",
|
|
33
33
|
"express-session": "1.17.3",
|
|
34
34
|
"passport-jwt": "4.0.0",
|
|
35
35
|
"passport-local": "1.0.0",
|
|
36
36
|
"passport-openidconnect": "0.1.1"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "f6b5a3ff3d19ae2a0d33a5a14357bee2a8463767"
|
|
39
39
|
}
|