@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.
Files changed (109) hide show
  1. package/LICENSE +203 -0
  2. package/README.md +14 -0
  3. package/dist/apikey.d.ts +100 -0
  4. package/dist/apikey.d.ts.map +1 -0
  5. package/dist/auth.d.ts +131 -0
  6. package/dist/auth.d.ts.map +1 -0
  7. package/dist/authenticators/dummyfactor2.d.ts +129 -0
  8. package/dist/authenticators/dummyfactor2.d.ts.map +1 -0
  9. package/dist/authenticators/emailauth.d.ts +176 -0
  10. package/dist/authenticators/emailauth.d.ts.map +1 -0
  11. package/dist/authenticators/ldapauth.d.ts +89 -0
  12. package/dist/authenticators/ldapauth.d.ts.map +1 -0
  13. package/dist/authenticators/passwordauth.d.ts +159 -0
  14. package/dist/authenticators/passwordauth.d.ts.map +1 -0
  15. package/dist/authenticators/smsauth.d.ts +160 -0
  16. package/dist/authenticators/smsauth.d.ts.map +1 -0
  17. package/dist/authenticators/tests/ldapauth.test.d.ts +2 -0
  18. package/dist/authenticators/tests/ldapauth.test.d.ts.map +1 -0
  19. package/dist/authenticators/totpauth.d.ts +117 -0
  20. package/dist/authenticators/totpauth.d.ts.map +1 -0
  21. package/dist/authenticators/twilioauth.d.ts +29 -0
  22. package/dist/authenticators/twilioauth.d.ts.map +1 -0
  23. package/dist/cookieauth.d.ts +269 -0
  24. package/dist/cookieauth.d.ts.map +1 -0
  25. package/dist/crypto.d.ts +196 -0
  26. package/dist/crypto.d.ts.map +1 -0
  27. package/dist/emailtokens.d.ts +178 -0
  28. package/dist/emailtokens.d.ts.map +1 -0
  29. package/dist/index.cjs +9107 -0
  30. package/dist/index.d.ts +46 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +9090 -0
  33. package/dist/oauth/authserver.d.ts +490 -0
  34. package/dist/oauth/authserver.d.ts.map +1 -0
  35. package/dist/oauth/client.d.ts +72 -0
  36. package/dist/oauth/client.d.ts.map +1 -0
  37. package/dist/oauth/clientmanager.d.ts +73 -0
  38. package/dist/oauth/clientmanager.d.ts.map +1 -0
  39. package/dist/oauth/resserver.d.ts +43 -0
  40. package/dist/oauth/resserver.d.ts.map +1 -0
  41. package/dist/oauth/tests/common.d.ts +58 -0
  42. package/dist/oauth/tests/common.d.ts.map +1 -0
  43. package/dist/oauth/tests/oauthauthserver_authzcode.test.d.ts +2 -0
  44. package/dist/oauth/tests/oauthauthserver_authzcode.test.d.ts.map +1 -0
  45. package/dist/oauth/tests/oauthauthserver_clientcred.test.d.ts +2 -0
  46. package/dist/oauth/tests/oauthauthserver_clientcred.test.d.ts.map +1 -0
  47. package/dist/oauth/tests/oauthauthserver_device.test.d.ts +2 -0
  48. package/dist/oauth/tests/oauthauthserver_device.test.d.ts.map +1 -0
  49. package/dist/oauth/tests/oauthauthserver_mfa.test.d.ts +5 -0
  50. package/dist/oauth/tests/oauthauthserver_mfa.test.d.ts.map +1 -0
  51. package/dist/oauth/tests/oauthauthserver_password.test.d.ts +2 -0
  52. package/dist/oauth/tests/oauthauthserver_password.test.d.ts.map +1 -0
  53. package/dist/oauth/tests/oauthclient.test.d.ts +2 -0
  54. package/dist/oauth/tests/oauthclient.test.d.ts.map +1 -0
  55. package/dist/oauth/tests/oauthresserver.test.d.ts +2 -0
  56. package/dist/oauth/tests/oauthresserver.test.d.ts.map +1 -0
  57. package/dist/oauth/tokenconsumer.d.ts +80 -0
  58. package/dist/oauth/tokenconsumer.d.ts.map +1 -0
  59. package/dist/session.d.ts +491 -0
  60. package/dist/session.d.ts.map +1 -0
  61. package/dist/storage/dbconnection.d.ts +19 -0
  62. package/dist/storage/dbconnection.d.ts.map +1 -0
  63. package/dist/storage/dbstorage.d.ts +319 -0
  64. package/dist/storage/dbstorage.d.ts.map +1 -0
  65. package/dist/storage/inmemorystorage.d.ts +225 -0
  66. package/dist/storage/inmemorystorage.d.ts.map +1 -0
  67. package/dist/storage/ldapstorage.d.ts +143 -0
  68. package/dist/storage/ldapstorage.d.ts.map +1 -0
  69. package/dist/storage/postgresconnection.d.ts +27 -0
  70. package/dist/storage/postgresconnection.d.ts.map +1 -0
  71. package/dist/storage/postgresstorage.d.ts +83 -0
  72. package/dist/storage/postgresstorage.d.ts.map +1 -0
  73. package/dist/storage/prismastorage.d.ts +361 -0
  74. package/dist/storage/prismastorage.d.ts.map +1 -0
  75. package/dist/storage/sqliteconnection.d.ts +35 -0
  76. package/dist/storage/sqliteconnection.d.ts.map +1 -0
  77. package/dist/storage/sqlitestorage.d.ts +83 -0
  78. package/dist/storage/sqlitestorage.d.ts.map +1 -0
  79. package/dist/storage/tests/dbtests.d.ts +5 -0
  80. package/dist/storage/tests/dbtests.d.ts.map +1 -0
  81. package/dist/storage/tests/inmemorystorage.test.d.ts +5 -0
  82. package/dist/storage/tests/inmemorystorage.test.d.ts.map +1 -0
  83. package/dist/storage/tests/inmemorytestdata.d.ts +4 -0
  84. package/dist/storage/tests/inmemorytestdata.d.ts.map +1 -0
  85. package/dist/storage/tests/ldapstorage.test.d.ts +2 -0
  86. package/dist/storage/tests/ldapstorage.test.d.ts.map +1 -0
  87. package/dist/storage/tests/postgresstorage.test.d.ts +2 -0
  88. package/dist/storage/tests/postgresstorage.test.d.ts.map +1 -0
  89. package/dist/storage/tests/prismastorage.test.d.ts +4 -0
  90. package/dist/storage/tests/prismastorage.test.d.ts.map +1 -0
  91. package/dist/storage/tests/sqlitestorage.test.d.ts +2 -0
  92. package/dist/storage/tests/sqlitestorage.test.d.ts.map +1 -0
  93. package/dist/storage.d.ts +411 -0
  94. package/dist/storage.d.ts.map +1 -0
  95. package/dist/tests/cookieauth.test.d.ts +4 -0
  96. package/dist/tests/cookieauth.test.d.ts.map +1 -0
  97. package/dist/tests/crypto.test.d.ts +2 -0
  98. package/dist/tests/crypto.test.d.ts.map +1 -0
  99. package/dist/tests/email.test.d.ts +4 -0
  100. package/dist/tests/email.test.d.ts.map +1 -0
  101. package/dist/tests/password.test.d.ts +5 -0
  102. package/dist/tests/password.test.d.ts.map +1 -0
  103. package/dist/tests/tmp.test.d.ts +2 -0
  104. package/dist/tests/tmp.test.d.ts.map +1 -0
  105. package/dist/tests/utils.test.d.ts +2 -0
  106. package/dist/tests/utils.test.d.ts.map +1 -0
  107. package/dist/utils.d.ts +41 -0
  108. package/dist/utils.d.ts.map +1 -0
  109. 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
