mirror of
https://github.com/tribufu/sdk-js
synced 2025-06-15 18:24:19 +00:00
Fix client headers
This commit is contained in:
@ -8,11 +8,8 @@ dotenv.config();
|
|||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const client = TribufuClient.fromEnv("TRIBUFU");
|
const client = TribufuClient.fromEnv("TRIBUFU");
|
||||||
|
const games = await client.getServers();
|
||||||
if (await client.passwordLogin("", "")) {
|
console.log(games);
|
||||||
const userInfo = await client.getUserInfo();
|
|
||||||
console.log(userInfo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
@ -136,7 +136,7 @@ export class TribufuApi {
|
|||||||
* Get the default headers for the Tribufu API.
|
* Get the default headers for the Tribufu API.
|
||||||
* @returns HeaderMap
|
* @returns HeaderMap
|
||||||
*/
|
*/
|
||||||
private static defaultHeaders(): HttpHeaders {
|
protected static defaultHeaders(): HttpHeaders {
|
||||||
const headers = new HttpHeaders();
|
const headers = new HttpHeaders();
|
||||||
headers.set("X-Tribufu-Language", "javascript");
|
headers.set("X-Tribufu-Language", "javascript");
|
||||||
headers.set("X-Tribufu-Version", TRIBUFU_VERSION);
|
headers.set("X-Tribufu-Version", TRIBUFU_VERSION);
|
||||||
|
@ -126,6 +126,22 @@ export class TribufuClient extends TribufuApi {
|
|||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current headers with the api key or access token.
|
||||||
|
* @returns HeaderMap
|
||||||
|
*/
|
||||||
|
protected override getHeaders(): HttpHeaders {
|
||||||
|
let headers = TribufuClient.defaultHeaders();
|
||||||
|
headers.set("Authorization", `Basic ${Buffer.from(`${this.clientId}:${this.clientSecret}`, "binary").toString("base64")}`);
|
||||||
|
|
||||||
|
if (this.options.accessToken) {
|
||||||
|
headers.set("Authorization", `Bearer ${this.options.accessToken}`);
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the client id.
|
* Get the client id.
|
||||||
* @returns string
|
* @returns string
|
||||||
|
Reference in New Issue
Block a user