-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient-credentials-token.ts
43 lines (37 loc) · 1.11 KB
/
client-credentials-token.ts
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
41
42
43
import inquirer from 'inquirer'
import { printTable } from 'console-table-printer'
import { SDKPool, InteractionType } from '@roll-network/auth-sdk'
import config from './config.js'
import logger from './logger.js'
const sdkPool = new SDKPool(config)
export const generateClientCredentialsToken = async () => {
try {
await sdkPool.getSDK(InteractionType.ClientCredentials).generateToken()
const token = await sdkPool
.getSDK(InteractionType.ClientCredentials)
.getToken()
printTable([token])
} catch (error) {
logger.fatal(JSON.stringify(error as Error))
}
}
export const refreshClientCredentialsToken = async () => {
try {
const answers = await inquirer.prompt([
{
type: 'confirm',
message: 'Do you want to do force refresh',
name: 'force',
},
])
await sdkPool
.getSDK(InteractionType.ClientCredentials)
.refreshToken(answers.force)
const token = await sdkPool
.getSDK(InteractionType.ClientCredentials)
.getToken()
printTable([token])
} catch (error) {
logger.fatal(JSON.stringify(error as Error))
}
}