From 67df6a4d737a40c240a3dfdd804d03784fba5cc0 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Tue, 8 Jul 2014 10:35:45 +0200 Subject: [PATCH] Adds support for several auth tokens --- lib/cartodb/signed_maps.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/cartodb/signed_maps.js b/lib/cartodb/signed_maps.js index 11cfa72e..43bf13be 100644 --- a/lib/cartodb/signed_maps.js +++ b/lib/cartodb/signed_maps.js @@ -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);