@midwayjs/passport 3.4.0-beta.9 → 3.4.3
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/config/config.default.d.ts +2 -0
- package/dist/config/config.default.js +2 -0
- package/dist/configuration.js +2 -11
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/interface.d.ts +62 -8
- package/dist/interface.js +1 -4
- package/dist/passport/authenticator.d.ts +128 -0
- package/dist/passport/authenticator.js +439 -0
- package/dist/passport/passport.service.d.ts +6 -0
- package/dist/passport/passport.service.js +417 -0
- package/dist/passport/pause.d.ts +19 -0
- package/dist/passport/pause.js +50 -0
- package/dist/passport/request.d.ts +2 -0
- package/dist/{proxy/framework → passport}/request.js +17 -25
- package/dist/passport/session.stratey.d.ts +34 -0
- package/dist/passport/session.stratey.js +68 -0
- package/dist/passport/strategy.d.ts +14 -0
- package/dist/passport/strategy.js +10 -0
- package/index.d.ts +2 -2
- package/package.json +11 -15
- package/dist/proxy/framework/koa.d.ts +0 -39
- package/dist/proxy/framework/koa.js +0 -190
- package/dist/proxy/framework/request.d.ts +0 -11
- package/dist/proxy/index.d.ts +0 -7
- package/dist/proxy/index.js +0 -21
- package/dist/service/passport.service.d.ts +0 -6
- package/dist/service/passport.service.js +0 -226
- package/dist/util.d.ts +0 -3
- package/dist/util.js +0 -16
package/dist/configuration.js
CHANGED
|
@@ -12,20 +12,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.PassportConfiguration = void 0;
|
|
13
13
|
const decorator_1 = require("@midwayjs/decorator");
|
|
14
14
|
const DefaultConfig = require("./config/config.default");
|
|
15
|
-
const util_1 = require("./util");
|
|
16
15
|
const core_1 = require("@midwayjs/core");
|
|
16
|
+
const authenticator_1 = require("./passport/authenticator");
|
|
17
17
|
let PassportConfiguration = class PassportConfiguration {
|
|
18
18
|
async onReady(container) {
|
|
19
|
-
|
|
20
|
-
const passport = (0, util_1.getPassport)();
|
|
21
|
-
this.applicationManager
|
|
22
|
-
.getApplications(['express', 'koa', 'egg', 'faas'])
|
|
23
|
-
.forEach(app => {
|
|
24
|
-
app.useMiddleware(passport.initialize());
|
|
25
|
-
if (passportConfig.session) {
|
|
26
|
-
app.useMiddleware(passport.session());
|
|
27
|
-
}
|
|
28
|
-
});
|
|
19
|
+
await container.getAsync(authenticator_1.PassportAuthenticator);
|
|
29
20
|
}
|
|
30
21
|
};
|
|
31
22
|
__decorate([
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { PassportConfiguration as Configuration } from './configuration';
|
|
2
2
|
export * from './decorator/strategy';
|
|
3
|
-
export * from './
|
|
3
|
+
export * from './passport/authenticator';
|
|
4
|
+
export * from './passport/passport.service';
|
|
5
|
+
export * from './interface';
|
|
4
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -18,5 +18,7 @@ exports.Configuration = void 0;
|
|
|
18
18
|
var configuration_1 = require("./configuration");
|
|
19
19
|
Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.PassportConfiguration; } });
|
|
20
20
|
__exportStar(require("./decorator/strategy"), exports);
|
|
21
|
-
__exportStar(require("./
|
|
21
|
+
__exportStar(require("./passport/authenticator"), exports);
|
|
22
|
+
__exportStar(require("./passport/passport.service"), exports);
|
|
23
|
+
__exportStar(require("./interface"), exports);
|
|
22
24
|
//# sourceMappingURL=index.js.map
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
|
-
import * as passport from 'passport';
|
|
2
1
|
import { IMiddleware } from '@midwayjs/core';
|
|
2
|
+
export interface AuthenticateOptions {
|
|
3
|
+
authInfo?: boolean | undefined;
|
|
4
|
+
assignProperty?: string | undefined;
|
|
5
|
+
failureMessage?: boolean | string | undefined;
|
|
6
|
+
failureRedirect?: string | undefined;
|
|
7
|
+
session?: boolean | undefined;
|
|
8
|
+
scope?: string | string[] | undefined;
|
|
9
|
+
successMessage?: boolean | string | undefined;
|
|
10
|
+
successRedirect?: string | undefined;
|
|
11
|
+
successReturnToOrRedirect?: string | undefined;
|
|
12
|
+
state?: string | undefined;
|
|
13
|
+
pauseStream?: boolean | undefined;
|
|
14
|
+
userProperty?: string | undefined;
|
|
15
|
+
passReqToCallback?: boolean | undefined;
|
|
16
|
+
prompt?: string | undefined;
|
|
17
|
+
}
|
|
3
18
|
export interface IPassportStrategy {
|
|
4
19
|
validate(...args: any[]): any;
|
|
5
20
|
getStrategyOptions(): any;
|
|
@@ -7,16 +22,55 @@ export interface IPassportStrategy {
|
|
|
7
22
|
deserializeUser?(id: any, done: (err: any, user?: any) => void): void;
|
|
8
23
|
transformAuthInfo?(info: any, done: (err: any, info: any) => void): void;
|
|
9
24
|
}
|
|
10
|
-
export declare abstract class AbstractStrategy implements IPassportStrategy {
|
|
11
|
-
abstract validate(...args: any[]): any;
|
|
12
|
-
abstract getStrategyOptions(): any;
|
|
13
|
-
}
|
|
14
25
|
export interface IPassportMiddleware extends IMiddleware<any, any> {
|
|
15
|
-
authenticate?(options:
|
|
26
|
+
authenticate?(options: AuthenticateOptions, callback: Function): any;
|
|
16
27
|
}
|
|
17
28
|
export declare abstract class AbstractPassportMiddleware implements Pick<IPassportMiddleware, 'authenticate'> {
|
|
18
|
-
abstract getAuthenticateOptions(): Promise<
|
|
19
|
-
authenticate?(options:
|
|
29
|
+
abstract getAuthenticateOptions(): Promise<AuthenticateOptions> | AuthenticateOptions;
|
|
30
|
+
authenticate?(options: AuthenticateOptions, callback?: Function): any;
|
|
20
31
|
resolve(): any;
|
|
21
32
|
}
|
|
33
|
+
export interface StrategyCreatedStatic {
|
|
34
|
+
/**
|
|
35
|
+
* Authenticate `user`, with optional `info`.
|
|
36
|
+
*
|
|
37
|
+
* Strategies should call this function to successfully authenticate a
|
|
38
|
+
* user. `user` should be an object supplied by the application after it
|
|
39
|
+
* has been given an opportunity to verify credentials. `info` is an
|
|
40
|
+
* optional argument containing additional user information. This is
|
|
41
|
+
* useful for third-party authentication strategies to pass profile
|
|
42
|
+
* details.
|
|
43
|
+
*/
|
|
44
|
+
success(user: any, info?: Record<string, any>): void;
|
|
45
|
+
/**
|
|
46
|
+
* Fail authentication, with optional `challenge` and `status`, defaulting
|
|
47
|
+
* to 401.
|
|
48
|
+
*
|
|
49
|
+
* Strategies should call this function to fail an authentication attempt.
|
|
50
|
+
*/
|
|
51
|
+
fail(challenge?: string | number, status?: number): void;
|
|
52
|
+
/**
|
|
53
|
+
* Redirect to `url` with optional `status`, defaulting to 302.
|
|
54
|
+
*
|
|
55
|
+
* Strategies should call this function to redirect the user (via their
|
|
56
|
+
* user agent) to a third-party website for authentication.
|
|
57
|
+
*/
|
|
58
|
+
redirect(url: string, status?: number): void;
|
|
59
|
+
/**
|
|
60
|
+
* Pass without making a success or fail decision.
|
|
61
|
+
*
|
|
62
|
+
* Under most circumstances, Strategies should not need to call this
|
|
63
|
+
* function. It exists primarily to allow previous authentication state
|
|
64
|
+
* to be restored, for example from an HTTP session.
|
|
65
|
+
*/
|
|
66
|
+
pass(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Internal error while performing authentication.
|
|
69
|
+
*
|
|
70
|
+
* Strategies should call this function when an internal error occurs
|
|
71
|
+
* during the process of performing authentication; for example, if the
|
|
72
|
+
* user directory is not available.
|
|
73
|
+
*/
|
|
74
|
+
error(err: any): void;
|
|
75
|
+
}
|
|
22
76
|
//# sourceMappingURL=interface.d.ts.map
|
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
|
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AuthenticateOptions } from '../interface';
|
|
3
|
+
import { Strategy } from './strategy';
|
|
4
|
+
import { IMidwayContainer } from '@midwayjs/core';
|
|
5
|
+
import { IncomingMessage } from 'http';
|
|
6
|
+
export declare class PassportAuthenticator {
|
|
7
|
+
private strategies;
|
|
8
|
+
private userProperty;
|
|
9
|
+
private sessionUserProperty;
|
|
10
|
+
_key: string;
|
|
11
|
+
_serializers: any[];
|
|
12
|
+
_deserializers: any[];
|
|
13
|
+
_infoTransformers: any[];
|
|
14
|
+
applicationContext: IMidwayContainer;
|
|
15
|
+
passportConfig: any;
|
|
16
|
+
protected init(): void;
|
|
17
|
+
isExpressMode(): boolean;
|
|
18
|
+
isEnableSession(): boolean;
|
|
19
|
+
getUserProperty(): string;
|
|
20
|
+
getSessionUserProperty(): string;
|
|
21
|
+
use(name: string | Strategy, strategy?: Strategy): this;
|
|
22
|
+
unuse(name: string): this;
|
|
23
|
+
/**
|
|
24
|
+
* Authenticates requests.
|
|
25
|
+
*
|
|
26
|
+
* Applies the `name`ed strategy (or strategies) to the incoming request, in
|
|
27
|
+
* order to authenticate the request. If authentication is successful, the user
|
|
28
|
+
* will be logged in and populated at `req.user` and a session will be
|
|
29
|
+
* established by default. If authentication fails, an unauthorized response
|
|
30
|
+
* will be sent.
|
|
31
|
+
*
|
|
32
|
+
* Options:
|
|
33
|
+
* - `session` Save login state in session, defaults to _true_
|
|
34
|
+
* - `successRedirect` After successful login, redirect to given URL
|
|
35
|
+
* - `successMessage` True to store success message in
|
|
36
|
+
* req.session.messages, or a string to use as override
|
|
37
|
+
* message for success.
|
|
38
|
+
* - `successFlash` True to flash success messages or a string to use as a flash
|
|
39
|
+
* message for success (overrides any from the strategy itself).
|
|
40
|
+
* - `failureRedirect` After failed login, redirect to given URL
|
|
41
|
+
* - `failureMessage` True to store failure message in
|
|
42
|
+
* req.session.messages, or a string to use as override
|
|
43
|
+
* message for failure.
|
|
44
|
+
* - `failureFlash` True to flash failure messages or a string to use as a flash
|
|
45
|
+
* message for failures (overrides any from the strategy itself).
|
|
46
|
+
* - `assignProperty` Assign the object provided by the verify callback to given property
|
|
47
|
+
*/
|
|
48
|
+
authenticate(strategies: Strategy[], options?: AuthenticateOptions): (req: any) => Promise<{
|
|
49
|
+
successResult?: {
|
|
50
|
+
user: any;
|
|
51
|
+
info: any;
|
|
52
|
+
} | undefined;
|
|
53
|
+
redirectResult?: {
|
|
54
|
+
url: string;
|
|
55
|
+
status: number;
|
|
56
|
+
} | undefined;
|
|
57
|
+
failResult?: {
|
|
58
|
+
failures: Array<{
|
|
59
|
+
challenge: string;
|
|
60
|
+
status: number;
|
|
61
|
+
}>;
|
|
62
|
+
};
|
|
63
|
+
}>;
|
|
64
|
+
serializeUser(user: any, req: any, done: any): void;
|
|
65
|
+
/**
|
|
66
|
+
* Registers a function used to deserialize user objects out of the session.
|
|
67
|
+
*
|
|
68
|
+
* Examples:
|
|
69
|
+
*
|
|
70
|
+
* passport.deserializeUser(function(id, done) {
|
|
71
|
+
* User.findById(id, function (err, user) {
|
|
72
|
+
* done(err, user);
|
|
73
|
+
* });
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* @api public
|
|
77
|
+
*/
|
|
78
|
+
deserializeUser(obj: any, req: any, done: any): void;
|
|
79
|
+
/**
|
|
80
|
+
* Registers a function used to transform auth info.
|
|
81
|
+
*
|
|
82
|
+
* In some circumstances authorization details are contained in authentication
|
|
83
|
+
* credentials or loaded as part of verification.
|
|
84
|
+
*
|
|
85
|
+
* For example, when using bearer tokens for API authentication, the tokens may
|
|
86
|
+
* encode (either directly or indirectly in a database), details such as scope
|
|
87
|
+
* of access or the client to which the token was issued.
|
|
88
|
+
*
|
|
89
|
+
* Such authorization details should be enforced separately from authentication.
|
|
90
|
+
* Because Passport deals only with the latter, this is the responsiblity of
|
|
91
|
+
* middleware or routes further along the chain. However, it is not optimal to
|
|
92
|
+
* decode the same data or execute the same database query later. To avoid
|
|
93
|
+
* this, Passport accepts optional `info` along with the authenticated `user`
|
|
94
|
+
* in a strategy's `success()` action. This info is set at `req.authInfo`,
|
|
95
|
+
* where said later middlware or routes can access it.
|
|
96
|
+
*
|
|
97
|
+
* Optionally, applications can register transforms to proccess this info,
|
|
98
|
+
* which take effect prior to `req.authInfo` being set. This is useful, for
|
|
99
|
+
* example, when the info contains a client ID. The transform can load the
|
|
100
|
+
* client from the database and include the instance in the transformed info,
|
|
101
|
+
* allowing the full set of client properties to be convieniently accessed.
|
|
102
|
+
*
|
|
103
|
+
* If no transforms are registered, `info` supplied by the strategy will be left
|
|
104
|
+
* unmodified.
|
|
105
|
+
*
|
|
106
|
+
* Examples:
|
|
107
|
+
*
|
|
108
|
+
* passport.transformAuthInfo(function(info, done) {
|
|
109
|
+
* Client.findById(info.clientID, function (err, client) {
|
|
110
|
+
* info.client = client;
|
|
111
|
+
* done(err, info);
|
|
112
|
+
* });
|
|
113
|
+
* });
|
|
114
|
+
*
|
|
115
|
+
* @api public
|
|
116
|
+
*/
|
|
117
|
+
transformAuthInfo(info: any, req: any, done: any): void;
|
|
118
|
+
logInToSession(req: IncomingMessage & {
|
|
119
|
+
session: any;
|
|
120
|
+
}, user: any): Promise<void>;
|
|
121
|
+
logOutFromSession(req: any, options?: {
|
|
122
|
+
keepSessionInfo?: boolean;
|
|
123
|
+
}): Promise<void>;
|
|
124
|
+
addSerializer(fn: any): void;
|
|
125
|
+
addDeserializer(fn: any): void;
|
|
126
|
+
addInfoTransformer(fn: any): void;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=authenticator.d.ts.map
|