mirror of
https://github.com/snobu/destreamer.git
synced 2026-01-30 11:52:18 +00:00
v2.0 RELEASE
This commit is contained in:
@@ -2,6 +2,8 @@ import * as fs from 'fs';
|
||||
import { Session } from './Types';
|
||||
import { bgGreen, bgYellow, green } from 'colors';
|
||||
import jwtDecode from 'jwt-decode';
|
||||
import axios from 'axios';
|
||||
import colors from 'colors';
|
||||
|
||||
export class TokenCache {
|
||||
private tokenCacheFile: string = '.token_cache';
|
||||
@@ -53,4 +55,27 @@ export class TokenCache {
|
||||
console.info(green('Fresh access token dropped into .token_cache'));
|
||||
});
|
||||
}
|
||||
|
||||
public async RefreshToken(session: Session): Promise<string | null> {
|
||||
let endpoint = `${session.ApiGatewayUri}refreshtoken?api-version=${session.ApiGatewayVersion}`;
|
||||
|
||||
let response = await axios.get(endpoint,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${session.AccessToken}`
|
||||
}
|
||||
});
|
||||
|
||||
let freshCookie: string | null = null;
|
||||
|
||||
try {
|
||||
let cookie: string = response.headers["set-cookie"].toString();
|
||||
freshCookie = cookie.split(',Authorization_Api=')[0];
|
||||
}
|
||||
catch (e) {
|
||||
console.error(colors.yellow("Error when calling /refreshtoken: Missing or unexpected set-cookie header."));
|
||||
}
|
||||
|
||||
return freshCookie;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user