47 lines
938 B
TypeScript
47 lines
938 B
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({ type: 'text', nullable: true })
|
|
scope: string;
|
|
|
|
@ManyToOne(() => User, { nullable: true })
|
|
user: User;
|
|
|
|
@ManyToOne(() => OAuth2Client)
|
|
client: OAuth2Client;
|
|
|
|
@Column({ type: 'timestamp' })
|
|
public expires_at: Date;
|
|
|
|
@CreateDateColumn()
|
|
public created_at: Date;
|
|
|
|
@UpdateDateColumn()
|
|
public updated_at: Date;
|
|
}
|