@webda/auth 0.0.0-stage → 4.0.0-beta.11

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.
Files changed (77) hide show
  1. package/LICENSE +166 -0
  2. package/README.md +59 -2
  3. package/lib/authentication.service.d.ts +322 -0
  4. package/lib/authentication.service.d.ts.map +1 -0
  5. package/lib/authentication.service.js +978 -0
  6. package/lib/authentication.service.js.map +1 -0
  7. package/lib/certificate/certificate.service.d.ts +139 -0
  8. package/lib/certificate/certificate.service.d.ts.map +1 -0
  9. package/lib/certificate/certificate.service.js +343 -0
  10. package/lib/certificate/certificate.service.js.map +1 -0
  11. package/lib/compat/upgrade.d.ts +71 -0
  12. package/lib/compat/upgrade.d.ts.map +1 -0
  13. package/lib/compat/upgrade.js +200 -0
  14. package/lib/compat/upgrade.js.map +1 -0
  15. package/lib/email/emailpassword.service.d.ts +249 -0
  16. package/lib/email/emailpassword.service.d.ts.map +1 -0
  17. package/lib/email/emailpassword.service.js +714 -0
  18. package/lib/email/emailpassword.service.js.map +1 -0
  19. package/lib/email/tokens.d.ts +36 -0
  20. package/lib/email/tokens.d.ts.map +1 -0
  21. package/lib/email/tokens.js +46 -0
  22. package/lib/email/tokens.js.map +1 -0
  23. package/lib/errors.d.ts +53 -0
  24. package/lib/errors.d.ts.map +1 -0
  25. package/lib/errors.js +74 -0
  26. package/lib/errors.js.map +1 -0
  27. package/lib/index.d.ts +12 -0
  28. package/lib/index.d.ts.map +1 -0
  29. package/lib/index.js +12 -0
  30. package/lib/index.js.map +1 -0
  31. package/lib/mfa/secondfactor.service.d.ts +44 -0
  32. package/lib/mfa/secondfactor.service.d.ts.map +1 -0
  33. package/lib/mfa/secondfactor.service.js +38 -0
  34. package/lib/mfa/secondfactor.service.js.map +1 -0
  35. package/lib/mfa/totp.service.d.ts +41 -0
  36. package/lib/mfa/totp.service.d.ts.map +1 -0
  37. package/lib/mfa/totp.service.js +63 -0
  38. package/lib/mfa/totp.service.js.map +1 -0
  39. package/lib/oauth/oauth.service.d.ts +296 -0
  40. package/lib/oauth/oauth.service.d.ts.map +1 -0
  41. package/lib/oauth/oauth.service.js +560 -0
  42. package/lib/oauth/oauth.service.js.map +1 -0
  43. package/lib/provider.d.ts +53 -0
  44. package/lib/provider.d.ts.map +1 -0
  45. package/lib/provider.js +55 -0
  46. package/lib/provider.js.map +1 -0
  47. package/lib/test/authtest.d.ts +39 -0
  48. package/lib/test/authtest.d.ts.map +1 -0
  49. package/lib/test/authtest.js +62 -0
  50. package/lib/test/authtest.js.map +1 -0
  51. package/lib/test/emailtest.d.ts +25 -0
  52. package/lib/test/emailtest.d.ts.map +1 -0
  53. package/lib/test/emailtest.js +42 -0
  54. package/lib/test/emailtest.js.map +1 -0
  55. package/lib/test/fakeoauth.service.d.ts +45 -0
  56. package/lib/test/fakeoauth.service.d.ts.map +1 -0
  57. package/lib/test/fakeoauth.service.js +78 -0
  58. package/lib/test/fakeoauth.service.js.map +1 -0
  59. package/lib/test/mfauser.fixture.model.d.ts +11 -0
  60. package/lib/test/mfauser.fixture.model.d.ts.map +1 -0
  61. package/lib/test/mfauser.fixture.model.js +44 -0
  62. package/lib/test/mfauser.fixture.model.js.map +1 -0
  63. package/lib/test/stubprovider.d.ts +35 -0
  64. package/lib/test/stubprovider.d.ts.map +1 -0
  65. package/lib/test/stubprovider.js +46 -0
  66. package/lib/test/stubprovider.js.map +1 -0
  67. package/lib/test/v3.d.ts +29 -0
  68. package/lib/test/v3.d.ts.map +1 -0
  69. package/lib/test/v3.js +47 -0
  70. package/lib/test/v3.js.map +1 -0
  71. package/lib/throttle.d.ts +41 -0
  72. package/lib/throttle.d.ts.map +1 -0
  73. package/lib/throttle.js +49 -0
  74. package/lib/throttle.js.map +1 -0
  75. package/package.json +69 -3
  76. package/test/config.json +23 -0
  77. package/webda.module.json +891 -0
