Repository: auth0/auth0.js
Pull request #284 (2017-01-04 17:52:28)

Fix getSSOData failing due to extra headers


Patch:
diff --git a/package.json b/package.json
index 097398e..5d11761 100644
--- a/package.json
+++ b/package.json
@@ -31,7 +31,7 @@
   "dependencies": {
     "base64-js": "^1.2.0",
     "idtoken-verifier": "^1.0.0",
-    "superagent": "^2.3.0",
+    "superagent": "^3.3.1",
     "url-join": "^1.1.0",
     "winchan": "^0.1.4"
   },
diff --git a/src/authentication/index.js b/src/authentication/index.js
index c0921a3..37657cc 100644
--- a/src/authentication/index.js
+++ b/src/authentication/index.js
@@ -311,7 +311,7 @@ Authentication.prototype.getSSOData = function (withActiveDirectories, cb) {
   url = urljoin(this.baseOptions.rootUrl, 'user', 'ssodata', params);
 
   return this.request
-    .get(url)
+    .get(url, {noHeaders: true})
     .withCredentials()
     .end(responseHandler(cb));
 };
diff --git a/src/helper/request-builder.js b/src/helper/request-builder.js
index e74e0d3..c314d33 100644
--- a/src/helper/request-builder.js
+++ b/src/helper/request-builder.js
@@ -67,7 +67,13 @@ function RequestBuilder(options) {
   this.headers = options.headers || {};
 }
 
-RequestBuilder.prototype.setCommonConfiguration = function (ongoingRequest) {
+RequestBuilder.prototype.setCommonConfiguration = function (ongoingRequest, options) {
+  options = options || {};
+
+  if (options.noHeaders) {
+    return ongoingRequest;
+  }
+
   var headers = this.headers;
   ongoingRequest = ongoingRequest.set('Content-Type', 'application/json');
   Object.keys(this.headers).forEach(function (header) {
@@ -85,16 +91,16 @@ RequestBuilder.prototype.getTelemetryData = function () {
   return base64Url.encode(jsonClientInfo);
 };
 
-RequestBuilder.prototype.get = function (url) {
-  return new RequestObj(this.setCommonConfiguration(request.get(url)));
+RequestBuilder.prototype.get = function (url, options) {
+  return new RequestObj(this.setCommonConfiguration(request.get(url), options));
 };
 
-RequestBuilder.prototype.post = function (url) {
-  return new RequestObj(this.setCommonConfiguration(request.post(url)));
+RequestBuilder.prototype.post = function (url, options) {
+  return new RequestObj(this.setCommonConfiguration(request.post(url), options));
 };
 
-RequestBuilder.prototype.patch = function (url) {
-  return new RequestObj(this.setCommonConfiguration(request.patch(url)));
+RequestBuilder.prototype.patch = function (url, options) {
+  return new RequestObj(this.setCommonConfiguration(request.patch(url), options));
 };
 
 module.exports = RequestBuilder;


Test patch:
diff --git a/test/authentication/authentication.test.js b/test/authentication/authentication.test.js
index 19a4fe9..3a78e7a 100644
--- a/test/authentication/authentication.test.js
+++ b/test/authentication/authentication.test.js
@@ -467,9 +467,7 @@ describe('auth0.authentication', function () {
       stub(request, 'get', function(url) {
         expect(url).to.be('https://me.auth0.com/user/ssodata/')
         return new RequestMock({
-          headers: {
-            'Content-Type': 'application/json'
-          },
+          headers: {},
           cb: function(cb) {
             cb(null, {
               body: {
@@ -509,9 +507,7 @@ describe('auth0.authentication', function () {
       stub(request, 'get', function(url) {
         expect(url).to.be('https://me.auth0.com/user/ssodata?ldaps=1&client_id=...')
         return new RequestMock({
-          headers: {
-            'Content-Type': 'application/json'
-          },
+          headers: {},
           cb: function(cb) {
             cb(null, {
               body: {