@crossauth/backend 1.1.7 → 1.1.9
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/dist/cookieauth.d.ts +128 -4
- package/dist/cookieauth.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +1573 -1359
- package/dist/oauth/authserver.d.ts +1 -3
- package/dist/oauth/authserver.d.ts.map +1 -1
- package/dist/session.d.ts +34 -1
- package/dist/session.d.ts.map +1 -1
- package/dist/storage/prismastorage.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/cookieauth.d.ts
CHANGED
|
@@ -113,17 +113,15 @@ export declare class DoubleSubmitCsrfToken {
|
|
|
113
113
|
validateCsrfCookie(cookieValue: string): string;
|
|
114
114
|
}
|
|
115
115
|
/**
|
|
116
|
-
* Options for
|
|
116
|
+
* Options for session cookies
|
|
117
117
|
*/
|
|
118
118
|
export interface SessionCookieOptions extends CookieOptions, TokenEmailerOptions {
|
|
119
119
|
/**
|
|
120
120
|
* If user login is enabled, you must provide the user storage class
|
|
121
121
|
*/
|
|
122
122
|
userStorage?: UserStorage;
|
|
123
|
-
/** Name of cookie. Defaults to "
|
|
123
|
+
/** Name of cookie. Defaults to "SESSIONID" */
|
|
124
124
|
cookieName?: string;
|
|
125
|
-
/** If true, session IDs are stored in hashed form in the key storage. Default false. */
|
|
126
|
-
hashSessionId?: boolean;
|
|
127
125
|
/** If non zero, sessions will time out after this number of seconds have elapsed without activity. Default 0 (no timeout) */
|
|
128
126
|
idleTimeout?: number;
|
|
129
127
|
/** If true, sessions cookies will be persisted between browser sessions. Default true */
|
|
@@ -264,4 +262,130 @@ export declare class SessionCookie {
|
|
|
264
262
|
*/
|
|
265
263
|
deleteAllForUser(userid: string | number, except: string | undefined): Promise<void>;
|
|
266
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Options for known device cookies
|
|
267
|
+
*/
|
|
268
|
+
export interface KnownDeviceCookieOptions extends CookieOptions {
|
|
269
|
+
/** Name of cookie. Defaults to "KNOWNDEVICE" */
|
|
270
|
+
cookieName?: string;
|
|
271
|
+
/** App secret */
|
|
272
|
+
secret?: string;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Class for creating and validating cookies to prevent 2FA on known devices
|
|
276
|
+
*/
|
|
277
|
+
export declare class KnownDeviceCookie {
|
|
278
|
+
private keyStorage;
|
|
279
|
+
/** Name of the CSRF Cookie, set from input options */
|
|
280
|
+
readonly cookieName: string;
|
|
281
|
+
readonly maxAge: number;
|
|
282
|
+
readonly domain: string | undefined;
|
|
283
|
+
readonly httpOnly: boolean;
|
|
284
|
+
readonly path: string;
|
|
285
|
+
readonly secure: boolean;
|
|
286
|
+
readonly sameSite: boolean | "lax" | "strict" | "none" | undefined;
|
|
287
|
+
private secret;
|
|
288
|
+
/**
|
|
289
|
+
* Constructor.
|
|
290
|
+
*
|
|
291
|
+
* @param keyStorage where to put session IDs
|
|
292
|
+
* @param options configurable options. See {@link SessionCookieOptions}. The
|
|
293
|
+
* expires option is ignored (cookies are session-only).
|
|
294
|
+
*/
|
|
295
|
+
constructor(keyStorage: KeyStorage, options?: KnownDeviceCookieOptions);
|
|
296
|
+
private expiry;
|
|
297
|
+
/**
|
|
298
|
+
* Returns a hash of a session ID, with the session ID prefix for storing
|
|
299
|
+
* in the storage table.
|
|
300
|
+
* @param value the value to hash
|
|
301
|
+
* @returns a base64-url-encoded string that can go into the storage
|
|
302
|
+
*/
|
|
303
|
+
static hashValue(value: string): string;
|
|
304
|
+
/**
|
|
305
|
+
* Creates a cookie value and saves in storage
|
|
306
|
+
*
|
|
307
|
+
* Date created is the current date/time on the server.
|
|
308
|
+
*
|
|
309
|
+
* In the unlikely event of the key already existing, it is retried up to 10 times before throwing
|
|
310
|
+
* an error with ErrorCode.KeyExists
|
|
311
|
+
*
|
|
312
|
+
* @param userid the user ID to store with the value.
|
|
313
|
+
* @returns the new cookie value
|
|
314
|
+
* @throws {@link @crossauth/common!CrossauthError} with
|
|
315
|
+
* {@link @crossauth/common!ErrorCode} `KeyExists` if maximum
|
|
316
|
+
* attempts exceeded trying to create a unique session id
|
|
317
|
+
*/
|
|
318
|
+
createValue(userid: string | number): Promise<Key>;
|
|
319
|
+
updateUser(cookieValue: string, userid: string | number): Promise<void>;
|
|
320
|
+
removeUser(cookieValue: string, userid: string | number): Promise<void>;
|
|
321
|
+
/**
|
|
322
|
+
* Returns a {@link Cookie } object with the given session key.
|
|
323
|
+
*
|
|
324
|
+
* This class is compatible, for example, with Express.
|
|
325
|
+
*
|
|
326
|
+
* @param knownDeviceKey the value of the known device cookie
|
|
327
|
+
* @returns a {@link Cookie } object,
|
|
328
|
+
*/
|
|
329
|
+
makeCookie(knownDeviceKey: Key): Cookie;
|
|
330
|
+
/**
|
|
331
|
+
* Takes a session ID and creates a string representation of the cookie
|
|
332
|
+
* (value of the HTTP `Cookie` header).
|
|
333
|
+
*
|
|
334
|
+
* @param cookie the cookie vlaues to make a string from
|
|
335
|
+
* @returns a string representation of the cookie and options.
|
|
336
|
+
*/
|
|
337
|
+
makeCookieString(cookie: Cookie): string;
|
|
338
|
+
/**
|
|
339
|
+
* Updates a session record in storage
|
|
340
|
+
* @param knownDeviceKey the fields to update. `value` must be set, and
|
|
341
|
+
* will not be updated. All other defined fields will be updated.
|
|
342
|
+
* @throws {@link @crossauth/common!CrossauthError} if the session does
|
|
343
|
+
* not exist.
|
|
344
|
+
*/
|
|
345
|
+
updateKnownDeviceKey(knownDeviceKey: Partial<Key>): Promise<void>;
|
|
346
|
+
/**
|
|
347
|
+
* Unsigns a cookie and returns the original value.
|
|
348
|
+
* @param cookieValue the signed cookie value
|
|
349
|
+
* @returns the unsigned value
|
|
350
|
+
* @throws {@link @crossauth/common!CrossauthError} if the signature
|
|
351
|
+
* is invalid.
|
|
352
|
+
*/
|
|
353
|
+
unsignCookie(cookieValue: string): string;
|
|
354
|
+
/**
|
|
355
|
+
* Returns the user matching the given session key in session storage, or throws an exception.
|
|
356
|
+
*
|
|
357
|
+
* Looks the user up in the {@link UserStorage} instance passed to the constructor.
|
|
358
|
+
*
|
|
359
|
+
* Undefined will also fail is CookieAuthOptions.filterFunction is defined and returns false,
|
|
360
|
+
*
|
|
361
|
+
* @param sessionId the value in the session cookie
|
|
362
|
+
* @param options See {@link UserStorageGetOptions}
|
|
363
|
+
* @returns a {@link @crossauth/common!User } object, with the password hash removed, and the {@link @crossauth/common!Key } with the unhashed
|
|
364
|
+
* sessionId
|
|
365
|
+
* @throws a {@link @crossauth/common!CrossauthError } with {@link @crossauth/common!ErrorCode } set to `InvalidSessionId` or `Expired`.
|
|
366
|
+
*/
|
|
367
|
+
getUsersForKnownDeviceKey(knownDeviceKey: string): Promise<{
|
|
368
|
+
[key: string | number]: Date;
|
|
369
|
+
}>;
|
|
370
|
+
/**
|
|
371
|
+
* Returns the user matching the given session key in session storage, or throws an exception.
|
|
372
|
+
*
|
|
373
|
+
* Looks the user up in the {@link UserStorage} instance passed to the constructor.
|
|
374
|
+
*
|
|
375
|
+
* Undefined will also fail is CookieAuthOptions.filterFunction is defined and returns false,
|
|
376
|
+
*
|
|
377
|
+
* @param sessionId the unsigned value of the session cookie
|
|
378
|
+
* @returns a {@link User } object, with the password hash removed.
|
|
379
|
+
* @throws a {@link @crossauth/common!CrossauthError } with
|
|
380
|
+
* {@link @crossauth/common!ErrorCode } set to `InvalidSessionId`,
|
|
381
|
+
* `Expired` or `UserNotExist`.
|
|
382
|
+
*/
|
|
383
|
+
getKnownDeviceKey(value: string): Promise<Key>;
|
|
384
|
+
/**
|
|
385
|
+
* Deletes all keys for the given user
|
|
386
|
+
* @param userid the user to delete keys for
|
|
387
|
+
* @param except if defined, don't delete this key
|
|
388
|
+
*/
|
|
389
|
+
deleteAllForUser(userid: string | number, except: string | undefined): Promise<void>;
|
|
390
|
+
}
|
|
267
391
|
//# sourceMappingURL=cookieauth.d.ts.map
|
package/dist/cookieauth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookieauth.d.ts","sourceRoot":"","sources":["../src/cookieauth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAGnD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAC3E,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAI5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"cookieauth.d.ts","sourceRoot":"","sources":["../src/cookieauth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAGnD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAC3E,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAI5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAC;AAMhD;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAE1B,MAAM,CAAC,EAAG,MAAM,CAAC;IACjB,OAAO,CAAC,EAAG,IAAI,CAAC;IAChB,MAAM,CAAC,EAAG,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAG,OAAO,CAAC;IACpB,IAAI,CAAC,EAAG,MAAM,CAAC;IACf,MAAM,CAAC,EAAG,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAG,OAAO,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;CAC/D;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAG,aAAa,GAAI,sBAAsB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;CAAE,CAM7G;AAED;;GAEG;AACH,MAAM,WAAW,MAAM;IACnB,IAAI,EAAG,MAAM,CAAC;IACd,KAAK,EAAG,MAAM,CAAC;IACf,OAAO,E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