Adds support for several auth tokens

This commit is contained in:
Raul Ochoa
2014-07-08 10:35:45 +02:00
parent f756b9d77f
commit 67df6a4d73
+2 -6
View File
@@ -128,6 +128,7 @@ console.log("Cert is : "); console.dir(cert);
// Check if the given certificate authorizes waiver of "auth"
o.authorizedByCert = function(cert, auth) {
auth = _.isArray(auth) ? auth : [auth];
var err = this.checkInvalidCertificate(cert);
if ( err ) throw err;
@@ -139,12 +140,7 @@ o.authorizedByCert = function(cert, auth) {
// Token based authentication requires valid token
if ( method === 'token' ) {
var found = cert.auth.valid_tokens.indexOf(auth);
//if ( found !== -1 ) {
//console.log("Token " + auth + " is found at position " + found + " in valid tokens " + cert.auth.valid_tokens);
// return true;
//} else return false;
return cert.auth.valid_tokens.indexOf(auth) !== -1;
return _.intersection(cert.auth.valid_tokens, auth).length > 0;
}
throw new Error("Unsupported authentication method: " + cert.auth.method);