Revert "Revert "fix auth error response and use 401 for malformed header""

This reverts commit 5d25af9026159b0c1e0a53f0d1fd0d9c685b40ee.

GitOrigin-RevId: d5cc2fd2e7a676cad637717d77d1a69a7fe6453c
This commit is contained in:
Ersun Warncke 2019-05-14 05:27:45 -04:00 committed by sharelatex
parent 7883554d73
commit 8e916a830d

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