51 lines
1.1 KiB
JavaScript
51 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
|
|
let clientId = ""
|
|
let clientSecret = ""
|
|
let 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"
|
|
}
|
|
)
|
|
clientId = raw.data['client_id']
|
|
|
|
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 register()
|
|
//await fetchToken()
|
|
} catch(err) {
|
|
console.log(err.message)
|
|
console.log(err.response?.data)
|
|
}
|
|
})()
|
|
|