Spaces:
Running
Running
File size: 1,460 Bytes
b39afbe |
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 44 45 46 47 48 49 50 51 |
/**
* Copyright (c) 2023 MERCENARIES.AI PTE. LTD.
* All rights reserved.
*/
const script = {
name: 'generateJwtToken',
exec: async function (ctx, payload) {
// const ability = new PermissionChecker(ctx.session.get('permission'))
// if (!ability) {
// throw new Error('Action not permitted')
// }
// // Scope will be either:
// // 1. Execute a workflow
// // 2. Adding user to an org
// for (const scope of scopes) {
// const { action, subject, orgId, workflowIds } = scope
// // Requested scope should match the user's permission
// if (!ability.can(action, subject)) {
// integration.debug('Action not permitted: ', action, subject)
// throw new Error('Action not permitted')
// }
// }
const [action, subject, workflowId, expiresIn] = payload
const scopes = [
{
action,
subject,
conditions: {
id: workflowId
}
}
]
// @ts-ignore
const user = ctx.user
const sessionId = ctx.session.sessionId
const integration = ctx.app.integrations.get('auth')
const token = await integration.generateJwtToken(scopes, user, parseInt(expiresIn))
ctx.app.sendMessageToSession(sessionId, `Generated token: ${token}`, 'text/plain')
return true
}
}
export default script
|