chore: Use httpOnly authentication cookie (#5552)

This commit is contained in:
Tom Moor
2023-07-15 16:56:32 -04:00
committed by GitHub
parent b1230d0c81
commit 39e12cef65
16 changed files with 114 additions and 120 deletions

View File

@@ -1,5 +1,5 @@
import crypto from "crypto";
import { addMinutes, subMinutes } from "date-fns";
import { addHours, addMinutes, subMinutes } from "date-fns";
import JWT from "jsonwebtoken";
import { Context } from "koa";
import { Transaction, QueryTypes, SaveOptions, Op } from "sequelize";
@@ -453,6 +453,22 @@ class User extends ParanoidModel {
this.jwtSecret
);
/**
* Returns a session token that is used to make collaboration requests and is
* stored in the client memory.
*
* @returns The session token
*/
getCollaborationToken = () =>
JWT.sign(
{
id: this.id,
expiresAt: addHours(new Date(), 24).toISOString(),
type: "collaboration",
},
this.jwtSecret
);
/**
* Returns a temporary token that is only used for transferring a session
* between subdomains or domains. It has a short expiry and can only be used