Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.

Commit

Permalink
Fix: local validation forced on client-credential tokens
Browse files Browse the repository at this point in the history
If local validation was specified for the JwtAuthenticator, it would also force the client-credential-based tokens through the JwtAuthenticator, which is not what we want
  • Loading branch information
Robert committed Mar 24, 2016
1 parent 72d6c1b commit 64c69c6
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions lib/jwt/jwt-authenticator.js
Expand Up @@ -43,17 +43,20 @@ JwtAuthenticator.prototype.authenticate = function authenticate(token,cb){
err.statusCode = 401;
cb(err);
}else{
if(self.localValidation){
cb(null, new JwtAuthenticationResult(self.application,{
jwt: token,
expandedJwt: jwt,
localValidation: true,
account: {
href: jwt.body.sub
}
}));
}else if(jwt.header.kid){
// If the KID exists, this was issued by our API

// If the KID exists, this was issued by our API from a password grant

if(jwt.header.kid){
if(self.localValidation){
return cb(null, new JwtAuthenticationResult(self.application,{
jwt: token,
expandedJwt: jwt,
localValidation: true,
account: {
href: jwt.body.sub
}
}));
}
var href = self.application.href + '/authTokens/' + token;
self.application.dataStore.getResource(href,function(err,response){
if(err){
Expand All @@ -64,9 +67,9 @@ JwtAuthenticator.prototype.authenticate = function authenticate(token,cb){
});
}else{

// If there is no KID, this means it was
// issued by the SDK (not the API) so we have
// to do remote validation in a different way
// If there is no KID, this means it was issued by the SDK (not the
// API) from a client credentials grant so we have to do remote
// validation in a different way.
var authenticator = new OauthAccessTokenAuthenticator(self.application, token);
authenticator.authenticate(cb);
}
Expand Down

0 comments on commit 64c69c6

Please sign in to comment.