Fix some refactiring error. And Add a way to insert admin credentials

This commit is contained in:
2021-07-30 12:40:24 +02:00
parent 6407c1b072
commit 2c6df73d02
2 changed files with 70 additions and 23 deletions

View File

@ -27,21 +27,21 @@ class PeerTubeRequester {
this.password = config.password;
}
private async requestAuthToken(): Promise<any> {
async requestAuthToken(): Promise<any> {
let response = await fetch(
new URL(`/api/v1/oauth-clients/local`, this.domainName)
);
if (!response.ok) {
throw new Error(response.statusText); // CRASH
throw new Error("Cannot get client credentials : " + response.statusText); // CRASH
}
const { client_id: clientId, client_secret: clientSecret } =
await response.json();
const clientInfo: { [key: string]: string } = {
clientId,
clientSecret,
grantType: "password",
responseType: "code",
client_id: clientId,
client_secret: clientSecret,
grant_type: "password",
response_type: "code",
username: this.username,
password: this.password,
};
@ -54,7 +54,7 @@ class PeerTubeRequester {
body: myParams,
});
if (!response.ok) {
throw new Error(response.statusText); // CRASH
throw new Error("Cannot get access Token : " + response.statusText); // CRASH
}
const { access_token: accessToken } = await response.json();
return accessToken;