+ }
178
+ //# sourceMappingURL=emailtokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emailtokens.d.ts","sourceRoot":"","sources":["../src/emailtokens.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAKpD,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAK9C,MAAM,WAAW,mBAAmB;IAEhC,0GAA0G;IAC1G,OAAO,CAAC,EAAG,MAAM,CAAC;IAElB,mGAAmG;IACnG,MAAM,CAAC,EAAG,MAAM,CAAC;IAEjB,sEAAsE;IACtE,KAAK,CAAC,EAAG,MAAM,CAAC;IAEhB,wGAAwG;IACxG,yBAAyB,CAAC,EAAG,MAAM,CAAC;IAEpC,wGAAwG;IACxG,yBAAyB,CAAC,EAAG,MAAM,CAAC;IAEpC,mDAAmD;IACnD,wBAAwB,CAAC,EAAG,MAAM,CAAC;IAEnC,oGAAoG;IACpG,qBAAqB,CAAC,EAAG,MAAM,CAAC;IAEhC,oGAAoG;IACpG,qBAAqB,CAAC,EAAG,MAAM,CAAC;IAEhC,+CAA+C;IAC/C,oBAAoB,CAAC,EAAG,MAAM,CAAC;IAE/B,wBAAwB;IACxB,SAAS,CAAC,EAAG,MAAM,CAAC;IAEpB,oEAAoE;IACpE,QAAQ,CAAC,EAAG,MAAM,CAAC;IAEnB,sDAAsD;IACtD,QAAQ,CAAC,EAAG,MAAM,CAAC;IAEnB,oEAAoE;IACpE,UAAU,CAAC,EAAG,OAAO,CAAC;IAEtB,kEAAkE;IAClE,YAAY,CAAC,EAAG,MAAM,CAAC;IAEvB,k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