Feature/jwt auth (#75)

* initial changes for jwt auth

* return permissions as an array of string

* Add JWT expiration environment variable (#74)

* allow fromHost in createCall REST API

* add JWT_EXPIRES_IN=<mins> env variable, 60 mins by default

* add jwt expiration in register.js and signin.js

* fix tests - add permissions and scope to encoded obj in jwt

Co-authored-by: Dave Horton <daveh@beachdognet.com>
Co-authored-by: eglehelms <e.helms@cognigy.com>

* return only the jwt-token in the api response

Co-authored-by: EgleH <egle.helms@gmail.com>
Co-authored-by: eglehelms <e.helms@cognigy.com>
This commit is contained in:
Dave Horton
2022-10-27 07:39:11 -04:00
committed by GitHub
co-authored by eglehelms EgleH
parent 110c4ed0d8
commit 35214a04dc
13 changed files with 234 additions and 68 deletions
+8 -7
View File
@@ -35,20 +35,21 @@ function makeStrategy(logger, retrieveKey) {
debug(err);
logger.info({err}, 'Error checking blacklist for jwt');
}
const {user_sid, account_sid, email, name} = decoded;
//logger.debug({user_sid, account_sid}, 'successfully validated jwt');
const scope = ['account'];
const {user_sid, service_provider_sid, account_sid, email, name, scope, permissions} = decoded;
const user = {
service_provider_sid,
account_sid,
user_sid,
jwt: token,
email,
name,
hasScope: (s) => s === 'account',
hasAdminAuth: false,
hasServiceProviderAuth: false,
hasAccountAuth: true
permissions,
hasScope: (s) => s === scope,
hasAdminAuth: scope === 'admin',
hasServiceProviderAuth: scope === 'service_provider',
hasAccountAuth: scope === 'account'
};
logger.debug({user}, 'successfully validated jwt');
return done(null, user, {scope});
}
});