mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2026-07-24 21:12:10 +00:00
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:
+10
-3
@@ -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});
|
||||
|
||||
@@ -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};
|
||||
|
||||
Reference in New Issue
Block a user