forked from mybricks/apaas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenapi-sign.js
37 lines (28 loc) · 1.13 KB
/
openapi-sign.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
const Log = require('./utils/log')
const { readUserConfig } = require('./shared');
const { getAccessToken, verifyAccessToken } = require('./shared/access-token')
const openApiLog = Log('MyBricks: openApi授权')
const userConfig = readUserConfig();
async function main () {
if (!userConfig?.openApi?.tokenSecretOrPrivateKey) {
openApiLog.error('当前未配置 openApi.tokenSecretOrPrivateKey,请检查配置文件')
return
}
if (!Array.isArray(userConfig?.openApi?.accessApps) || userConfig?.openApi?.accessApps.length < 1) {
openApiLog.error('当前未配置 openApi.accessApps 或者 需要授权的应用数小于一个')
return
}
let printString = '';
const apps = userConfig?.openApi?.accessApps;
for (let index = 0; index < apps.length; index++) {
const app = apps[index];
if (app.appId) {
const token = await getAccessToken({ appId: app.appId }, userConfig?.openApi?.tokenSecretOrPrivateKey)
printString += `应用ID:${app.appId}\n授权token:${token}
`
}
}
openApiLog.log('当前授权应用token如下:\n')
console.log(printString)
}
main().catch(console.error)