-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.js
40 lines (40 loc) · 1.23 KB
/
auth.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
39
40
const readline = require('readline')
const { stdin: input, stdout: output } = require('node:process')
const open = require('open')
const rl = readline.createInterface({ input, output })
const { pulsoidApi } = require('./pulsoidApi')
const fs = require('fs')
const pulsoidAuthPage = () => {
return `${pulsoidApi.baseUrl}?client_id=${pulsoidApi.client_id}&redirect_uri=${pulsoidApi.redirect_uri}&response_type=${pulsoidApi.response_type}&scope=${pulsoidApi.scope}&state=${pulsoidApi.state}&response_mode=${pulsoidApi.response_mode}`
}
/**
*
* @param {*} callback
* @returns {Promise<string>}
*/
const StartAuth = async (callback) => {
return new Promise((resolve, reject) => {
console.log('Open Pulsoid Auth Page...')
open(pulsoidAuthPage())
/**
* @type {string}
*/
rl.question('Enter Pulsoid Auth Token: ', (token) => {
if (token == '') {
console.log('no Enter.')
return reject()
}
// 写入到 token.txt
fs.writeFile('token.txt', token, (err) => {
if (err) {
console.log(err)
return reject()
}
console.log('token.txt saved.')
callback && callback(token)
return resolve(token)
})
})
})
}
exports.StartAuth = StartAuth