From c0ab195eedfd5eabfc459b59a9fc7298d8d4232f Mon Sep 17 00:00:00 2001 From: Ersun Warncke Date: Thu, 9 May 2019 06:07:38 -0400 Subject: [PATCH] fix auth error response and use 401 for malformed header GitOrigin-RevId: 6dc4d10c25db7710b3e4e8e876d425a1e84574c8 --- .../Features/Authentication/AuthenticationController.coffee | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/web/app/coffee/Features/Authentication/AuthenticationController.coffee b/services/web/app/coffee/Features/Authentication/AuthenticationController.coffee index 1086a2d634..de29316df5 100644 --- a/services/web/app/coffee/Features/Authentication/AuthenticationController.coffee +++ b/services/web/app/coffee/Features/Authentication/AuthenticationController.coffee @@ -194,10 +194,12 @@ module.exports = AuthenticationController = response = new Oauth2Server.Response(res) Oauth2Server.server.authenticate request, response, {}, (err, token) -> if err? + # use a 401 status code for malformed header for git-bridge + err.code = 401 if err.code == 400 and err.message == 'Invalid request: malformed authorization header' # fall back to v1 on invalid token return AuthenticationController._requireOauthV1Fallback req, res, next if err.code == 401 - # bubble up all other errors - return next(err) + # send all other errors + return res.status(err.code).json({error: err.name, error_description: err.message}) req.oauth = access_token: token.accessToken req.oauth_token = token