icynet-auth-server/src/modules/objects/oauth2-token/oauth2-token.entity.ts

53 lines
1.1 KiB
TypeScript

import {
Column,
CreateDateColumn,
Entity,
ManyToOne,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';
import { OAuth2Client } from '../oauth2-client/oauth2-client.entity';
import { User } from '../user/user.entity';
export enum OAuth2TokenType {
CODE = 'code',
ACCESS_TOKEN = 'access_token',
REFRESH_TOKEN = 'refresh_token',
}
@Entity()
export class OAuth2Token {
@PrimaryGeneratedColumn()
id: number;
@Column({ type: 'enum', enum: OAuth2TokenType, nullable: false })
type: OAuth2TokenType;
@Column({ nullable: false, type: 'text' })
token: string;
@Column({ nullable: true, type: 'text' })
nonce: string;
@Column({ nullable: true, type: 'text' })
pcke: string;
@Column({ type: 'text', nullable: true })
scope: string;
@ManyToOne(() => User, { nullable: true, onDelete: 'CASCADE' })
user: User;
@ManyToOne(() => OAuth2Client, { onDelete: 'CASCADE' })
client: OAuth2Client;
@Column({ type: 'timestamp' })
public expires_at: Date;
@CreateDateColumn()
public created_at: Date;
@UpdateDateColumn()
public updated_at: Date;
}