Skip to content

Commit

Permalink
fix(express-tooling): pass logger to getTokenInfo and log error (#218)
Browse files Browse the repository at this point in the history
* pass logger to getTokenInfo and log error
* pass error to the 2nd arg of logger
* bump version in package.json

close #211
  • Loading branch information
shuhei authored and bzums committed Jun 6, 2018
1 parent 6a4ad30 commit e47c422
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "authmosphere",
"version": "2.0.5",
"version": "2.0.6",
"description": "authmosphere is a library to support OAuth2 workflows in JavaScript projects.",
"main": "./lib/src/index.js",
"typings": "./lib/src/index.d.ts",
Expand Down
9 changes: 6 additions & 3 deletions src/express-tooling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const requireScopesMiddleware: requireScopesMiddleware =

precedenceFunction(request, response, nextFunction)
.catch(error => {
logOrNothing.warn(`Error while executing precedenceFunction: ${error}`);
logOrNothing.warn('Error while executing precedenceFunction', error);
// PrecedencFunction was not successful
// false -> trigger fallback to default scope validation
return false;
Expand Down Expand Up @@ -199,12 +199,15 @@ const authenticationMiddleware: authenticationMiddleware = (options) => {
notAuthenticatedHandler(res, logOrNothing, HttpStatus.UNAUTHORIZED);
return;
} else {
getTokenInfo(tokenInfoEndpoint, accessToken)
getTokenInfo(tokenInfoEndpoint, accessToken, logger)
.then(setTokeninfo(req))
.then(next)
// TODO we should send 500 for issues with network etc.
// we should send HttpStatus.UNAUTHORIZED for invalid token
.catch(err => notAuthenticatedHandler(res, logOrNothing, HttpStatus.UNAUTHORIZED));
.catch(error => {
logOrNothing.warn('Error while getting token info', error);
notAuthenticatedHandler(res, logOrNothing, HttpStatus.UNAUTHORIZED);
});
}
};

Expand Down

0 comments on commit e47c422

Please sign in to comment.