Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions lib/handlers/authenticate-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var Request = require('../request');
var Response = require('../response');
var ServerError = require('../errors/server-error');
var UnauthorizedRequestError = require('../errors/unauthorized-request-error');
var utilFormat = require('util').format;

/**
* Constructor.
Expand Down Expand Up @@ -87,12 +88,21 @@ AuthenticateHandler.prototype.handle = function(request, response) {
return this.updateResponse(response, token);
})
.catch(function(e) {
// Include the "WWW-Authenticate" response header field if the client
// lacks any authentication information.
// Include the "WWW-Authenticate" response header field if the token authentication fails
//
// @see https://tools.ietf.org/html/rfc6750#section-3.1
if (e instanceof UnauthorizedRequestError) {
response.set('WWW-Authenticate', 'Bearer realm="Service"');
if (e instanceof InvalidRequestError || e instanceof InvalidTokenError || e instanceof InsufficientScopeError || e instanceof UnauthorizedRequestError) {

if(e instanceof UnauthorizedRequestError)
{response.set('WWW-Authenticate', 'Bearer realm="Service"');}
else
{
if(e.message)
{response.set('WWW-Authenticate', utilFormat('Bearer realm="Service",error="%s",error_description="%s"',e.name,e.message));}
else
{response.set('WWW-Authenticate', utilFormat('Bearer realm="Service",error="%s"', e.name));}
}

}

if (!(e instanceof OAuthError)) {
Expand Down