1
0
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:
snobu
2020-04-18 15:34:26 +03:00
parent 65847cb29d
commit 609cf43ee0
10 changed files with 125 additions and 114 deletions

View File

@@ -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;
}
}