import { Serializable } from "../../interfaces/serializable"; import { now } from "../../utils/unix-timestamp"; export interface TokenSetJson { access_token: string; id_token: string; refresh_token: string; scope: string; token_type: string; expires_in: number; created_at: number; } export class TokenSet implements Serializable { public access_token: string; public id_token: string; public refresh_token: string; public scope: string; public token_type: string; public created_at: number; public expires_in: number; constructor(grantResponse: TokenSetJson) { this.access_token = grantResponse.access_token; this.id_token = grantResponse.id_token; this.refresh_token = grantResponse.refresh_token; this.scope = grantResponse.scope; this.token_type = grantResponse.token_type; this.expires_in = grantResponse.expires_in; this.created_at = grantResponse.created_at || now(); } public expired(): boolean { return (this.created_at + this.expires_in) < now(); } public toJson(): TokenSetJson { return { access_token: this.access_token, id_token: this.id_token, refresh_token: this.refresh_token, scope: this.scope, token_type: this.token_type, expires_in: this.expires_in, created_at: this.created_at } } }