Untitled
unknown
plain_text
a year ago
1.1 kB
2
Indexable
Never
private clientId = '9YxHBeR2nXxzvdQu4HVZ'; private clientSecret = 'uScf4sLEEMFH5KL3suOUEFVqhDZu9c5Fy8Ar5RMSSMxaSp4lRWBK3BVo6w71'; private authorizationHeader: string = Buffer.from( `${this.clientId}:${this.clientSecret}`, ).toString('base64'); private accessToken!: string; private lastUpdateTimeStampOfAccessToken!: number; private timeStampExpiresIn!: number; constructor(private readonly httpService: HttpService) { this.updateAccessToken(); } public async updateAccessToken(): Promise<void> { const response = await firstValueFrom( this.httpService.post( 'https://account.stubhub.com/oauth2/token', { grant_type: 'client_credentials', scope: 'read:events' }, { headers: { 'Content-Type': 'application/x-www-form-urlencoded', Authorization: `Basic ${this.authorizationHeader}`, }, }, ), ); const { expires_in, access_token } = response.data; this.timeStampExpiresIn = expires_in; this.lastUpdateTimeStampOfAccessToken = new Date().valueOf() / 1000; this.accessToken = access_token; }