@crossauth/backend 0.0.2
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/LICENSE +203 -0
- package/README.md +14 -0
- package/dist/apikey.d.ts +100 -0
- package/dist/apikey.d.ts.map +1 -0
- package/dist/auth.d.ts +131 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/authenticators/dummyfactor2.d.ts +129 -0
- package/dist/authenticators/dummyfactor2.d.ts.map +1 -0
- package/dist/authenticators/emailauth.d.ts +176 -0
- package/dist/authenticators/emailauth.d.ts.map +1 -0
- package/dist/authenticators/ldapauth.d.ts +89 -0
- package/dist/authenticators/ldapauth.d.ts.map +1 -0
- package/dist/authenticators/passwordauth.d.ts +159 -0
- package/dist/authenticators/passwordauth.d.ts.map +1 -0
- package/dist/authenticators/smsauth.d.ts +160 -0
- package/dist/authenticators/smsauth.d.ts.map +1 -0
- package/dist/authenticators/tests/ldapauth.test.d.ts +2 -0
- package/dist/authenticators/tests/ldapauth.test.d.ts.map +1 -0
- package/dist/authenticators/totpauth.d.ts +117 -0
- package/dist/authenticators/totpauth.d.ts.map +1 -0
- package/dist/authenticators/twilioauth.d.ts +29 -0
- package/dist/authenticators/twilioauth.d.ts.map +1 -0
- package/dist/cookieauth.d.ts +269 -0
- package/dist/cookieauth.d.ts.map +1 -0
- package/dist/crypto.d.ts +196 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/emailtokens.d.ts +178 -0
- package/dist/emailtokens.d.ts.map +1 -0
- package/dist/index.cjs +9107 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9090 -0
- package/dist/oauth/authserver.d.ts +490 -0
- package/dist/oauth/authserver.d.ts.map +1 -0
- package/dist/oauth/client.d.ts +72 -0
- package/dist/oauth/client.d.ts.map +1 -0
- package/dist/oauth/clientmanager.d.ts +73 -0
- package/dist/oauth/clientmanager.d.ts.map +1 -0
- package/dist/oauth/resserver.d.ts +43 -0
- package/dist/oauth/resserver.d.ts.map +1 -0
- package/dist/oauth/tests/common.d.ts +58 -0
- package/dist/oauth/tests/common.d.ts.map +1 -0
- package/dist/oauth/tests/oauthauthserver_authzcode.test.d.ts +2 -0
- package/dist/oauth/tests/oauthauthserver_authzcode.test.d.ts.map +1 -0
- package/dist/oauth/tests/oauthauthserver_clientcred.test.d.ts +2 -0
- package/dist/oauth/tests/oauthauthserver_clientcred.test.d.ts.map +1 -0
- package/dist/oauth/tests/oauthauthserver_device.test.d.ts +2 -0
- package/dist/oauth/tests/oauthauthserver_device.test.d.ts.map +1 -0
- package/dist/oauth/tests/oauthauthserver_mfa.test.d.ts +5 -0
- package/dist/oauth/tests/oauthauthserver_mfa.test.d.ts.map +1 -0
- package/dist/oauth/tests/oauthauthserver_password.test.d.ts +2 -0
- package/dist/oauth/tests/oauthauthserver_password.test.d.ts.map +1 -0
- package/dist/oauth/tests/oauthclient.test.d.ts +2 -0
- package/dist/oauth/tests/oauthclient.test.d.ts.map +1 -0
- package/dist/oauth/tests/oauthresserver.test.d.ts +2 -0
- package/dist/oauth/tests/oauthresserver.test.d.ts.map +1 -0
- package/dist/oauth/tokenconsumer.d.ts +80 -0
- package/dist/oauth/tokenconsumer.d.ts.map +1 -0
- package/dist/session.d.ts +491 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/storage/dbconnection.d.ts +19 -0
- package/dist/storage/dbconnection.d.ts.map +1 -0
- package/dist/storage/dbstorage.d.ts +319 -0
- package/dist/storage/dbstorage.d.ts.map +1 -0
- package/dist/storage/inmemorystorage.d.ts +225 -0
- package/dist/storage/inmemorystorage.d.ts.map +1 -0
- package/dist/storage/ldapstorage.d.ts +143 -0
- package/dist/storage/ldapstorage.d.ts.map +1 -0
- package/dist/storage/postgresconnection.d.ts +27 -0
- package/dist/storage/postgresconnection.d.ts.map +1 -0
- package/dist/storage/postgresstorage.d.ts +83 -0
- package/dist/storage/postgresstorage.d.ts.map +1 -0
- package/dist/storage/prismastorage.d.ts +361 -0
- package/dist/storage/prismastorage.d.ts.map +1 -0
- package/dist/storage/sqliteconnection.d.ts +35 -0
- package/dist/storage/sqliteconnection.d.ts.map +1 -0
- package/dist/storage/sqlitestorage.d.ts +83 -0
- package/dist/storage/sqlitestorage.d.ts.map +1 -0
- package/dist/storage/tests/dbtests.d.ts +5 -0
- package/dist/storage/tests/dbtests.d.ts.map +1 -0
- package/dist/storage/tests/inmemorystorage.test.d.ts +5 -0
- package/dist/storage/tests/inmemorystorage.test.d.ts.map +1 -0
- package/dist/storage/tests/inmemorytestdata.d.ts +4 -0
- package/dist/storage/tests/inmemorytestdata.d.ts.map +1 -0
- package/dist/storage/tests/ldapstorage.test.d.ts +2 -0
- package/dist/storage/tests/ldapstorage.test.d.ts.map +1 -0
- package/dist/storage/tests/postgresstorage.test.d.ts +2 -0
- package/dist/storage/tests/postgresstorage.test.d.ts.map +1 -0
- package/dist/storage/tests/prismastorage.test.d.ts +4 -0
- package/dist/storage/tests/prismastorage.test.d.ts.map +1 -0
- package/dist/storage/tests/sqlitestorage.test.d.ts +2 -0
- package/dist/storage/tests/sqlitestorage.test.d.ts.map +1 -0
- package/dist/storage.d.ts +411 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/tests/cookieauth.test.d.ts +4 -0
- package/dist/tests/cookieauth.test.d.ts.map +1 -0
- package/dist/tests/crypto.test.d.ts +2 -0
- package/dist/tests/crypto.test.d.ts.map +1 -0
- package/dist/tests/email.test.d.ts +4 -0
- package/dist/tests/email.test.d.ts.map +1 -0
- package/dist/tests/password.test.d.ts +5 -0
- package/dist/tests/password.test.d.ts.map +1 -0
- package/dist/tests/tmp.test.d.ts +2 -0
- package/dist/tests/tmp.test.d.ts.map +1 -0
- package/dist/tests/utils.test.d.ts +2 -0
- package/dist/tests/utils.test.d.ts.map +1 -0
- package/dist/utils.d.ts +41 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { User, Key, UserSecretsInputFields, UserInputFields } from '@crossauth/common';
|
|
2
|
+
import { Authenticator, AuthenticationParameters, AuthenticationOptions } from '../auth.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options for `EmailAuthenticator`
|
|
6
|
+
*/
|
|
7
|
+
export interface EmailAuthenticatorOptions extends AuthenticationOptions {
|
|
8
|
+
/** The directory containing views (by default, Nunjucks templates) */
|
|
9
|
+
views?: string;
|
|
10
|
+
/** Template file containing page for producing the text version of the
|
|
11
|
+
* email verification email body */
|
|
12
|
+
emailAuthenticatorTextBody?: string;
|
|
13
|
+
/** Template file containing page for producing the HTML version of the
|
|
14
|
+
* email verification email body */
|
|
15
|
+
emailAuthenticatorHtmlBody?: string;
|
|
16
|
+
/** Subject for the the email verification email */
|
|
17
|
+
emailAuthenticatorSubject?: string;
|
|
18
|
+
/** Sender for emails */
|
|
19
|
+
emailFrom?: string;
|
|
20
|
+
/** Hostname of the SMTP server. No default - required parameter */
|
|
21
|
+
smtpHost?: string;
|
|
22
|
+
/** Port the SMTP server is running on. Default 25 */
|
|
23
|
+
smtpPort?: number;
|
|
24
|
+
/** Whether or not TLS is used by the SMTP server. Default false */
|
|
25
|
+
smtpUseTls?: boolean;
|
|
26
|
+
/** Username for connecting to SMTP servger. Default undefined */
|
|
27
|
+
smtpUsername?: string;
|
|
28
|
+
/** Password for connecting to SMTP servger. Default undefined */
|
|
29
|
+
smtpPassword?: string;
|
|
30
|
+
/** Number of seconds before otps should expire. Default 5 minutes */
|
|
31
|
+
emailAuthenticatorTokenExpires?: number;
|
|
32
|
+
/** if passed, use this instead of the default nunjucks renderer */
|
|
33
|
+
render?: (template: string, data: {
|
|
34
|
+
[key: string]: any;
|
|
35
|
+
}) => string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* This authenticator creates a one-time code and sends it in email
|
|
39
|
+
*/
|
|
40
|
+
export declare class EmailAuthenticator extends Authenticator {
|
|
41
|
+
private views;
|
|
42
|
+
private emailAuthenticatorTextBody?;
|
|
43
|
+
private emailAuthenticatorHtmlBody?;
|
|
44
|
+
private emailAuthenticatorSubject;
|
|
45
|
+
private emailFrom;
|
|
46
|
+
private smtpHost;
|
|
47
|
+
private smtpPort;
|
|
48
|
+
private smtpUseTls?;
|
|
49
|
+
private smtpUsername?;
|
|
50
|
+
private smtpPassword?;
|
|
51
|
+
private emailAuthenticatorTokenExpires;
|
|
52
|
+
private render?;
|
|
53
|
+
/**
|
|
54
|
+
* Constructor
|
|
55
|
+
*
|
|
56
|
+
* @param options see {@link EmailAuthenticatorOptions}
|
|
57
|
+
*/
|
|
58
|
+
constructor(options?: EmailAuthenticatorOptions);
|
|
59
|
+
/**
|
|
60
|
+
* Used by the OAuth password_mfa grant type.
|
|
61
|
+
*/
|
|
62
|
+
mfaType(): "none" | "oob" | "otp";
|
|
63
|
+
/**
|
|
64
|
+
* Used by the OAuth password_mfa grant type.
|
|
65
|
+
*/
|
|
66
|
+
mfaChannel(): "none" | "email" | "sms";
|
|
67
|
+
private createEmailer;
|
|
68
|
+
private sendToken;
|
|
69
|
+
/**
|
|
70
|
+
* Creates and emails the one-time code
|
|
71
|
+
* @param user the user to create it for. Uses the `email` field if
|
|
72
|
+
* present, `username` otherwise (which in this case is
|
|
73
|
+
* expected to contain an email address)
|
|
74
|
+
* @returns `userData` containing `username`, `email`, `factor2`
|
|
75
|
+
* `sessionData` containing the same plus `otp` and `expiry` which
|
|
76
|
+
* is a Unix time (number).
|
|
77
|
+
*/
|
|
78
|
+
prepareConfiguration(user: UserInputFields): Promise<{
|
|
79
|
+
userData: {
|
|
80
|
+
[key: string]: any;
|
|
81
|
+
};
|
|
82
|
+
sessionData: {
|
|
83
|
+
[key: string]: any;
|
|
84
|
+
};
|
|
85
|
+
} | undefined>;
|
|
86
|
+
/**
|
|
87
|
+
* Creates and emails a new one-time code.
|
|
88
|
+
* @param _username ignored
|
|
89
|
+
* @param sessionKey the session containing the previously created data.
|
|
90
|
+
* @returns
|
|
91
|
+
*/
|
|
92
|
+
reprepareConfiguration(_username: string, sessionKey: Key): Promise<{
|
|
93
|
+
userData: {
|
|
94
|
+
[key: string]: any;
|
|
95
|
+
};
|
|
96
|
+
secrets: Partial<UserSecretsInputFields>;
|
|
97
|
+
newSessionData: {
|
|
98
|
+
[key: string]: any;
|
|
99
|
+
} | undefined;
|
|
100
|
+
} | undefined>;
|
|
101
|
+
/**
|
|
102
|
+
* Authenticates the user by comparing the user-provided otp with the one
|
|
103
|
+
* in secrets.
|
|
104
|
+
*
|
|
105
|
+
* Validation fails if the otp is incorrect or has expired.
|
|
106
|
+
*
|
|
107
|
+
* @param _user ignored
|
|
108
|
+
* @param secrets taken from the session and should contain `otp` and
|
|
109
|
+
* `expiry`
|
|
110
|
+
* @param params user input and should contain `otp`
|
|
111
|
+
* @throws {@link @crossauth/common!CrossauthError} with
|
|
112
|
+
* {@link @crossauth/common!ErrorCode} `InvalidToken` or `Expired`.
|
|
113
|
+
*/
|
|
114
|
+
authenticateUser(_user: User, secrets: UserSecretsInputFields, params: AuthenticationParameters): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Does nothing for this class
|
|
117
|
+
*/
|
|
118
|
+
createPersistentSecrets(_username: string, _params: AuthenticationParameters, _repeatParams?: AuthenticationParameters): Promise<Partial<UserSecretsInputFields>>;
|
|
119
|
+
/**
|
|
120
|
+
* Creates and emails a new one-time code.
|
|
121
|
+
* @param user the user to create it for. Uses the `email` field if
|
|
122
|
+
* present, `username` otherwise (which in this case is
|
|
123
|
+
* expected to contain an email address)
|
|
124
|
+
* @returns `otp` and `expiry` as a Unix time (number).
|
|
125
|
+
*/
|
|
126
|
+
createOneTimeSecrets(user: User): Promise<Partial<UserSecretsInputFields>>;
|
|
127
|
+
/**
|
|
128
|
+
* @returns true - this class can create users
|
|
129
|
+
*/
|
|
130
|
+
canCreateUser(): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* @returns true - this class can update users
|
|
133
|
+
*/
|
|
134
|
+
canUpdateUser(): boolean;
|
|
135
|
+
/**
|
|
136
|
+
* @returns false - users cannot update secrets
|
|
137
|
+
*/
|
|
138
|
+
canUpdateSecrets(): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* @returns empty - this authenticator has no persistent secrets
|
|
141
|
+
*/
|
|
142
|
+
secretNames(): string[];
|
|
143
|
+
/**
|
|
144
|
+
* @returns otp
|
|
145
|
+
*/
|
|
146
|
+
transientSecretNames(): string[];
|
|
147
|
+
/**
|
|
148
|
+
* Does nothing for this class
|
|
149
|
+
*/
|
|
150
|
+
validateSecrets(_params: AuthenticationParameters): string[];
|
|
151
|
+
/**
|
|
152
|
+
* @returns true - as a code is sent to the registers email address, no
|
|
153
|
+
* additional email verification is needed
|
|
154
|
+
*/
|
|
155
|
+
skipEmailVerificationOnSignup(): boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Returns whether or not the passed email has a valid form.
|
|
158
|
+
* @param email the email address to validate
|
|
159
|
+
* @returns true if it is valid. false otherwise
|
|
160
|
+
*/
|
|
161
|
+
static isEmailValid(email: string): boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Throws an exception if an email address doesn't have a valid form.
|
|
164
|
+
* @param email the email address to validate
|
|
165
|
+
* @throws {@link @crossauth/common!CrossauthError} with {@link @crossauth/common!ErrorCode} `InvalidEmail`.
|
|
166
|
+
*/
|
|
167
|
+
static validateEmail(email: string | undefined): void;
|
|
168
|
+
/**
|
|
169
|
+
* Takles a number and turns it into a zero-padded string
|
|
170
|
+
* @param num number ot pad
|
|
171
|
+
* @param places total number of required digits
|
|
172
|
+
* @returns zero-padded string
|
|
173
|
+
*/
|
|
174
|
+
static zeroPad(num: number, places: number): string;
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=emailauth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emailauth.d.ts","sourceRoot":"","sources":["../../src/authenticators/emailauth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,IAAI,EACJ,GAAG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,wBAAwB,GACxC,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAI5C;;;;;;OAMG;IACG,oBAAoB,CAAC,IAAI,EAAG,IAAI,GAClC,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAgB5C;;OAEG;IACH,aAAa,IAAK,OAAO;IAKzB;;OAEG;IACH,aAAa,IAAK,OAAO;IAIzB;;OAEG;IACH,gBAAgB,IAAK,OAAO;IAI5B;;OAEG;IACH,WAAW,IAAK,MAAM,EAAE;IAIxB;;OAEG;IACH,oBAAoB,IAAK,MAAM,EAAE;IAIjC;;OAEG;IACH,eAAe,CAAC,OAAO,EAAG,wBAAwB,GAAI,MAAM,EAAE;IAI9D;;;OAGG;IACH,6BAA6B,IAAK,OAAO;IAIzC;;;;OAIG;IACH,MAAM,CAAC,YAAY,CAAC,KAAK,EAAG,MAAM,GAAI,OAAO;IAU7C;;;;OAIG;IACH,MAAM,CAAC,aAAa,CAAC,KAAK,EAAG,MAAM,GAAC,SAAS;IAM7C;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAG,MAAM,EAAE,MAAM,EAAG,MAAM,GAAI,MAAM;CAKzD"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { User, UserSecretsInputFields, Key, UserInputFields } from '@crossauth/common';
|
|
2
|
+
import { PasswordAuthenticator, AuthenticationParameters, AuthenticationOptions } from '../auth.ts';
|
|
3
|
+
import { LdapUserStorage } from '../storage/ldapstorage.ts';
|
|
4
|
+
|
|
5
|
+
/** Optional parameters to pass to {@link LdapAuthenticator} constructor. */
|
|
6
|
+
export interface LdapAuthenticatorOptions extends AuthenticationOptions {
|
|
7
|
+
ldapAutoCreateAccount?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Authenticates a user against LDAP.
|
|
11
|
+
*
|
|
12
|
+
* Users are expected to be in a local storage as well, as defined by `ldapStorage`.
|
|
13
|
+
* This class can optionally auto-create a user that is not already there.
|
|
14
|
+
*/
|
|
15
|
+
export declare class LdapAuthenticator extends PasswordAuthenticator {
|
|
16
|
+
private ldapAutoCreateAccount;
|
|
17
|
+
private ldapStorage;
|
|
18
|
+
/**
|
|
19
|
+
* Create a new authenticator.
|
|
20
|
+
*
|
|
21
|
+
* @param ldapStorage the storage that defines the LDAP server and databse for storing users locally
|
|
22
|
+
* @param options see {@link LdapAuthenticatorOptions}
|
|
23
|
+
*/
|
|
24
|
+
constructor(ldapStorage: LdapUserStorage, options?: LdapAuthenticatorOptions);
|
|
25
|
+
/**
|
|
26
|
+
* Authenticates the user, returning a the user as a {@link User} object.
|
|
27
|
+
*
|
|
28
|
+
* @param user the `username` field is required and this is used for LDAP authentication.
|
|
29
|
+
* If `ldapAutoCreateAccount` is true, these attributes as used for user creation (see {@link LdapUserStorage.createUser}).
|
|
30
|
+
* @param _secrets Ignored as secrets are stored in LDAP
|
|
31
|
+
* @param params the `password` field is expected to contain the LDAP password.
|
|
32
|
+
* @throws {@link @crossauth/common!CrossauthError} with {@link @crossauth/common!ErrorCode} of `Connection`, `UsernameOrPasswordInvalid`.
|
|
33
|
+
*/
|
|
34
|
+
authenticateUser(user: UserInputFields, _secrets: UserSecretsInputFields, params: AuthenticationParameters): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Does nothing as LDAP is responsible for password format (this class doesn't create password entries)
|
|
37
|
+
*/
|
|
38
|
+
validateSecrets(_params: AuthenticationParameters): string[];
|
|
39
|
+
/**
|
|
40
|
+
* Does nothing in this class.
|
|
41
|
+
*/
|
|
42
|
+
createPersistentSecrets(_username: string, _params: AuthenticationParameters, _repeatParams: AuthenticationParameters): Promise<Partial<UserSecretsInputFields>>;
|
|
43
|
+
/**
|
|
44
|
+
* Does nothing in this class.
|
|
45
|
+
*/
|
|
46
|
+
createOneTimeSecrets(_user: User): Promise<Partial<UserSecretsInputFields>>;
|
|
47
|
+
/**
|
|
48
|
+
* @returns true - we can create a user (but not secrets)
|
|
49
|
+
*/
|
|
50
|
+
canCreateUser(): boolean;
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @returns true - we can update user (but not secrets).
|
|
54
|
+
*/
|
|
55
|
+
canUpdateUser(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* @returns false - users cannot update secrets
|
|
58
|
+
*/
|
|
59
|
+
canUpdateSecrets(): boolean;
|
|
60
|
+
/**
|
|
61
|
+
*
|
|
62
|
+
* @returns false - if email verification is enabled, it should happen for this authenticator
|
|
63
|
+
*/
|
|
64
|
+
skipEmailVerificationOnSignup(): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Does nothing in this class
|
|
67
|
+
*/
|
|
68
|
+
prepareConfiguration(_user: UserInputFields): Promise<{
|
|
69
|
+
userData: {
|
|
70
|
+
[key: string]: any;
|
|
71
|
+
};
|
|
72
|
+
sessionData: {
|
|
73
|
+
[key: string]: any;
|
|
74
|
+
};
|
|
75
|
+
} | undefined>;
|
|
76
|
+
/**
|
|
77
|
+
* Does nothing in this class
|
|
78
|
+
*/
|
|
79
|
+
reprepareConfiguration(_username: string, _sessionKey: Key): Promise<{
|
|
80
|
+
userData: {
|
|
81
|
+
[key: string]: any;
|
|
82
|
+
};
|
|
83
|
+
secrets: Partial<UserSecretsInputFields>;
|
|
84
|
+
newSessionData: {
|
|
85
|
+
[key: string]: any;
|
|
86
|
+
} | undefined;
|
|
87
|
+
} | undefined>;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=ldapauth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ldapauth.d.ts","sourceRoot":"","sources":["../../src/authenticators/ldapauth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,sBAAsB,EAAE,GAAG,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAG5F,OAAO,EAAE,qBAAqB,EAAE,KAAK,wBAAwB,EAAG,KAAK,qBAAqB,EAAC,MAAM,YAAY,CAAC;AAC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ACG,sBAAsB,CAAC,SAAS,EAAG,MAAM,EAAE,WAAW,EAAG,GAAG,GAAI,OAAO,CAAC;QAAC,QAAQ,EAAE;YAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;SAAC,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAC;QAAC,cAAc,EAAE;YAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;SAAC,GAAC,SAAS,CAAA;KAAC,GAAC,SAAS,CAAC;CAGpN"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { User, UserSecretsInputFields, Key, UserInputFields } from '@crossauth/common';
|
|
2
|
+
import { UserStorage } from '../storage.ts';
|
|
3
|
+
import { PasswordAuthenticator, AuthenticationParameters, AuthenticationOptions } from '../auth.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Optional parameters to pass to {@link LocalPasswordAuthenticator}
|
|
7
|
+
* constructor.
|
|
8
|
+
*/
|
|
9
|
+
export interface LocalPasswordAuthenticatorOptions extends AuthenticationOptions {
|
|
10
|
+
/** Application secret. If defined, it is used as the secret in PBKDF2 to hash passwords */
|
|
11
|
+
secret?: string;
|
|
12
|
+
/** If true, the `secret` will be concatenated to the salt when generating a hash for storing the password */
|
|
13
|
+
enableSecretForPasswordHash?: boolean;
|
|
14
|
+
/** Digest method for PBKDF2 hasher.. Default `sha256` */
|
|
15
|
+
pbkdf2Digest?: string;
|
|
16
|
+
/** Number of PBKDF2 iterations. Default 600_000 */
|
|
17
|
+
pbkdf2Iterations?: number;
|
|
18
|
+
/** Number of characters for salt, before base64-enoding. Default 16 */
|
|
19
|
+
pbkdf2SaltLength?: number;
|
|
20
|
+
/** Length the PBKDF2 key to generate, before bsae64-url encoding. Default 32 */
|
|
21
|
+
pbkdf2KeyLength?: number;
|
|
22
|
+
/** Function that throws a {@link @crossauth/common!CrossauthError} with
|
|
23
|
+
* {@link @crossauth/common!ErrorCode} `PasswordFormat` if the password
|
|
24
|
+
* doesn't confirm to local rules (eg number of charafters) */
|
|
25
|
+
validatePasswordFn?: (params: AuthenticationParameters) => string[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Does username/password authentication using PBKDF2 hashed passwords.
|
|
29
|
+
*/
|
|
30
|
+
export declare class LocalPasswordAuthenticator extends PasswordAuthenticator {
|
|
31
|
+
static NoPassword: string;
|
|
32
|
+
private secret;
|
|
33
|
+
/** If true, the secret key will be added to the salt when hashing. Default false */
|
|
34
|
+
enableSecretForPasswords: boolean;
|
|
35
|
+
/** See {@link LocalPasswordAuthenticatorOptions.pbkdf2Digest} */
|
|
36
|
+
pbkdf2Digest?: string;
|
|
37
|
+
/** See {@link LocalPasswordAuthenticatorOptions.pbkdf2Iterations} */
|
|
38
|
+
pbkdf2Iterations?: number;
|
|
39
|
+
/** See {@link LocalPasswordAuthenticatorOptions.pbkdf2SaltLength} */
|
|
40
|
+
pbkdf2SaltLength?: number;
|
|
41
|
+
/** See {@link LocalPasswordAuthenticatorOptions.pbkdf2KeyLength} */
|
|
42
|
+
pbkdf2KeyLength?: number;
|
|
43
|
+
/** See {@link LocalPasswordAuthenticatorOptions.validatePasswordFn} */
|
|
44
|
+
validatePasswordFn: (params: AuthenticationParameters) => string[];
|
|
45
|
+
/**
|
|
46
|
+
* Create a new authenticator.
|
|
47
|
+
*
|
|
48
|
+
* See crypto.pbkdf2 for more information on the optional parameters.
|
|
49
|
+
*
|
|
50
|
+
* @param _userStorage ignored
|
|
51
|
+
* @param options see {@link LocalPasswordAuthenticatorOptions}
|
|
52
|
+
*/
|
|
53
|
+
constructor(_userStorage: UserStorage, options?: LocalPasswordAuthenticatorOptions);
|
|
54
|
+
/**
|
|
55
|
+
* Authenticates the user, returning a the user as a {@link User} object.
|
|
56
|
+
*
|
|
57
|
+
* If you set `extraFields` when constructing the {@link UserStorage} instance passed to the constructor,
|
|
58
|
+
* these will be included in the returned User object. `hashedPassword`, if present in the User object,
|
|
59
|
+
* will be removed.
|
|
60
|
+
*
|
|
61
|
+
* @param user the `username` field should contain the username
|
|
62
|
+
* @param secrets from the `UserSecrets` table. `password` is expected to be present
|
|
63
|
+
* @param params the user input. `password` is expected to be present
|
|
64
|
+
* @throws {@link @crossauth/common!CrossauthError} with
|
|
65
|
+
* {@link @crossauth/common!ErrorCode} of `Connection`,
|
|
66
|
+
* `UserNotExist`or `PasswordInvalid`, `TwoFactorIncomplete`,
|
|
67
|
+
* `EmailNotVerified` or `UserNotActive`.
|
|
68
|
+
*/
|
|
69
|
+
authenticateUser(user: UserInputFields, secrets: UserSecretsInputFields, params: AuthenticationParameters): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Calls the implementor-provided `validatePasswordFn`
|
|
72
|
+
*
|
|
73
|
+
* This function is called to apply local password policy (password length,
|
|
74
|
+
* uppercase/lowercase etc)
|
|
75
|
+
* @param params the password should be in `password`
|
|
76
|
+
* @returns an array of errors
|
|
77
|
+
*/
|
|
78
|
+
validateSecrets(params: AuthenticationParameters): string[];
|
|
79
|
+
/**
|
|
80
|
+
* Creates and returns a hash of the passed password, with the hashing parameters encoded ready
|
|
81
|
+
* for storage.
|
|
82
|
+
*
|
|
83
|
+
* If salt is not provieed, a random one is greated. If secret was passed to the constructor
|
|
84
|
+
* or in the .env, and enableSecretInPasswords was set to true, it is used as the pepper.
|
|
85
|
+
* used as the pepper.
|
|
86
|
+
*
|
|
87
|
+
* @param password the password to hash
|
|
88
|
+
* @param salt the salt to use. If undefined, a random one will be generated.
|
|
89
|
+
* @returns the encoded hash string.
|
|
90
|
+
*/
|
|
91
|
+
createPasswordHash(password: string, salt?: string): Promise<string>;
|
|
92
|
+
/**
|
|
93
|
+
* Just calls createPasswordHash with encode set to true
|
|
94
|
+
* @param password the password to hash
|
|
95
|
+
* @returns a string for storing in storage
|
|
96
|
+
*/
|
|
97
|
+
createPasswordForStorage(password: string): Promise<string>;
|
|
98
|
+
/**
|
|
99
|
+
* A static version of the password hasher, provided for convenience
|
|
100
|
+
* @param password : unhashed password
|
|
101
|
+
* @param passwordHash : hashed password
|
|
102
|
+
* @param secret secret, if used when hashing passwords, or undefined if not
|
|
103
|
+
* @returns true if match, false otherwise
|
|
104
|
+
*/
|
|
105
|
+
passwordMatchesHash(password: string, passwordHash: string, secret?: string): Promise<boolean>;
|
|
106
|
+
/**
|
|
107
|
+
* This will return p hash of the passed password.
|
|
108
|
+
* @param _username ignored
|
|
109
|
+
* @param params expected to contain `password`
|
|
110
|
+
* @param repeatParams if defined, this is expected to also contain
|
|
111
|
+
* `password` and is checked to match the one in `params`
|
|
112
|
+
* @returns the newly created password in the `password` field.
|
|
113
|
+
*/
|
|
114
|
+
createPersistentSecrets(_username: string, params: AuthenticationParameters, repeatParams: AuthenticationParameters): Promise<Partial<UserSecretsInputFields>>;
|
|
115
|
+
/**
|
|
116
|
+
* Does nothing for this class.
|
|
117
|
+
*/
|
|
118
|
+
createOneTimeSecrets(_user: User): Promise<Partial<UserSecretsInputFields>>;
|
|
119
|
+
/**
|
|
120
|
+
* @returns true - this class can create users
|
|
121
|
+
*/
|
|
122
|
+
canCreateUser(): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* @returns true - this class can update users
|
|
125
|
+
*/
|
|
126
|
+
canUpdateUser(): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* @returns true - users can update secrets
|
|
129
|
+
*/
|
|
130
|
+
canUpdateSecrets(): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* @returns false, if email verification is enabled, it should be for this authenticator too
|
|
133
|
+
*/
|
|
134
|
+
skipEmailVerificationOnSignup(): boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Does nothing for this class.
|
|
137
|
+
*/
|
|
138
|
+
prepareConfiguration(_user: UserInputFields): Promise<{
|
|
139
|
+
userData: {
|
|
140
|
+
[key: string]: any;
|
|
141
|
+
};
|
|
142
|
+
sessionData: {
|
|
143
|
+
[key: string]: any;
|
|
144
|
+
};
|
|
145
|
+
} | undefined>;
|
|
146
|
+
/**
|
|
147
|
+
* Does nothing for this class.
|
|
148
|
+
*/
|
|
149
|
+
reprepareConfiguration(_username: string, _sessionKey: Key): Promise<{
|
|
150
|
+
userData: {
|
|
151
|
+
[key: string]: any;
|
|
152
|
+
};
|
|
153
|
+
secrets: Partial<UserSecretsInputFields>;
|
|
154
|
+
newSessionData: {
|
|
155
|
+
[key: string]: any;
|
|
156
|
+
} | undefined;
|
|
157
|
+
} | undefined>;
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=passwordauth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"passwordauth.d.ts","sourceRoot":"","sources":["../../src/authenticators/passwordauth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,sBAAsB,EAAE,GAAG,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAE5F,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAI3C,OAAO,EAAE,qBAAqB,EAAE,KAAK,wBAAwB,EAAG,KAAK,qBAAqB,EAAC,MAAM,YAAY,CAAC;AAwB9G;;;GAGG;AACH,MAAM,WAAW,iCAAkC,SAAQ,qBAAqB;IAE5E,4FAA4F;IAC5F,MAAM,CAAC,EAAG,MAAM,CAAC;IAEjB,6GAA6G;IAC7G,2BAA2B,CAAC,EAAG,OAAO,CAAC;IAEvC,yDAAyD;IACzD,YAAY,CAAC,EAAG,MAAM,CAAC;IAEvB,oDAAoD;IACpD,gBAAgB,CAAC,EAAG,MAAM,CAAC;IAE3B,wEAAwE;IACxE,gBAAgB,CAAC,EAAG,MAAM,CAAC;IAE3B,iFAAiF;IACjF,eAAe,CAAC,EAAG,MAAM,CAAC;IAE1B;;oEAEgE;IAChE,kBAAkB,CAAC,EAAG,CAAC,MAAM,EAAG,wBAAwB,KAAK,MAAM,EAAE,CAAC;CACzE;AAED;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,qBAAqB;IAEjE,MAAM,CAAC,UAAU,SAA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O,CAAC,sBAAsB,CAAC,CAAC;IAInF;;OAEG;IACH,aAAa,IAAK,OAAO;IACzB;;OAEG;IACH,aAAa,IAAK,OAAO;IAEzB;;OAEG;IACH,gBAAgB,IAAK,OAAO;IAI5B;;OAEG;IACH,6BAA6B,IAAK,OAAO;IAIzC;;OAEG;IACG,oBAAoB,CAAC,KAAK,EAAG,eAAe,GAAI,OAAO,CAAC;QAAC,QAAQ,EAAE;YAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;SAAC,CAAC;QAAC,WAAW,EAAE;YAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;SAAC,CAAA;KAAC,GAAC,SAAS,CAAC;IAI1I;;OAEG;IACG,sBAAsB,CAAC,SAAS,EAAG,MAAM,EAAE,WAAW,EAAG,GAAG,GAAI,OAAO,CAAC;QAAC,QAAQ,EAAE;YAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;SAAC,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAC;QAAC,cAAc,EAAE;YAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;SAAC,GAAC,SAAS,CAAA;KAAC,GAAC,SAAS,CAAC;CAGpN"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { User, Key, UserSecretsInputFields, UserInputFields } from '@crossauth/common';
|
|
2
|
+
import { Authenticator, AuthenticationParameters, AuthenticationOptions } from '../auth.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options for {@link SmsAuthenticator}
|
|
6
|
+
*/
|
|
7
|
+
export interface SmsAuthenticatorOptions extends AuthenticationOptions {
|
|
8
|
+
/** The directory containing views (by default, Nunjucks templates) */
|
|
9
|
+
views?: string;
|
|
10
|
+
/** Template file containing page for producing the
|
|
11
|
+
* SMS message */
|
|
12
|
+
smsAuthenticatorBody?: string;
|
|
13
|
+
/** Phone number for sending sms from */
|
|
14
|
+
smsAuthenticatorFrom?: string;
|
|
15
|
+
/** Number of seconds before otps should expire. Default 5 minutes */
|
|
16
|
+
smsAuthenticatorTokenExpires?: number;
|
|
17
|
+
/** if passed, use this instead of the default nunjucks renderer */
|
|
18
|
+
render?: (template: string, data: {
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}) => string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* This authenticator creates a one-time code and sends it in an sms using
|
|
24
|
+
* Twilio
|
|
25
|
+
*/
|
|
26
|
+
export declare abstract class SmsAuthenticator extends Authenticator {
|
|
27
|
+
protected views: string;
|
|
28
|
+
protected smsAuthenticatorBody: string;
|
|
29
|
+
protected smsAuthenticatorFrom: string;
|
|
30
|
+
protected smsAuthenticatorTokenExpires: number;
|
|
31
|
+
private render?;
|
|
32
|
+
/**
|
|
33
|
+
* Constructor
|
|
34
|
+
* @param options see {@link SmsAuthenticatorOptions}
|
|
35
|
+
*/
|
|
36
|
+
constructor(options?: SmsAuthenticatorOptions);
|
|
37
|
+
/**
|
|
38
|
+
* Used by the OAuth password_mfa grant type.
|
|
39
|
+
*/
|
|
40
|
+
mfaType(): "none" | "oob" | "otp";
|
|
41
|
+
/**
|
|
42
|
+
* Used by the OAuth password_mfa grant type.
|
|
43
|
+
*/
|
|
44
|
+
mfaChannel(): "none" | "email" | "sms";
|
|
45
|
+
/**
|
|
46
|
+
* Send an SMS
|
|
47
|
+
*
|
|
48
|
+
* @param to number to send SMS to (starting with `+`)
|
|
49
|
+
* @param body text to send
|
|
50
|
+
* @returns the send message ID
|
|
51
|
+
*/
|
|
52
|
+
protected abstract sendSms(to: string, body: string): Promise<string>;
|
|
53
|
+
/**
|
|
54
|
+
* Creates and sends the one-time code
|
|
55
|
+
* @param user the user to create it for. Uses the `phone` field which
|
|
56
|
+
* is expected to be a phone number starting with `+`
|
|
57
|
+
* @returns `userData` containing `username`, `phone`, `factor2`
|
|
58
|
+
* `sessionData` containing the same plus `otp` and `expiry` which
|
|
59
|
+
* is a Unix time (number).
|
|
60
|
+
*/
|
|
61
|
+
prepareConfiguration(user: UserInputFields): Promise<{
|
|
62
|
+
userData: {
|
|
63
|
+
[key: string]: any;
|
|
64
|
+
};
|
|
65
|
+
sessionData: {
|
|
66
|
+
[key: string]: any;
|
|
67
|
+
};
|
|
68
|
+
} | undefined>;
|
|
69
|
+
/**
|
|
70
|
+
* Creates and sends a new one-time code.
|
|
71
|
+
* @param _username ignored
|
|
72
|
+
* @param sessionKey the session containing the previously created data.
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
75
|
+
reprepareConfiguration(_username: string, sessionKey: Key): Promise<{
|
|
76
|
+
userData: {
|
|
77
|
+
[key: string]: any;
|
|
78
|
+
};
|
|
79
|
+
secrets: Partial<UserSecretsInputFields>;
|
|
80
|
+
newSessionData: {
|
|
81
|
+
[key: string]: any;
|
|
82
|
+
} | undefined;
|
|
83
|
+
} | undefined>;
|
|
84
|
+
/**
|
|
85
|
+
* Authenticates the user by comparing the user-provided otp with the one
|
|
86
|
+
* in secrets.
|
|
87
|
+
*
|
|
88
|
+
* Validation fails if the otp is incorrect or has expired.
|
|
89
|
+
*
|
|
90
|
+
* @param _user ignored
|
|
91
|
+
* @param secrets taken from the session and should contain `otp` and
|
|
92
|
+
* `expiry`
|
|
93
|
+
* @param params user input and should contain `otp`
|
|
94
|
+
* @throws {@link @crossauth/common!CrossauthError} with
|
|
95
|
+
* {@link @crossauth/common!ErrorCode} `InvalidToken` or `Expired`.
|
|
96
|
+
*/
|
|
97
|
+
authenticateUser(_user: User, secrets: UserSecretsInputFields, params: AuthenticationParameters): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Does nothing for this class
|
|
100
|
+
*/
|
|
101
|
+
createPersistentSecrets(_username: string, _params: AuthenticationParameters, _repeatParams?: AuthenticationParameters): Promise<Partial<UserSecretsInputFields>>;
|
|
102
|
+
/**
|
|
103
|
+
* Creates and sends a new one-time code.
|
|
104
|
+
* @param user the user to create it for. Uses the `phone` field which
|
|
105
|
+
* should start with `+`
|
|
106
|
+
* @returns `otp` and `expiry` as a Unix time (number).
|
|
107
|
+
*/
|
|
108
|
+
createOneTimeSecrets(user: User): Promise<Partial<UserSecretsInputFields>>;
|
|
109
|
+
/**
|
|
110
|
+
* @returns true - this class can create users
|
|
111
|
+
*/
|
|
112
|
+
canCreateUser(): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* @returns true - this class can update users
|
|
115
|
+
*/
|
|
116
|
+
canUpdateUser(): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* @returns false - users cannot update secrets
|
|
119
|
+
*/
|
|
120
|
+
canUpdateSecrets(): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* @returns empty - this authenticator has no persistent secrets
|
|
123
|
+
*/
|
|
124
|
+
secretNames(): string[];
|
|
125
|
+
/**
|
|
126
|
+
* @returns otp
|
|
127
|
+
*/
|
|
128
|
+
transientSecretNames(): string[];
|
|
129
|
+
/**
|
|
130
|
+
* Does nothing for this class
|
|
131
|
+
*/
|
|
132
|
+
validateSecrets(_params: AuthenticationParameters): string[];
|
|
133
|
+
/**
|
|
134
|
+
* @returns false - doesn't replace email verification
|
|
135
|
+
*/
|
|
136
|
+
skipEmailVerificationOnSignup(): boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Returns whether or not the passed phone number has a valid form.
|
|
139
|
+
* @param number the phone number to validate
|
|
140
|
+
* @returns true if it is valid. false otherwise
|
|
141
|
+
*/
|
|
142
|
+
static isPhoneValid(number: string): boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Throws an exception if a phone number doesn't have a valid form.
|
|
145
|
+
*
|
|
146
|
+
* It must start with a `+` and be 8 to 15 digits
|
|
147
|
+
* @param number the phone number to validate
|
|
148
|
+
* @throws {@link @crossauth/common!CrossauthError} with
|
|
149
|
+
* {@link @crossauth/common!ErrorCode} `InvalidPhoneNumber`.
|
|
150
|
+
*/
|
|
151
|
+
static validatePhone(number: string | undefined): void;
|
|
152
|
+
/**
|
|
153
|
+
* Takles a number and turns it into a zero-padded string
|
|
154
|
+
* @param num number ot pad
|
|
155
|
+
* @param places total number of required digits
|
|
156
|
+
* @returns zero-padded string
|
|
157
|
+
*/
|
|
158
|
+
static zeroPad(num: number, places: number): string;
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=smsauth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smsauth.d.ts","sourceRoot":"","sources":["../../src/authenticators/smsauth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,IAAI,EACJ,GAAG,EACH,sBAAsB,EACtB,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAI/C,OAAO,EACH,aAAa,EACb,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAMnD;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,qBAAqB;IAElE,sEAAsE;IACtE,KAAK,CAAC,EAAG,MAAM,CAAC;IAEhB;qBACiB;IACjB,oBAAoB,CAAC,EAAG,MAAM,CAAC;IAE/B,wCAAwC;IACxC,oBAAoB,CAAC,EAAG,MAAM,CAAC;IAE/B,sEAAsE;IACtE,4BAA4B,CAAC,EAAG,MAAM,CAAC;IAEvC,mEAAmE;IACnE,MAAM,CAAC,EAAG,CAAC,QAAQ,EAAG,MAAM,EAAE,IAAI,EAAG;QAAC,CAAC,GAAG,EAAC,MAAM,GAAE,GAAG,CAAA;KAAC,KAAK,MAAM,CAAC;CACtE;AAED;;;GAGG;AACH,8BAAsB,gBAAiB,SAAQ,aAAa;IAExD,SAAS,CAAC,KAAK,EAAG,MAAM,CAAW;IACnC,SAAS,CAAC,oBAAoB,EAAG,MAAM,CAA+B;IACtE,SAAS,CAAC,oBAAoB,EAAG,MAAM,CAAM;IAC7C,SAAS,CAAC,4BAA4B,EAAG,MAAM,CAAQ;IACvD,OAAO,CAAC,MAAM,CAAC,CACQ;IAEvB;;;OAGG;gBACS,OAAO,GAAG,uBAA4B;IAclD;;OAE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