mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-06-02 07:59:56 -04:00
tokens: Add token creation
Fix token deletion Update plantuml docs Add token validUntil and lastUsed fields Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
cce1626c48
commit
c9751404f7
9 changed files with 113 additions and 35 deletions
|
@ -4,7 +4,13 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { User } from './user.entity';
|
||||
|
||||
@Entity()
|
||||
|
@ -12,6 +18,9 @@ export class AuthToken {
|
|||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column({ unique: true })
|
||||
keyId: string;
|
||||
|
||||
@ManyToOne((_) => User, (user) => user.authTokens)
|
||||
user: User;
|
||||
|
||||
|
@ -24,21 +33,32 @@ export class AuthToken {
|
|||
@Column({ unique: true })
|
||||
accessToken: string;
|
||||
|
||||
@Column({ type: 'date' })
|
||||
validUntil: Date;
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
validUntil: number;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
lastUsed: number;
|
||||
|
||||
public static create(
|
||||
user: User,
|
||||
identifier: string,
|
||||
keyId: string,
|
||||
accessToken: string,
|
||||
validUntil: Date,
|
||||
validUntil?: number,
|
||||
): Pick<AuthToken, 'user' | 'accessToken'> {
|
||||
const newToken = new AuthToken();
|
||||
newToken.user = user;
|
||||
newToken.identifier = identifier;
|
||||
newToken.keyId = keyId;
|
||||
newToken.accessToken = accessToken;
|
||||
newToken.createdAt = new Date();
|
||||
newToken.validUntil = validUntil;
|
||||
if (validUntil !== undefined) {
|
||||
newToken.validUntil = validUntil;
|
||||
}
|
||||
return newToken;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue