@magda/authentication-plugin-sdk 0.0.60-alpha.9 → 0.0.60-dt.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/README.md +41 -26
- package/dist/index.d.ts +162 -122
- package/dist/index.js +44626 -158
- package/package.json +4 -4
- package/dist/createPool.js +0 -35
- package/dist/createPool.js.map +0 -1
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -15,9 +15,24 @@ You can use [this repo](https://github.com/magda-io/magda-auth-template) as [a t
|
|
|
15
15
|
* @returns {Router}
|
|
16
16
|
*/
|
|
17
17
|
export declare function createMagdaSessionRouter(
|
|
18
|
-
|
|
18
|
+
options: MagdaSessionRouterOptions
|
|
19
19
|
): Router;
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Complete destroy Magda session and remove session cookie from the user agent
|
|
23
|
+
*
|
|
24
|
+
* @export
|
|
25
|
+
* @param {Request} req
|
|
26
|
+
* @param {Response} res
|
|
27
|
+
* @param {SessionCookieOptions} cookieOptions
|
|
28
|
+
* @return {*} {Promise<void>}
|
|
29
|
+
*/
|
|
30
|
+
export declare async function destroyMagdaSession(
|
|
31
|
+
req: Request,
|
|
32
|
+
res: Response,
|
|
33
|
+
cookieOptions: SessionCookieOptions
|
|
34
|
+
): Promise<void>;
|
|
35
|
+
|
|
21
36
|
/**
|
|
22
37
|
* Verify the user using the user profile received during the authentication.
|
|
23
38
|
* If a user can be located, return UserToken type data.
|
|
@@ -50,19 +65,19 @@ export declare function createMagdaSessionRouter(
|
|
|
50
65
|
* @returns {Promise<UserToken>}
|
|
51
66
|
*/
|
|
52
67
|
export declare function createOrGetUserToken(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
authApi: AuthApiClient,
|
|
69
|
+
profile: passport.Profile,
|
|
70
|
+
source: string,
|
|
71
|
+
beforeUserCreated?: (
|
|
72
|
+
authApiClient: AuthApiClient,
|
|
73
|
+
userData: User,
|
|
74
|
+
profile: passport.Profile
|
|
75
|
+
) => Promise<User>,
|
|
76
|
+
afterUserCreated?: (
|
|
77
|
+
authApiClient: AuthApiClient,
|
|
78
|
+
user: User,
|
|
79
|
+
profile: passport.Profile
|
|
80
|
+
) => Promise<void>
|
|
66
81
|
): Promise<UserToken>;
|
|
67
82
|
|
|
68
83
|
/**
|
|
@@ -75,23 +90,23 @@ export declare function createOrGetUserToken(
|
|
|
75
90
|
* @returns
|
|
76
91
|
*/
|
|
77
92
|
export declare function getAbsoluteUrl(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
93
|
+
url: string,
|
|
94
|
+
baseUrl: string,
|
|
95
|
+
optionalQueries?: {
|
|
96
|
+
[key: string]: string;
|
|
97
|
+
}
|
|
83
98
|
): string;
|
|
84
99
|
|
|
85
100
|
export declare function redirectOnSuccess(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
101
|
+
toURL: string,
|
|
102
|
+
req: Request,
|
|
103
|
+
res: Response
|
|
89
104
|
): void;
|
|
90
105
|
|
|
91
106
|
export declare function redirectOnError(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
107
|
+
err: any,
|
|
108
|
+
toURL: string,
|
|
109
|
+
req: Request,
|
|
110
|
+
res: Response
|
|
96
111
|
): void;
|
|
97
112
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,122 +1,162 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import passport from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* @
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
1
|
+
import AuthApiClient from '@magda/auth-api-client';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import passport from 'passport';
|
|
4
|
+
import { Request as Request_2 } from 'express';
|
|
5
|
+
import { Response as Response_2 } from 'express';
|
|
6
|
+
import { Router } from 'express';
|
|
7
|
+
import { User } from '@magda/auth-api-client';
|
|
8
|
+
import { UserToken } from '@magda/auth-api-client';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Different type of AuthenticationMethod:
|
|
12
|
+
* - IDP-URI-REDIRECTION: the plugin will rediredct user agent to idp (identity provider) for authentication. e.g. Google & fackebook oauth etc.
|
|
13
|
+
* - This is the default method.
|
|
14
|
+
* - PASSWORD: the plugin expect frontend do a form post that contains username & password to the plugin for authentication
|
|
15
|
+
* - QR-CODE: the plugin offers a url that is used by the frontend to request auth challenge data. The data will be encoded into a QR-code image and expect the user scan the QR code with a mobile app to complete the authentication request.
|
|
16
|
+
* - Once the QR-code image is generated, the frontend is expected to start polling a pre-defined plugin url to check whether the authentication is complete or not.
|
|
17
|
+
*/
|
|
18
|
+
export declare type AuthenticationMethod = "IDP-URI-REDIRECTION" | "PASSWORD" | "QR-CODE";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Basic Auth Plugin are the config info that supplied to Gateway
|
|
22
|
+
* via [authPlugins](https://github.com/magda-io/magda/tree/master/deploy/helm/internal-charts/gateway) helm chart config
|
|
23
|
+
*/
|
|
24
|
+
export declare type AuthPluginBasicConfig = {
|
|
25
|
+
key: string;
|
|
26
|
+
baseUrl: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export declare interface AuthPluginConfig extends Omit<AuthPluginBasicConfig, "baseUrl"> {
|
|
30
|
+
name: string;
|
|
31
|
+
iconUrl: string;
|
|
32
|
+
authenticationMethod: AuthenticationMethod;
|
|
33
|
+
loginFormExtraInfoHeading?: string;
|
|
34
|
+
loginFormExtraInfoContent?: string;
|
|
35
|
+
loginFormUsernameFieldLabel?: string;
|
|
36
|
+
loginFormPasswordFieldLabel?: string;
|
|
37
|
+
qrCodeImgDataRequestUrl?: string;
|
|
38
|
+
qrCodeAuthResultPollUrl?: string;
|
|
39
|
+
qrCodeExtraInfoHeading?: string;
|
|
40
|
+
qrCodeExtraInfoContent?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export declare type CookieOptions = CookieOptions_2;
|
|
44
|
+
|
|
45
|
+
/** This is present in the express-session types but not actually exported properly, so it needs to be copy-pasted here */
|
|
46
|
+
declare type CookieOptions_2 = {
|
|
47
|
+
maxAge?: number;
|
|
48
|
+
signed?: boolean;
|
|
49
|
+
expires?: Date;
|
|
50
|
+
httpOnly?: boolean;
|
|
51
|
+
path?: string;
|
|
52
|
+
domain?: string;
|
|
53
|
+
secure?: boolean | "auto";
|
|
54
|
+
encode?: (val: string) => string;
|
|
55
|
+
sameSite?: boolean | "lax" | "strict" | "none";
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Create an express router that can be used to enable session on an express application.
|
|
60
|
+
*
|
|
61
|
+
* @export
|
|
62
|
+
* @param {MagdaSessionRouterOptions} options
|
|
63
|
+
* @returns {Router}
|
|
64
|
+
*/
|
|
65
|
+
export declare function createMagdaSessionRouter(options: MagdaSessionRouterOptions): Router;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Verify the user using the user profile received during the authentication.
|
|
69
|
+
* If a user can be located, return UserToken type data.
|
|
70
|
+
* Otherwise, create a new user and return UserToken type data .
|
|
71
|
+
*
|
|
72
|
+
* @export
|
|
73
|
+
* @param {AuthApiClient} authApi
|
|
74
|
+
* @param {passport.Profile} profile
|
|
75
|
+
* @param {string} source
|
|
76
|
+
* @param {(
|
|
77
|
+
* authApiClient: AuthApiClient,
|
|
78
|
+
* userData: User,
|
|
79
|
+
* profile: passport.Profile
|
|
80
|
+
* ) => Promise<User>} [beforeUserCreated] an optional handler that will be called just before a user is created.
|
|
81
|
+
* The user data returned by this handler will be used to create the user record. The following parameters will be provided to the handler:
|
|
82
|
+
* - authApiClient: Auth API Client. You can use it to add a role to the user.
|
|
83
|
+
* - userData: the user data that is converted from the user profile received using the default conversion logic.
|
|
84
|
+
* - profile: the user profile received
|
|
85
|
+
*
|
|
86
|
+
* @param {(
|
|
87
|
+
* authApiClient: AuthApiClient,
|
|
88
|
+
* user: User,
|
|
89
|
+
* profile: passport.Profile
|
|
90
|
+
* ) => Promise<void>} [afterUserCreated] an optional call that will be called when a user has just been created.
|
|
91
|
+
* The following parameters will be provided to the handler:
|
|
92
|
+
* - authApiClient: Auth API Client. You can use it to add a role to the user.
|
|
93
|
+
* - user: the user data of the magda user that is just created.
|
|
94
|
+
* - profile: the user profile received
|
|
95
|
+
*
|
|
96
|
+
* @returns {Promise<UserToken>}
|
|
97
|
+
*/
|
|
98
|
+
export declare function createOrGetUserToken(authApi: AuthApiClient, profile: passport.Profile, source: string, beforeUserCreated?: (authApiClient: AuthApiClient, userData: User, profile: passport.Profile) => Promise<User>, afterUserCreated?: (authApiClient: AuthApiClient, user: User, profile: passport.Profile) => Promise<void>): Promise<UserToken>;
|
|
99
|
+
|
|
100
|
+
export declare const DEFAULT_SESSION_COOKIE_NAME: string;
|
|
101
|
+
|
|
102
|
+
export declare const DEFAULT_SESSION_COOKIE_OPTIONS: CookieOptions_2;
|
|
103
|
+
|
|
104
|
+
export declare const deleteCookie: typeof deleteCookie_2;
|
|
105
|
+
|
|
106
|
+
declare function deleteCookie_2(cookieName: string, cookieOptions: CookieOptions_2, res: express.Response): void;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Complete destroy Magda session and remove session cookie from the user agent
|
|
110
|
+
*
|
|
111
|
+
* @export
|
|
112
|
+
* @param {Request} req
|
|
113
|
+
* @param {Response} res
|
|
114
|
+
* @param {SessionCookieOptions} cookieOptions
|
|
115
|
+
* @return {*} {Promise<void>}
|
|
116
|
+
*/
|
|
117
|
+
export declare function destroyMagdaSession(req: Request_2, res: Response_2, cookieOptions: SessionCookieOptions): Promise<void>;
|
|
118
|
+
|
|
119
|
+
export declare const destroySession: typeof destroySession_2;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* destroy the session.
|
|
123
|
+
* - will delete the session data from session store only.
|
|
124
|
+
* - will not delete session cookie (Call deleteCookie method for deleting cookie)
|
|
125
|
+
* @export
|
|
126
|
+
* @param {express.Request} req
|
|
127
|
+
* @return {*} {Promise<void>}
|
|
128
|
+
*/
|
|
129
|
+
declare function destroySession_2(req: express.Request): Promise<void>;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Join `url` with `baseUrl` if `url` is not an absolute url
|
|
133
|
+
*
|
|
134
|
+
* @export
|
|
135
|
+
* @param {string} url
|
|
136
|
+
* @param {string} baseUrl
|
|
137
|
+
* @param {{ [key: string]: string }} [optionalQueries]
|
|
138
|
+
* @returns
|
|
139
|
+
*/
|
|
140
|
+
export declare function getAbsoluteUrl(url: string, baseUrl: string, optionalQueries?: {
|
|
141
|
+
[key: string]: string;
|
|
142
|
+
}): string;
|
|
143
|
+
|
|
144
|
+
export declare function getSessionId(req: express.Request, secret?: string): string;
|
|
145
|
+
|
|
146
|
+
export declare type MagdaSessionRouterOptions = {
|
|
147
|
+
cookieOptions: SessionCookieOptions;
|
|
148
|
+
sessionSecret: string;
|
|
149
|
+
sessionDBHost: string;
|
|
150
|
+
sessionDBPort: number;
|
|
151
|
+
sessionDBUser?: string;
|
|
152
|
+
sessionDBPassword?: string;
|
|
153
|
+
sessionDBName?: string;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export declare function redirectOnError(err: any, toURL: string, req: Request_2, res: Response_2): void;
|
|
157
|
+
|
|
158
|
+
export declare function redirectOnSuccess(toURL: string, req: Request_2, res: Response_2): void;
|
|
159
|
+
|
|
160
|
+
export declare type SessionCookieOptions = CookieOptions_2;
|
|
161
|
+
|
|
162
|
+
export { }
|