plerobuddies/src/registerApp.js

49 lines
1.1 KiB
JavaScript

const axios = require('axios')
const instance = 'https://chat.brainbaking.com'
const clientName = "plerobuddies"
// Fill these in after register() ed. calls
const clientId = ""
const clientSecret = ""
const approvalCode = ""
async function register() {
const raw = await axios.post(`${instance}/api/v1/apps`, {
client_name: clientName,
redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
scopes: "read write"
}
)
console.log(raw.data)
console.log(`${instance}/oauth/authorize?redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&client_id=${clientId}&scope=read%20write`)
}
async function fetchToken() {
const raw = await axios.post(`${instance}/oauth/token`, {
client_id: clientId,
client_secret: clientSecret,
redirect_uri: "urn:ietf:wg:oauth:2.0:oob",
scopes: "read write",
grant_type: "authorization_code",
code: approvalCode
}
)
console.log(raw.data)
console.log(raw.data.access_token)
}
(async function() {
try {
await fetchToken()
} catch(err) {
console.log(err.message)
console.log(err.response?.data)
}
})()