@midwayjs/passport 3.4.0-beta.11 → 3.4.0-beta.12
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/dist/interface.d.ts +0 -7
- package/dist/interface.js +1 -4
- package/dist/passport/passport.service.d.ts +4 -4
- package/dist/passport/passport.service.js +47 -37
- package/dist/passport/pause.d.ts +19 -0
- package/dist/passport/pause.js +50 -0
- package/dist/passport/session.stratey.js +2 -2
- package/dist/passport/strategy.d.ts +5 -1
- package/dist/passport/strategy.js +4 -1
- package/package.json +9 -12
package/dist/interface.d.ts
CHANGED
|
@@ -2,13 +2,10 @@ import { IMiddleware } from '@midwayjs/core';
|
|
|
2
2
|
export interface AuthenticateOptions {
|
|
3
3
|
authInfo?: boolean | undefined;
|
|
4
4
|
assignProperty?: string | undefined;
|
|
5
|
-
failureFlash?: string | boolean | undefined;
|
|
6
5
|
failureMessage?: boolean | string | undefined;
|
|
7
6
|
failureRedirect?: string | undefined;
|
|
8
|
-
failWithError?: boolean | undefined;
|
|
9
7
|
session?: boolean | undefined;
|
|
10
8
|
scope?: string | string[] | undefined;
|
|
11
|
-
successFlash?: string | boolean | undefined;
|
|
12
9
|
successMessage?: boolean | string | undefined;
|
|
13
10
|
successRedirect?: string | undefined;
|
|
14
11
|
successReturnToOrRedirect?: string | undefined;
|
|
@@ -25,10 +22,6 @@ export interface IPassportStrategy {
|
|
|
25
22
|
deserializeUser?(id: any, done: (err: any, user?: any) => void): void;
|
|
26
23
|
transformAuthInfo?(info: any, done: (err: any, info: any) => void): void;
|
|
27
24
|
}
|
|
28
|
-
export declare abstract class AbstractStrategy implements IPassportStrategy {
|
|
29
|
-
abstract validate(...args: any[]): any;
|
|
30
|
-
abstract getStrategyOptions(): any;
|
|
31
|
-
}
|
|
32
25
|
export interface IPassportMiddleware extends IMiddleware<any, any> {
|
|
33
26
|
authenticate?(options: AuthenticateOptions, callback: Function): any;
|
|
34
27
|
}
|
package/dist/interface.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AbstractPassportMiddleware =
|
|
4
|
-
class AbstractStrategy {
|
|
5
|
-
}
|
|
6
|
-
exports.AbstractStrategy = AbstractStrategy;
|
|
3
|
+
exports.AbstractPassportMiddleware = void 0;
|
|
7
4
|
class AbstractPassportMiddleware {
|
|
8
5
|
resolve() { }
|
|
9
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AbstractPassportMiddleware
|
|
2
|
-
import { Strategy } from './strategy';
|
|
3
|
-
export declare function PassportStrategy(Strategy: new (...args: any[]) => Strategy, name?: string): new (...args: any[]) =>
|
|
4
|
-
export declare type StrategyClass = new (...args: any[]) =>
|
|
1
|
+
import { AbstractPassportMiddleware } from '../interface';
|
|
2
|
+
import { AbstractStrategyWrapper, Strategy } from './strategy';
|
|
3
|
+
export declare function PassportStrategy(Strategy: new (...args: any[]) => Strategy, name?: string): new (...args: any[]) => AbstractStrategyWrapper;
|
|
4
|
+
export declare type StrategyClass = new (...args: any[]) => AbstractStrategyWrapper;
|
|
5
5
|
export declare function PassportMiddleware(strategy: StrategyClass | StrategyClass[]): new (...args: any[]) => AbstractPassportMiddleware;
|
|
6
6
|
//# sourceMappingURL=passport.service.d.ts.map
|
|
@@ -14,10 +14,10 @@ const decorator_1 = require("@midwayjs/decorator");
|
|
|
14
14
|
const interface_1 = require("../interface");
|
|
15
15
|
const core_1 = require("@midwayjs/core");
|
|
16
16
|
const authenticator_1 = require("./authenticator");
|
|
17
|
-
const
|
|
17
|
+
const strategy_1 = require("./strategy");
|
|
18
18
|
const request_1 = require("./request");
|
|
19
19
|
function PassportStrategy(Strategy, name) {
|
|
20
|
-
class InnerStrategyAbstractClass extends
|
|
20
|
+
class InnerStrategyAbstractClass extends strategy_1.AbstractStrategyWrapper {
|
|
21
21
|
async init() {
|
|
22
22
|
const cb = async (...params) => {
|
|
23
23
|
const done = params[params.length - 1];
|
|
@@ -116,7 +116,13 @@ function PassportMiddleware(strategy) {
|
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
118
|
else {
|
|
119
|
-
|
|
119
|
+
try {
|
|
120
|
+
this.allFailed(options, authenticateResult.failResult, req, res);
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
next(err);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
120
126
|
}
|
|
121
127
|
next();
|
|
122
128
|
}.bind(this);
|
|
@@ -176,7 +182,14 @@ function PassportMiddleware(strategy) {
|
|
|
176
182
|
return;
|
|
177
183
|
}
|
|
178
184
|
else {
|
|
179
|
-
this.allFailed(options, authenticateResult.failResult, req,
|
|
185
|
+
this.allFailed(options, authenticateResult.failResult, req, {
|
|
186
|
+
end(data) {
|
|
187
|
+
ctx.body = data;
|
|
188
|
+
},
|
|
189
|
+
redirect(url) {
|
|
190
|
+
ctx.redirect(url);
|
|
191
|
+
},
|
|
192
|
+
});
|
|
180
193
|
return;
|
|
181
194
|
}
|
|
182
195
|
await next();
|
|
@@ -188,18 +201,19 @@ function PassportMiddleware(strategy) {
|
|
|
188
201
|
}
|
|
189
202
|
async onceSucceed(options, user, info, req, res) {
|
|
190
203
|
let msg;
|
|
191
|
-
if (options.successFlash) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
204
|
+
// if (options.successFlash) {
|
|
205
|
+
// let flash: any = options.successFlash;
|
|
206
|
+
// if (typeof flash === 'string') {
|
|
207
|
+
// flash = { type: 'success', message: flash };
|
|
208
|
+
// }
|
|
209
|
+
// flash.type = flash.type || 'success';
|
|
210
|
+
//
|
|
211
|
+
// const type = flash.type || info.type || 'success';
|
|
212
|
+
// msg = flash.message || info.message || info;
|
|
213
|
+
// if (typeof msg === 'string') {
|
|
214
|
+
// req.flash && req.flash(type, msg);
|
|
215
|
+
// }
|
|
216
|
+
// }
|
|
203
217
|
if (options.successMessage) {
|
|
204
218
|
msg = options.successMessage;
|
|
205
219
|
if (typeof msg === 'boolean') {
|
|
@@ -246,32 +260,30 @@ function PassportMiddleware(strategy) {
|
|
|
246
260
|
// Strategies are ordered by priority. For the purpose of flashing a
|
|
247
261
|
// message, the first failure will be displayed.
|
|
248
262
|
let failure = failResult.failures[0] || {}, challenge = (failure === null || failure === void 0 ? void 0 : failure.challenge) || {}, msg;
|
|
249
|
-
if (options.failureFlash) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
263
|
+
// if (options.failureFlash) {
|
|
264
|
+
// let flash: any = options.failureFlash;
|
|
265
|
+
// if (typeof flash === 'string') {
|
|
266
|
+
// flash = { type: 'error', message: flash };
|
|
267
|
+
// }
|
|
268
|
+
// flash.type = flash.type || 'error';
|
|
269
|
+
//
|
|
270
|
+
// const type = flash.type || challenge.type || 'error';
|
|
271
|
+
// msg = flash.message || challenge.message || challenge;
|
|
272
|
+
// if (typeof msg === 'string') {
|
|
273
|
+
// req.flash && req.flash(type, msg);
|
|
274
|
+
// }
|
|
275
|
+
// }
|
|
262
276
|
if (options.failureMessage) {
|
|
263
277
|
msg = options.failureMessage;
|
|
264
278
|
if (typeof msg === 'boolean') {
|
|
265
279
|
msg = challenge.message || challenge;
|
|
266
280
|
}
|
|
267
281
|
if (typeof msg === 'string') {
|
|
268
|
-
// TODO
|
|
269
282
|
req.session.messages = req.session.messages || [];
|
|
270
283
|
req.session.messages.push(msg);
|
|
271
284
|
}
|
|
272
285
|
}
|
|
273
286
|
if (options.failureRedirect) {
|
|
274
|
-
// TODO
|
|
275
287
|
return res.redirect(options.failureRedirect);
|
|
276
288
|
}
|
|
277
289
|
// When failure handling is not delegated to the application, the default
|
|
@@ -293,14 +305,12 @@ function PassportMiddleware(strategy) {
|
|
|
293
305
|
res.statusCode = rstatus || 401;
|
|
294
306
|
// eslint-disable-next-line eqeqeq
|
|
295
307
|
if (res.statusCode === 401 && rchallenge.length) {
|
|
296
|
-
// TODO
|
|
297
308
|
res.setHeader('WWW-Authenticate', rchallenge);
|
|
298
309
|
}
|
|
299
|
-
if (options.failWithError) {
|
|
300
|
-
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
res.end(http.STATUS_CODES[res.statusCode]);
|
|
310
|
+
// if (options.failWithError) {
|
|
311
|
+
// throw new httpError.UnauthorizedError();
|
|
312
|
+
// }
|
|
313
|
+
throw new core_1.httpError.UnauthorizedError();
|
|
304
314
|
}
|
|
305
315
|
attachRequestMethod(req) {
|
|
306
316
|
// init req method
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* pause
|
|
3
|
+
* Copyright(c) 2012 TJ Holowaychuk
|
|
4
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
/// <reference types="node" />
|
|
8
|
+
import { Stream } from 'stream';
|
|
9
|
+
/**
|
|
10
|
+
* Pause the data events on a stream.
|
|
11
|
+
*
|
|
12
|
+
* @param {object} stream
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export declare function pause(stream: Stream): {
|
|
16
|
+
end: () => void;
|
|
17
|
+
resume: () => void;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=pause.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* pause
|
|
4
|
+
* Copyright(c) 2012 TJ Holowaychuk
|
|
5
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
6
|
+
* MIT Licensed
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.pause = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* Pause the data events on a stream.
|
|
12
|
+
*
|
|
13
|
+
* @param {object} stream
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
function pause(stream) {
|
|
17
|
+
const events = [];
|
|
18
|
+
const onData = createEventListener('data', events);
|
|
19
|
+
const onEnd = createEventListener('end', events);
|
|
20
|
+
// buffer data
|
|
21
|
+
stream.on('data', onData);
|
|
22
|
+
// buffer end
|
|
23
|
+
stream.on('end', onEnd);
|
|
24
|
+
return {
|
|
25
|
+
end: function end() {
|
|
26
|
+
stream.removeListener('data', onData);
|
|
27
|
+
stream.removeListener('end', onEnd);
|
|
28
|
+
},
|
|
29
|
+
resume: function resume() {
|
|
30
|
+
this.end();
|
|
31
|
+
for (let i = 0; i < events.length; i++) {
|
|
32
|
+
// eslint-disable-next-line prefer-spread
|
|
33
|
+
stream.emit.apply(stream, events[i]);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
exports.pause = pause;
|
|
39
|
+
function createEventListener(name, events) {
|
|
40
|
+
return function onEvent() {
|
|
41
|
+
const args = new Array(arguments.length + 1);
|
|
42
|
+
args[0] = name;
|
|
43
|
+
for (let i = 0; i < arguments.length; i++) {
|
|
44
|
+
// eslint-disable-next-line prefer-rest-params
|
|
45
|
+
args[i + 1] = arguments[i];
|
|
46
|
+
}
|
|
47
|
+
events.push(args);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=pause.js.map
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SessionStrategy = void 0;
|
|
4
4
|
const strategy_1 = require("./strategy");
|
|
5
5
|
const core_1 = require("@midwayjs/core");
|
|
6
|
-
const
|
|
6
|
+
const pause_1 = require("./pause");
|
|
7
7
|
/**
|
|
8
8
|
* `SessionStrategy` constructor.
|
|
9
9
|
*
|
|
@@ -42,7 +42,7 @@ class SessionStrategy extends strategy_1.Strategy {
|
|
|
42
42
|
// NOTE: Stream pausing is desirable in the case where later middleware is
|
|
43
43
|
// listening for events emitted from request. For discussion on the
|
|
44
44
|
// matter, refer to: https://github.com/jaredhanson/passport/pull/106
|
|
45
|
-
const paused = options.pauseStream ? pause(req) : null;
|
|
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
|
return new core_1.httpError.UnauthorizedError(err.message);
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IncomingMessage } from 'http';
|
|
3
|
-
import { StrategyCreatedStatic } from '../interface';
|
|
3
|
+
import { IPassportStrategy, StrategyCreatedStatic } from '../interface';
|
|
4
4
|
export declare abstract class Strategy {
|
|
5
5
|
name?: string | undefined;
|
|
6
6
|
abstract authenticate(req: IncomingMessage, options?: any): any;
|
|
7
7
|
}
|
|
8
8
|
export interface Strategy extends StrategyCreatedStatic {
|
|
9
9
|
}
|
|
10
|
+
export declare abstract class AbstractStrategyWrapper implements IPassportStrategy {
|
|
11
|
+
abstract validate(...args: any[]): any;
|
|
12
|
+
abstract getStrategyOptions(): any;
|
|
13
|
+
}
|
|
10
14
|
//# sourceMappingURL=strategy.d.ts.map
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Strategy = void 0;
|
|
3
|
+
exports.AbstractStrategyWrapper = exports.Strategy = void 0;
|
|
4
4
|
class Strategy {
|
|
5
5
|
}
|
|
6
6
|
exports.Strategy = Strategy;
|
|
7
|
+
class AbstractStrategyWrapper {
|
|
8
|
+
}
|
|
9
|
+
exports.AbstractStrategyWrapper = AbstractStrategyWrapper;
|
|
7
10
|
//# sourceMappingURL=strategy.js.map
|
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.0-beta.
|
|
4
|
+
"version": "3.4.0-beta.12",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -22,21 +22,18 @@
|
|
|
22
22
|
"author": "Nawbc",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@midwayjs/core": "^3.4.0-beta.
|
|
26
|
-
"@midwayjs/decorator": "^3.4.0-beta.
|
|
27
|
-
"@midwayjs/express": "^3.4.0-beta.
|
|
28
|
-
"@midwayjs/jwt": "^3.4.0-beta.
|
|
29
|
-
"@midwayjs/koa": "^3.4.0-beta.
|
|
30
|
-
"@midwayjs/mock": "^3.4.0-beta.
|
|
31
|
-
"@midwayjs/web": "^3.4.0-beta.
|
|
25
|
+
"@midwayjs/core": "^3.4.0-beta.12",
|
|
26
|
+
"@midwayjs/decorator": "^3.4.0-beta.12",
|
|
27
|
+
"@midwayjs/express": "^3.4.0-beta.12",
|
|
28
|
+
"@midwayjs/jwt": "^3.4.0-beta.12",
|
|
29
|
+
"@midwayjs/koa": "^3.4.0-beta.12",
|
|
30
|
+
"@midwayjs/mock": "^3.4.0-beta.12",
|
|
31
|
+
"@midwayjs/web": "^3.4.0-beta.12",
|
|
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
|
-
"
|
|
39
|
-
"pause": "0.0.1"
|
|
40
|
-
},
|
|
41
|
-
"gitHead": "b1c7a439b0df37d3e381cd182ea3b9e74323107b"
|
|
38
|
+
"gitHead": "cb639763ececfc7928221eaafbd515bfd93c6ca1"
|
|
42
39
|
}
|