jwt contains {scope, permissions, user_sid, account_sid, service_provider_sid}, force_change now in the body of /login response

This commit is contained in:
Dave Horton
2022-10-27 10:50:17 -04:00
parent 35214a04dc
commit 8d303390b7
2 changed files with 11 additions and 5 deletions
+10 -3
View File
@@ -42,19 +42,26 @@ router.post('/', async(req, res) => {
const permissions = p.map((x) => x.name);
const obj = {user_sid: r[0].user_sid, scope: 'admin', force_change, permissions};
if (r[0].service_provider_sid) {
obj.scope = 'service-provider';
obj.scope = 'service_provider';
obj.service_provider_sid = r[0].service_provider_sid;
}
else if (r[0].account_sid) {
obj.scope = 'account';
obj.account_sid = r[0].account_sid;
}
const payload = {
scope: obj.scope,
permissions,
service_provider_sid: obj.service_provider_sid,
account_sid: obj.account_sid,
user_sid: obj.user_sid
};
const token = jwt.sign(
obj,
payload,
process.env.JWT_SECRET,
{ expiresIn: parseInt(process.env.JWT_EXPIRES_IN || 60) * 60 }
);
res.json({token});
res.json({token, ...obj});
}
else {
res.json({user_sid: r[0].user_sid, force_change, token: t[0].token});
+1 -2
View File
@@ -51,8 +51,7 @@ test('speech credentials tests', async(t) => {
const token = jwt.sign({
account_sid,
account_sid,
scope: "account",
scope: 'account',
permissions: ["PROVISION_USERS", "PROVISION_SERVICES", "VIEW_ONLY"]
}, process.env.JWT_SECRET, { expiresIn: '1h' });
const authUser = {bearer: token};