more app stuff
This commit is contained in:
parent
dcd41fa7d5
commit
23db830da3
1 changed files with 45 additions and 11 deletions
54
index.js
54
index.js
|
|
@ -8,14 +8,14 @@ const videoId = process.env.VIDEO_ID;
|
||||||
|
|
||||||
//const botBearer = fs.readFileSync(botBearerFile, 'utf-8');
|
//const botBearer = fs.readFileSync(botBearerFile, 'utf-8');
|
||||||
//const userBearer = fs.readFileSync(userBearerFile, 'utf-8');
|
//const userBearer = fs.readFileSync(userBearerFile, 'utf-8');
|
||||||
const botBearer = ''
|
const botBearer = '';
|
||||||
const userBearer = ''
|
const userBearer = '';
|
||||||
|
|
||||||
const globalState = {
|
const globalState = {
|
||||||
exit: false,
|
exit: false,
|
||||||
currentlyLive: false,
|
currentlyLive: false,
|
||||||
};
|
};
|
||||||
console.log(userBearer.trim())
|
console.log(userBearer.trim());
|
||||||
|
|
||||||
const headers = (bearer) => ({
|
const headers = (bearer) => ({
|
||||||
accept: 'application/json',
|
accept: 'application/json',
|
||||||
|
|
@ -40,10 +40,10 @@ const app = await fetch(`https://${instance}/api/v1/apps`, {
|
||||||
}),
|
}),
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
})
|
});
|
||||||
console.log('APP REG STATUS', app.status)
|
console.log('APP REG STATUS', app.status);
|
||||||
const { client_id, client_secret } = await app.json()
|
const { client_id, client_secret } = await app.json();
|
||||||
console.log({ client_id, client_secret })
|
console.log({ client_id, client_secret });
|
||||||
|
|
||||||
const bearer = await fetch(`https://${instance}/oauth/token`, {
|
const bearer = await fetch(`https://${instance}/oauth/token`, {
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -59,9 +59,43 @@ const bearer = await fetch(`https://${instance}/oauth/token`, {
|
||||||
}),
|
}),
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
})
|
});
|
||||||
console.log('TOKEN STATUS', bearer.status)
|
console.log('TOKEN STATUS', bearer.status);
|
||||||
console.log('TOKEN RESPONSE', await bearer.json())
|
console.log('TOKEN RESPONSE', await bearer.json());
|
||||||
|
const data = {
|
||||||
|
response_type: 'code',
|
||||||
|
client_id,
|
||||||
|
redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
|
||||||
|
scope: 'write:scrobbles',
|
||||||
|
};
|
||||||
|
|
||||||
|
const dataString = Object.entries(data).reduce((acc, [k, v]) => {
|
||||||
|
const encoded = `${k}=${encodeURIComponent(v)}`;
|
||||||
|
if (!acc) {
|
||||||
|
return encoded;
|
||||||
|
} else {
|
||||||
|
return `${acc}&${encoded}`;
|
||||||
|
}
|
||||||
|
}, '');
|
||||||
|
|
||||||
|
console.log(`AUTH: ${instance}/oauth/authorize?${dataString}`);
|
||||||
|
|
||||||
|
const auth = await fetch(`https://${instance}/oauth/authorize`, {
|
||||||
|
headers: {
|
||||||
|
accept: 'application/json',
|
||||||
|
'cache-control': 'no-cache',
|
||||||
|
'content-type': 'application/json',
|
||||||
|
pragma: 'no-cache',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
client_id,
|
||||||
|
response_type: 'code',
|
||||||
|
grant_type: 'client_credentials',
|
||||||
|
redirect_uris: 'urn:ietf:wg:oauth:2.0:oob',
|
||||||
|
}),
|
||||||
|
method: 'POST',
|
||||||
|
mode: 'cors',
|
||||||
|
});
|
||||||
/* */
|
/* */
|
||||||
|
|
||||||
const post = ({
|
const post = ({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue