-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathauthorization.js
38 lines (32 loc) · 1.15 KB
/
authorization.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import readline from 'readline'
import Mastodon from '../lib/mastodon'
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
let clientId
let clientSecret
Mastodon.createOAuthApp()
.catch((err) => console.error(err))
.then((res) => {
console.log('Please save \'id\', \'client_id\' and \'client_secret\' in your program and use it from now on!')
console.log(res)
clientId = res.client_id
clientSecret = res.client_secret
return Mastodon.getAuthorizationUrl(clientId, clientSecret)
})
.then((url) => {
console.log('This is the authorization URL. Open it in your browser and authorize with your account!')
console.log(url)
return new Promise((resolve) => {
rl.question('Please enter the code from the website: ', (code) => {
resolve(code)
rl.close()
})
})
})
.then((code) => Mastodon.getAccessToken(clientId, clientSecret, code))
.catch((err) => console.error(err))
.then((accessToken) => {
console.log(`This is the access token. Save it!\n${accessToken}`)
})