fix auth error response and use 401 for malformed header

GitOrigin-RevId: 6dc4d10c25db7710b3e4e8e876d425a1e84574c8
This commit is contained in:
Ersun Warncke 2019-05-09 06:07:38 -04:00 committed by sharelatex
parent dc06069dff
commit c0ab195eed

View file

@ -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