@magda/authentication-plugin-sdk 0.0.60-alpha.7 → 0.0.60-dt.1

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 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
- options: MagdaSessionRouterOptions
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
- authApi: AuthApiClient,
54
- profile: passport.Profile,
55
- source: string,
56
- beforeUserCreated?: (
57
- authApiClient: AuthApiClient,
58
- userData: User,
59
- profile: passport.Profile
60
- ) => Promise<User>,
61
- afterUserCreated?: (
62
- authApiClient: AuthApiClient,
63
- user: User,
64
- profile: passport.Profile
65
- ) => Promise<void>
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
- url: string,
79
- baseUrl: string,
80
- optionalQueries?: {
81
- [key: string]: string;
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
- toURL: string,
87
- req: Request,
88
- res: Response
101
+ toURL: string,
102
+ req: Request,
103
+ res: Response
89
104
  ): void;
90
105
 
91
106
  export declare function redirectOnError(
92
- err: any,
93
- toURL: string,
94
- req: Request,
95
- res: Response
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 { Router, Request, Response } from "express";
2
- import AuthApiClient, { User, UserToken } from "@magda/auth-api-client";
3
- import passport from "passport";
4
- declare global {
5
- namespace Express {
6
- /**
7
- * This defines magda session data type.
8
- * the default session data type is `UserToken` (i.e. only user id field is available and is a compulsory field)
9
- * But any auth plugin provider could choose to customise the session by adding more fields (e.g. `arcgis`).
10
- * We also make sure it allows extra fields here.
11
- */
12
- interface User extends UserToken {
13
- [key: string]: any;
14
- }
15
- }
16
- }
17
- export declare type MagdaSessionRouterOptions = {
18
- cookieOptions: SessionCookieOptions;
19
- sessionSecret: string;
20
- sessionDBHost: string;
21
- sessionDBPort: number;
22
- sessionDBUser?: string;
23
- sessionDBPassword?: string;
24
- sessionDBName?: string;
25
- };
26
- export declare type SessionCookieOptions = {
27
- maxAge?: number;
28
- signed?: boolean;
29
- expires?: Date;
30
- httpOnly?: boolean;
31
- path?: string;
32
- domain?: string;
33
- secure?: boolean | "auto";
34
- encode?: (val: string) => string;
35
- sameSite?: boolean | "lax" | "strict" | "none";
36
- };
37
- export declare const DEFAULT_SESSION_COOKIE_NAME: string;
38
- export declare let DEFAULT_SESSION_COOKIE_OPTIONS: SessionCookieOptions;
39
- /**
40
- * Create an express router that can be used to enable session on an express application.
41
- *
42
- * @export
43
- * @param {MagdaSessionRouterOptions} options
44
- * @returns {Router}
45
- */
46
- export declare function createMagdaSessionRouter(options: MagdaSessionRouterOptions): Router;
47
- /**
48
- * Different type of AuthenticationMethod:
49
- * - IDP-URI-REDIRECTION: the plugin will rediredct user agent to idp (identity provider) for authentication. e.g. Google & fackebook oauth etc.
50
- * - This is the default method.
51
- * - PASSWORD: the plugin expect frontend do a form post that contains username & password to the plugin for authentication
52
- * - 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.
53
- * - 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.
54
- */
55
- export declare type AuthenticationMethod = "IDP-URI-REDIRECTION" | "PASSWORD" | "QR-CODE";
56
- export interface AuthPluginConfig extends Omit<AuthPluginBasicConfig, "baseUrl"> {
57
- name: string;
58
- iconUrl: string;
59
- authenticationMethod: AuthenticationMethod;
60
- loginFormExtraInfoHeading?: string;
61
- loginFormExtraInfoContent?: string;
62
- loginFormUsernameFieldLabel?: string;
63
- loginFormPasswordFieldLabel?: string;
64
- qrCodeImgDataRequestUrl?: string;
65
- qrCodeAuthResultPollUrl?: string;
66
- qrCodeExtraInfoHeading?: string;
67
- qrCodeExtraInfoContent?: string;
68
- }
69
- /**
70
- * Basic Auth Plugin are the config info that supplied to Gateway
71
- * via [authPlugins](https://github.com/magda-io/magda/tree/master/deploy/helm/internal-charts/gateway) helm chart config
72
- */
73
- export declare type AuthPluginBasicConfig = {
74
- key: string;
75
- baseUrl: string;
76
- };
77
- /**
78
- * Join `url` with `baseUrl` if `url` is not an absolute url
79
- *
80
- * @export
81
- * @param {string} url
82
- * @param {string} baseUrl
83
- * @param {{ [key: string]: string }} [optionalQueries]
84
- * @returns
85
- */
86
- export declare function getAbsoluteUrl(url: string, baseUrl: string, optionalQueries?: {
87
- [key: string]: string;
88
- }): string;
89
- export declare function redirectOnSuccess(toURL: string, req: Request, res: Response): void;
90
- export declare function redirectOnError(err: any, toURL: string, req: Request, res: Response): void;
91
- /**
92
- * Verify the user using the user profile received during the authentication.
93
- * If a user can be located, return UserToken type data.
94
- * Otherwise, create a new user and return UserToken type data .
95
- *
96
- * @export
97
- * @param {AuthApiClient} authApi
98
- * @param {passport.Profile} profile
99
- * @param {string} source
100
- * @param {(
101
- * authApiClient: AuthApiClient,
102
- * userData: User,
103
- * profile: passport.Profile
104
- * ) => Promise<User>} [beforeUserCreated] an optional handler that will be called just before a user is created.
105
- * The user data returned by this handler will be used to create the user record. The following parameters will be provided to the handler:
106
- * - authApiClient: Auth API Client. You can use it to add a role to the user.
107
- * - userData: the user data that is converted from the user profile received using the default conversion logic.
108
- * - profile: the user profile received
109
- *
110
- * @param {(
111
- * authApiClient: AuthApiClient,
112
- * user: User,
113
- * profile: passport.Profile
114
- * ) => Promise<void>} [afterUserCreated] an optional call that will be called when a user has just been created.
115
- * The following parameters will be provided to the handler:
116
- * - authApiClient: Auth API Client. You can use it to add a role to the user.
117
- * - user: the user data of the magda user that is just created.
118
- * - profile: the user profile received
119
- *
120
- * @returns {Promise<UserToken>}
121
- */
122
- 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>;
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 { }