package/LICENSE ADDED
@@ -0,0 +1,166 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
166
+
package/README.md CHANGED
@@ -1,3 +1,60 @@
1
- # Temporary Holding Version
1
+ # @webda/auth module
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ This module is part of Webda Application Framework that allows you to quickly develop applications with all modern prerequisites: Security, Extensibility, GraphQL, REST, CloudNative [https://webda.io](https://webda.io)
4
+
5
+ <img src="https://webda.io/img/webda.svg" width="128" />
6
+
7
+ ![CI](https://github.com/loopingz/webda.io/workflows/CI/badge.svg)
8
+
9
+ [![Join the chat at https://gitter.im/loopingz/webda](https://badges.gitter.im/loopingz/webda.svg)](https://gitter.im/loopingz/webda?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
10
+ [![codecov](https://codecov.io/gh/loopingz/webda.io/branch/main/graph/badge.svg?token=8N9DNM3K3O)](https://codecov.io/gh/loopingz/webda.io)
11
+ [![SonarCloud.io](https://sonarcloud.io/api/project_badges/measure?project=loopingz_webda.io&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=loopingz_webda.io)
12
+ ![CodeQL](https://github.com/loopingz/webda.io/workflows/CodeQL/badge.svg)
13
+
14
+ <!-- README_HEADER -->
15
+
16
+ Authentication for Webda: login providers, account linking, access/refresh tokens, email + password with verification
17
+ and recovery, and v3 data compatibility.
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ pnpm add @webda/auth
23
+ ```
24
+
25
+ ## Minimal configuration
26
+
27
+ ```jsonc
28
+ {
29
+ "services": {
30
+ "Authentication": { "type": "Webda/Authentication" },
31
+ "emailAuth": { "type": "Webda/EmailPasswordProvider", "mailer": "Mailer" },
32
+ "db": { "type": "MemoryStore", "models": ["Webda/User", "Webda/Ident", "Webda/RefreshToken"] }
33
+ }
34
+ }
35
+ ```
36
+
37
+ ## Documentation
38
+
39
+ - [Authentication](../../docs/pages/Security/Authentication.md)
40
+ - [v3 to v4 migration](../../docs/pages/Migration/Authentication-v3-to-v4.md)
41
+
42
+ <!-- README_FOOTER -->
43
+
44
+ ## Sponsors
45
+
46
+ <!--
47
+ Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor](mailto:sponsor@webda.io)
48
+ -->
49
+
50
+ Arize AI is a machine learning observability and model monitoring platform. It helps you visualize, monitor, and explain your machine learning models. [Learn more](https://arize.com)
51
+
52
+ [<img src="https://webda.io/img/sponsors/arize.svg" width="200">](https://arize.com)
53
+
54
+ Loopingz is a software development company that provides consulting and development services. [Learn more](https://loopingz.com)
55
+
56
+ [<img src="https://webda.io/img/sponsors/loopingz.png" width="200">](https://loopingz.com)
57
+
58
+ Tellae is an innovative consulting firm specialized in cities transportation issues. We provide our clients, both public and private, with solutions to support your strategic and operational decisions. [Learn more](https://tellae.fr)
59
+
60
+ [<img src="https://webda.io/img/sponsors/tellae.svg" width="200">](https://tellae.fr)
@@ -0,0 +1,322 @@
1
+ import { type AuthenticationEvents, type AuthResult, Counter, Ident, MFA, type MfaAction, type IAuthenticationService, type IssuedTokens, type ProviderInfo, type ResolvedIdentity, Service, ServiceParameters, type User } from "@webda/core";
2
+ import type { ModelClass } from "@webda/models";
3
+ import { type AuthProvider, type ProviderEmailPolicy } from "./provider.js";
4
+ /** Account linking policy for unauthenticated logins matching an existing email */
5
+ export type LinkingPolicy = "never" | "verified" | "always";
6
+ /** v3 data compatibility options */
7
+ export interface AuthenticationCompatibility {
8
+ /**
9
+ * Read and write v3 data layouts
10
+ * @default true
11
+ */
12
+ v3?: boolean;
13
+ }
14
+ /** Counts of one kind of migrated records */
15
+ export interface MigrationCounts {
16
+ /** Records migrated (or that would be, in a dry run) */
17
+ migrated: number;
18
+ /** Records that look like v3 data but are not migrated (unrecognised key, foreign row) */
19
+ skipped: number;
20
+ /** Keys of the records whose migration failed */
21
+ failed: string[];
22
+ }
23
+ /** Result of `webda auth migrate` */
24
+ export interface MigrationReport {
25
+ /** v3 ident records */
26
+ idents: MigrationCounts;
27
+ /** Users whose stored record still has the v3 `__password` */
28
+ users: MigrationCounts;
29
+ /** Nothing was written */
30
+ dryRun: boolean;
31
+ /** Set when the ident passes stopped at the pass limit with records still migrating: run the command again */
32
+ incomplete?: boolean;
33
+ }
34
+ /** Authentication methods (amr) that are a primary factor: a second factor only counts on top of one of them */
35
+ export declare const PRIMARY_FACTORS: readonly string[];
36
+ /** Authentication parameters */
37
+ export declare class AuthenticationParameters extends ServiceParameters {
38
+ /**
39
+ * User model
40
+ * @default "Webda/User"
41
+ */
42
+ userModel: string;
43
+ /**
44
+ * Ident model
45
+ * @default "Webda/Ident"
46
+ */
47
+ identModel: string;
48
+ /**
49
+ * Linking policy
50
+ * @default "verified"
51
+ */
52
+ linking: LinkingPolicy;
53
+ /**
54
+ * Allow automatic registration of new users
55
+ * @default true
56
+ */
57
+ registration: boolean;
58
+ /**
59
+ * v3 data compatibility
60
+ * @default { "v3": true }
61
+ */
62
+ compatibility: AuthenticationCompatibility;
63
+ /**
64
+ * @param params - raw parameters
65
+ * @returns this
66
+ */
67
+ load(params?: any): this;
68
+ }
69
+ /**
70
+ * Shared authentication logic: providers hand a ResolvedIdentity to complete()
71
+ * @WebdaModda Authentication
72
+ */
73
+ export declare class Authentication<T extends AuthenticationParameters = AuthenticationParameters> extends Service<T, AuthenticationEvents> implements IAuthenticationService {
74
+ static Parameters: typeof AuthenticationParameters;
75
+ protected metrics?: {
76
+ login?: Counter;
77
+ logout?: Counter;
78
+ registration?: Counter;
79
+ };
80
+ protected providerMap: Map<string, AuthProvider>;
81
+ protected loginMfaAttribute?: string;
82
+ /**
83
+ * @returns the configured user model
84
+ */
85
+ getUserModel(): ModelClass<User>;
86
+ /**
87
+ * @returns the configured ident model
88
+ */
89
+ getIdentModel(): ModelClass<Ident>;
90
+ /** @override */
91
+ resolve(): this;
92
+ /** @override */
93
+ init(): Promise<this>;
94
+ /**
95
+ * Collect every service implementing {@link AuthProvider}
96
+ * @throws Error when two providers share the same name
97
+ */
98
+ protected discoverProviders(): void;
99
+ /** @override */
100
+ stop(): Promise<void>;
101
+ /**
102
+ * @param name - provider name
103
+ * @returns the provider
104
+ */
105
+ getProvider(name: string): AuthProvider | undefined;
106
+ /**
107
+ * @param name - provider name
108
+ * @returns the email policy of that provider, undefined for unknown providers or without policy
109
+ */
110
+ protected emailPolicyFor(name: string): ProviderEmailPolicy | undefined;
111
+ /**
112
+ * @returns public info of every provider
113
+ */
114
+ getProviders(): ProviderInfo[];
115
+ /**
116
+ * List available login methods
117
+ * @returns providers
118
+ */
119
+ providers(): ProviderInfo[];
120
+ /**
121
+ * Current user
122
+ * @returns public entry of the logged user
123
+ */
124
+ me(): Promise<any>;
125
+ /** @override */
126
+ initMetrics(): void;
127
+ /**
128
+ * Find an ident; with `compatibility.v3`, a miss falls back to the v3 record `"<uid>_<provider>"`, upgraded on
129
+ * the fly
130
+ * @param provider - provider
131
+ * @param providerUid - uid
132
+ * @returns the ident when it exists
133
+ */
134
+ protected findIdent(provider: string, providerUid: string): Promise<Ident | undefined>;
135
+ /**
136
+ * MFA methods enabled for a user
137
+ * @param user - user
138
+ * @returns enabled methods, empty when MFA is off
139
+ */
140
+ protected mfaMethods(user: User): string[];
141
+ /**
142
+ * Create and save a user for an identity
143
+ * @param identity - resolved identity
144
+ * @param data - extra profile data
145
+ * @param ctx - request context (complete() runs as system, so it passes the real one)
146
+ * @returns the user
147
+ */
148
+ registerUser(identity: ResolvedIdentity, data?: any, ctx?: any): Promise<User>;
149
+ /**
150
+ * Complete a login for an identity proven by a provider
151
+ * @param identity - resolved identity
152
+ * @param options - complete options
153
+ * @param options.newUser - identity.user was just created by the provider: its first ident is not a "link"
154
+ * @returns the result
155
+ * @throws IdentLinkedElsewhere when the ident belongs to another user than the logged one
156
+ * @throws AccountExists when the email matches an account the linking policy does not allow
157
+ * @throws RegistrationDisabled when a new user is needed but registration is off
158
+ * @throws WebdaError.BadRequest when `identity.provider` is not a registered AuthProvider
159
+ */
160
+ complete(identity: ResolvedIdentity, options?: {
161
+ newUser?: boolean;
162
+ }): Promise<AuthResult>;
163
+ /**
164
+ * Link an identity to the logged user without replacing their session or issuing credentials.
165
+ * @param identity - identity proved by a provider
166
+ * @returns a link acknowledgement
167
+ */
168
+ linkIdentity(identity: ResolvedIdentity): Promise<{
169
+ status: "linked";
170
+ }>;
171
+ /**
172
+ * Apply the email policy of the identity provider (complete() does it too, idempotently)
173
+ * Lets a provider refuse an identity before creating anything
174
+ * @param identity - resolved identity
175
+ * @returns the identity to use
176
+ * @throws EmailDomainNotAllowed when the policy refuses it
177
+ * @throws WebdaError.BadRequest when `identity.provider` is not a registered AuthProvider: an unknown name would
178
+ * escape the email policy of the provider it impersonates
179
+ */
180
+ applyPolicy(identity: ResolvedIdentity): ResolvedIdentity;
181
+ /**
182
+ * Body of {@link complete}, running as system with the request context passed explicitly
183
+ * @param identity - resolved identity
184
+ * @param ctx - request context
185
+ * @param retried - already retried after a concurrent creation
186
+ * @param newUser - identity.user was just created by the provider: its first ident is not a "link"
187
+ * @returns the result
188
+ */
189
+ protected completeAs(identity: ResolvedIdentity, ctx: any, retried: boolean, newUser?: boolean): Promise<AuthResult>;
190
+ /**
191
+ * @param userId - uuid
192
+ * @returns the user
193
+ */
194
+ protected loadUser(userId: string): Promise<User>;
195
+ /**
196
+ * Write the session, issue tokens, emit Login
197
+ * @param user - user or uuid
198
+ * @param ident - ident used
199
+ * @param identity - resolved identity
200
+ * @param ctx - request context (complete() runs as system, so it passes the real one)
201
+ * @returns the result
202
+ */
203
+ protected establish(user: User | string, ident: Ident, identity: ResolvedIdentity, ctx?: any): Promise<AuthResult>;
204
+ /**
205
+ * Finalise login after factors are verified: patch ident lastUsedAt, issue tokens, emit events, inc metric
206
+ * @param userObj - user instance
207
+ * @param ident - ident instance
208
+ * @param session - session
209
+ * @param ctx - operation context
210
+ * @param provider - provider name
211
+ * @param identity - optional resolved identity
212
+ * @param update - extra ident attributes to patch
213
+ * @returns auth result
214
+ */
215
+ protected finish(userObj: User, ident: Ident, session: any, ctx: any, provider: string, identity?: ResolvedIdentity, update?: any): Promise<AuthResult>;
216
+ /**
217
+ * Preserve login safeguards around the configured model attribute's actions.
218
+ * @param mfa - attached login MFA
219
+ * @param action - model behavior action
220
+ * @param method - requested factor method
221
+ * @param next - factor operation
222
+ * @returns model result, including tokens when authentication changes
223
+ */
224
+ protected runLoginMfa(mfa: MFA, action: MfaAction, method: string | undefined, next: () => Promise<any>): Promise<any>;
225
+ /**
226
+ * Complete second-factor authentication for a pending session
227
+ * @param amr - second factor method(s) used (e.g. ["totp"], ["recovery"])
228
+ * @returns auth result with issued tokens
229
+ */
230
+ completeSecondFactor(amr: string[]): Promise<AuthResult>;
231
+ /**
232
+ * Patch storing new provider tokens encrypted; also drops plaintext tokens left by an earlier v4 beta (`__tokens`)
233
+ * @param ident - the ident
234
+ * @param tokens - tokens from the provider, if any
235
+ * @returns the attributes to patch
236
+ */
237
+ protected tokensUpdate(ident: Ident, tokens: any): Promise<any>;
238
+ /**
239
+ * @returns the logged user id
240
+ * @throws WebdaError.Unauthorized when no fully logged session exists
241
+ */
242
+ protected requireUser(): string;
243
+ /**
244
+ * Logout and revoke the current refresh family; also abandons a pending MFA session
245
+ */
246
+ logout(): Promise<void>;
247
+ /**
248
+ * Exchange a refresh token
249
+ * @param refreshToken - refresh token
250
+ * @returns new tokens
251
+ */
252
+ refresh(refreshToken: string): Promise<IssuedTokens>;
253
+ /**
254
+ * List the current user's idents; with `compatibility.v3`, listing upgrades the user's v3 ident records first
255
+ * @returns idents of the current user
256
+ */
257
+ idents(): Promise<{
258
+ provider: string;
259
+ providerUid: string;
260
+ email?: string;
261
+ verifiedAt?: Date;
262
+ lastUsedAt?: Date;
263
+ }[]>;
264
+ /**
265
+ * @param userId - user
266
+ * @returns all idents owned by the user
267
+ */
268
+ protected listIdents(userId: string): Promise<Ident[]>;
269
+ /**
270
+ * Remove one of the current user's idents
271
+ * @param provider - provider
272
+ * @param providerUid - uid
273
+ * @throws LastLoginMethod when no usable login method would remain (non-email idents, plus email idents when the
274
+ * user has a password), or when it would remove the last email ident of a user with a password
275
+ */
276
+ unlink(provider: string, providerUid: string): Promise<void>;
277
+ /**
278
+ * Migrate v3 authentication data to the v4 layout
279
+ *
280
+ * Idents: every v3 record (`"<providerUid>_<provider>"` key) is upgraded to its `"<providerUid>:<provider>"`
281
+ * record (emails normalised) then deleted; with a custom ident model, the v3 rows typed as the core
282
+ * `Webda/Ident` are found through its repository too. Upgrading shifts position-based paging, so passes run
283
+ * until one upgrades nothing. Users: a user whose stored record still has the v3 `__password` is saved again in
284
+ * the v4 `password` shape. Idempotent: a second run migrates nothing. Failures are reported by key and logged,
285
+ * the migration goes on.
286
+ *
287
+ * Operator notes:
288
+ * - A v3 ident whose upgraded key another user already holds (e.g. two v3 email keys differing only by case) is
289
+ * reported in `idents.failed` (IDENT_CONFLICT) and kept: decide which user keeps the email, then delete or
290
+ * rename the other v3 row and run the command again.
291
+ * - A malformed ident key in the store stops the scan: remove that row manually.
292
+ * - Re-running is always safe: migrated records are not touched again.
293
+ * @param dryRun - only count, write nothing
294
+ * @param batch - page size of the scans
295
+ * @returns the report
296
+ */
297
+ migrate(
298
+ /** @description Only count the records to migrate, write nothing */
299
+ dryRun?: boolean,
300
+ /** @description Page size of the store scans */
301
+ batch?: number): Promise<MigrationReport>;
302
+ /**
303
+ * Enumerate the v3 ident rows: through the ident model, and through the core `Ident` repository when the
304
+ * ident model is a subclass (its queries only see rows typed as itself or its subclasses)
305
+ * @param pageSize - page size
306
+ * @returns the v3 keys found, each once per pass
307
+ */
308
+ protected legacyIdentKeys(pageSize: number): AsyncGenerator<string>;
309
+ /**
310
+ * Upgrade the v3 idents
311
+ * @param report - report to fill
312
+ * @param pageSize - page size
313
+ */
314
+ protected migrateIdents(report: MigrationReport, pageSize: number): Promise<void>;
315
+ /**
316
+ * Save again the users whose stored record still has the v3 `__password`
317
+ * @param report - report to fill
318
+ * @param pageSize - page size
319
+ */
320
+ protected migrateUsers(report: MigrationReport, pageSize: number): Promise<void>;
321
+ }
322
+ //# sourceMappingURL=authentication.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.service.d.ts","sourceRoot":"","sources":["../src/authentication.service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,UAAU,EAEf,OAAO,EACP,KAAK,EAEL,GAAG,EAEH,KAAK,SAAS,EAEd,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EAEjB,KA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