added accountIdx and accountHash to req.oauth3

This commit is contained in:
tigerbot 2017-08-10 11:09:39 -06:00
parent a1f514a155
commit de594964b4
1 changed files with 10 additions and 0 deletions

View File

@ -188,11 +188,21 @@ function attachOauth3(req, res, next) {
, url: 'https://oauth3.org/docs/errors#E_NOT_JWT' , url: 'https://oauth3.org/docs/errors#E_NOT_JWT'
}); });
} }
if (!decoded.iss) {
return PromiseA.reject({
message: 'token missing iss'
, code: 'E_MISSING_ISS'
, url: 'https://oauth3.org/docs/errors#E_MISSING_ISS'
});
}
var ppid = decoded.sub || decoded.ppid || decoded.appScopedId; var ppid = decoded.sub || decoded.ppid || decoded.appScopedId;
req.oauth3.encodedToken = token; req.oauth3.encodedToken = token;
req.oauth3.token = decoded; req.oauth3.token = decoded;
req.oauth3.ppid = ppid; req.oauth3.ppid = ppid;
req.oauth3.accountIdx = ppid+'@'+token.iss;
req.oauth3.accountHash = require('crypto').createHash('sha256').update(req.oauth3.accountIdx).digest('base64');
req.oauth3.accountHash = req.oauth3.accountHash.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+/g, '');
req.oauth3.rescope = function (sub) { req.oauth3.rescope = function (sub) {
// TODO: this function is supposed to convert PPIDs of different parties to some account // TODO: this function is supposed to convert PPIDs of different parties to some account