module.exports.getCredentialsFromToken = function()

in source/shared-modules/token-manager/token-manager.js [169:199]


module.exports.getCredentialsFromToken = function(req, updateCredentials) {
    var bearerToken = req.get('Authorization');
    if (bearerToken) {
        var tokenValue = bearerToken.substring(bearerToken.indexOf(' ') + 1);
        if (!(tokenValue in tokenCache)) {
            var decodedIdToken = jwtDecode(tokenValue);
            var userName = decodedIdToken['cognito:username'];
            async.waterfall([
                function(callback) {
                    getUserPoolWithParams(userName, callback)
                },
                function(userPool, callback) {
                    authenticateUserInPool(userPool, tokenValue, callback)
                }
            ], function(error, results) {
                if (error) {
                    winston.error('Error fetching credentials for user')
                    updateCredentials(null);
                }
                else {
                    tokenCache[tokenValue] = results;
                    updateCredentials(results);
                }
            });
        }
        else if (tokenValue in tokenCache) {
            winston.debug('Getting credentials from cache');
            updateCredentials(tokenCache[tokenValue]);
        }
    }
};