@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,178 @@
|
|
|
1
|
+
import { UserStorage, KeyStorage } from './storage';
|
|
2
|
+
import { User } from '@crossauth/common';
|
|
3
|
+
|
|
4
|
+
export interface TokenEmailerOptions {
|
|
5
|
+
/** The site url, used to create a link, eg "https://mysite.com:3000". No default - required parameter */
|
|
6
|
+
siteUrl?: string;
|
|
7
|
+
/** The prefix between the site url and the email verification/password reset link. Default "/" */
|
|
8
|
+
prefix?: string;
|
|
9
|
+
/** The directory containing views (by default, Nunjucks templates) */
|
|
10
|
+
views?: string;
|
|
11
|
+
/** Template file containing page for producing the text version of the email verification email body */
|
|
12
|
+
emailVerificationTextBody?: string;
|
|
13
|
+
/** Template file containing page for producing the HTML version of the email verification email body */
|
|
14
|
+
emailVerificationHtmlBody?: string;
|
|
15
|
+
/** Subject for the the email verification email */
|
|
16
|
+
emailVerificationSubject?: string;
|
|
17
|
+
/** Template file containing page for producing the text version of the password reset email body */
|
|
18
|
+
passwordResetTextBody?: string;
|
|
19
|
+
/** Template file containing page for producing the HTML version of the password reset email body */
|
|
20
|
+
passwordResetHtmlBody?: string;
|
|
21
|
+
/** Subject for the the password reset email */
|
|
22
|
+
passwordResetSubject?: string;
|
|
23
|
+
/** Sender for emails */
|
|
24
|
+
emailFrom?: string;
|
|
25
|
+
/** Hostname of the SMTP server. No default - required parameter */
|
|
26
|
+
smtpHost?: string;
|
|
27
|
+
/** Port the SMTP server is running on. Default 25 */
|
|
28
|
+
smtpPort?: number;
|
|
29
|
+
/** Whether or not TLS is used by the SMTP server. Default false */
|
|
30
|
+
smtpUseTls?: boolean;
|
|
31
|
+
/** Username for connecting to SMTP servger. Default undefined */
|
|
32
|
+
smtpUsername?: string;
|
|
33
|
+
/** Password for connecting to SMTP servger. Default undefined */
|
|
34
|
+
smtpPassword?: string;
|
|
35
|
+
/** Number of seconds befire email verification tokens should expire. Default 1 day */
|
|
36
|
+
verifyEmailExpires?: number;
|
|
37
|
+
/** Number of seconds befire password reset tokens should expire. Default 1 day */
|
|
38
|
+
passwordResetExpires?: number;
|
|
39
|
+
/** if passed, use this instead of the default nunjucks renderer */
|
|
40
|
+
render?: (template: string, data: {
|
|
41
|
+
[key: string]: any;
|
|
42
|
+
}) => string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Sends password reset and email verification tokens to an email addredss
|
|
46
|
+
*/
|
|
47
|
+
export declare class TokenEmailer {
|
|
48
|
+
private userStorage;
|
|
49
|
+
private keyStorage;
|
|
50
|
+
private views;
|
|
51
|
+
private siteUrl?;
|
|
52
|
+
private prefix?;
|
|
53
|
+
private emailVerificationTextBody?;
|
|
54
|
+
private emailVerificationHtmlBody?;
|
|
55
|
+
private emailVerificationSubject;
|
|
56
|
+
private passwordResetTextBody?;
|
|
57
|
+
private passwordResetHtmlBody?;
|
|
58
|
+
private passwordResetSubject;
|
|
59
|
+
private emailFrom;
|
|
60
|
+
private smtpHost;
|
|
61
|
+
private smtpPort;
|
|
62
|
+
private smtpUseTls?;
|
|
63
|
+
private smtpUsername?;
|
|
64
|
+
private smtpPassword?;
|
|
65
|
+
private verifyEmailExpires;
|
|
66
|
+
private passwordResetExpires;
|
|
67
|
+
private render?;
|
|
68
|
+
/**
|
|
69
|
+
* Construct a new EmailVerifier.
|
|
70
|
+
*
|
|
71
|
+
* This emails tokens for email verification and password reset
|
|
72
|
+
*
|
|
73
|
+
* @param userStorage : where to retrieve and update user details
|
|
74
|
+
* @param keyStorage : where to store email verification tokens
|
|
75
|
+
* @param options see {@link TokenEmailerOptions}
|
|
76
|
+
*/
|
|
77
|
+
constructor(userStorage: UserStorage, keyStorage: KeyStorage, options?: TokenEmailerOptions);
|
|
78
|
+
private createEmailer;
|
|
79
|
+
/**
|
|
80
|
+
* Produces a hash of the given email verification token with the
|
|
81
|
+
* correct prefix for inserting into storage.
|
|
82
|
+
*/
|
|
83
|
+
static hashEmailVerificationToken(token: string): string;
|
|
84
|
+
/**
|
|
85
|
+
* Produces a hash of the given password reset token with the
|
|
86
|
+
* correct prefix for inserting into storage.
|
|
87
|
+
*/
|
|
88
|
+
static hashPasswordResetToken(token: string): string;
|
|
89
|
+
private createAndSaveEmailVerificationToken;
|
|
90
|
+
/**
|
|
91
|
+
* Separated out for unit testing/mocking purposes
|
|
92
|
+
*/
|
|
93
|
+
private _sendEmailVerificationToken;
|
|
94
|
+
/**
|
|
95
|
+
* Send an email verification email using the Nunjucks templates.
|
|
96
|
+
*
|
|
97
|
+
* The email address to send it to will be taken from the user's record in
|
|
98
|
+
* user storage. It will
|
|
99
|
+
* first be validated, throwing a {@link @crossauth/common!CrossauthError}
|
|
100
|
+
* with {@link @crossauth/common!ErrorCode} of
|
|
101
|
+
* `InvalidEmail` if it is not valid..
|
|
102
|
+
*
|
|
103
|
+
* @param userid userid to send it for
|
|
104
|
+
* @param newEmail if this is a token to verify email for account
|
|
105
|
+
* activation, leave this empty.
|
|
106
|
+
* If it is for changing an email, this will be the field it is
|
|
107
|
+
* being changed do.
|
|
108
|
+
* @param extraData : these extra variables will be passed to the Nunjucks
|
|
109
|
+
* templates
|
|
110
|
+
*/
|
|
111
|
+
sendEmailVerificationToken(userid: string | number, newEmail?: string, extraData?: {
|
|
112
|
+
[key: string]: any;
|
|
113
|
+
}): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Validates an email verification token.
|
|
116
|
+
*
|
|
117
|
+
* The following must match:
|
|
118
|
+
* * expiry date in the key storage record must be less than current time
|
|
119
|
+
* * userid in the token must match the userid in the key storage
|
|
120
|
+
* * email address in user storage must match the email in the key. If there is no email address,
|
|
121
|
+
* the username field is set if it is in email format.
|
|
122
|
+
* * expiry time in the key storage must match the expiry time in the key
|
|
123
|
+
*
|
|
124
|
+
* Looks the token up in key storage and verifies it matches and has not expired.
|
|
125
|
+
* @param token the token to validate
|
|
126
|
+
* @returns the userid of the user the token is for and the email
|
|
127
|
+
* address the user is validating
|
|
128
|
+
*/
|
|
129
|
+
verifyEmailVerificationToken(token: string): Promise<{
|
|
130
|
+
userid: string | number;
|
|
131
|
+
newEmail: string;
|
|
132
|
+
}>;
|
|
133
|
+
deleteEmailVerificationToken(token: string): Promise<void>;
|
|
134
|
+
private createAndSavePasswordResetToken;
|
|
135
|
+
/**
|
|
136
|
+
* Validates a password reset token
|
|
137
|
+
*
|
|
138
|
+
* The following must match:
|
|
139
|
+
* * expiry date in the key storage record must be less than current time
|
|
140
|
+
* * userid in the token must match the userid in the key storage
|
|
141
|
+
* * the email in the token matches either the email or username field in user storage
|
|
142
|
+
* * the password in user storage must match the password in the key
|
|
143
|
+
* * expiry time in the key storage must match the expiry time in the key
|
|
144
|
+
* Looks the token up in key storage and verifies it matches and has not expired. Also verifies
|
|
145
|
+
* the user exists and password has not changed in the meantime.
|
|
146
|
+
* @param token the token to validate
|
|
147
|
+
* @returns the user that the token is for
|
|
148
|
+
*/
|
|
149
|
+
verifyPasswordResetToken(token: string): Promise<User>;
|
|
150
|
+
/**
|
|
151
|
+
* Separated out for unit testing/mocking purposes
|
|
152
|
+
*/
|
|
153
|
+
private _sendPasswordResetToken;
|
|
154
|
+
/**
|
|
155
|
+
* Send a password reset token email using the Nunjucks templates
|
|
156
|
+
* @param userid userid to send it for
|
|
157
|
+
* @param extraData : these extra variables will be passed to the Nunjucks
|
|
158
|
+
* templates
|
|
159
|
+
*/
|
|
160
|
+
sendPasswordResetToken(userid: string | number, extraData?: {
|
|
161
|
+
[key: string]: any;
|
|
162
|
+
}): Promise<void>;
|
|
163
|
+
/**
|
|
164
|
+
* Returns true if the given email has a valid format, false otherwise.
|
|
165
|
+
* @param email the email to validate
|
|
166
|
+
* @returns true or false
|
|
167
|
+
*/
|
|
168
|
+
static isEmailValid(email: string): boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Returns if the given email has a valid format. Throws a
|
|
171
|
+
* {@link @crossauth/common!CrossauthError} with
|
|
172
|
+
* {@link @crossauth/common!ErrorCode} `InvalidEmail` otherwise.
|
|
173
|
+
*
|
|
174
|
+
* @param email the email to validate
|
|
175
|
+
*/
|
|
176
|
+
static validateEmail(email: string | undefined): void;
|
|
177
|
+
}
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