Repository: auth0/auth0.js
Pull request #251 (2016-11-30 18:59:43)

Added sso data client


Patch:
diff --git a/example/index.html b/example/index.html
index 4af0a9f..79e897a 100644
--- a/example/index.html
+++ b/example/index.html
@@ -215,8 +215,12 @@
         connection: 'tests',
         username: $('.client-login-username').val(),
         password: $('.client-login-password').val(),
-        scope: 'openid'
-      }, htmlConsole.dumpCallback.bind(htmlConsole));
+        scope: 'openid profile',
+        audience: 'urn:test'
+      }, function(err, data) {
+        htmlConsole.dumpCallback.bind(htmlConsole)(err, data);
+        this.webAuth.client.userInfo(data.access_token, htmlConsole.dumpCallback.bind(htmlConsole));
+      });
     });
 
     $('.login-facebook').click(function (e) {
diff --git a/src/authentication/index.js b/src/authentication/index.js
index 70bed07..6d79826 100644
--- a/src/authentication/index.js
+++ b/src/authentication/index.js
@@ -177,6 +177,32 @@ Authentication.prototype.loginWithResourceOwner = function (options, cb) {
     .end(responseHandler(cb));
 };
 
+Authentication.prototype.getSSOData = function (withActiveDirectories, cb) {
+  var url;
+  var params = '';
+
+  if (typeof withActiveDirectories === 'function') {
+    cb = withActiveDirectories;
+    withActiveDirectories = false;
+  }
+
+  assert.check(withActiveDirectories, { type: 'boolean', message: 'withActiveDirectories parameter is not valid' });
+  assert.check(cb, { type: 'function', message: 'cb parameter is not valid' });
+
+  if (withActiveDirectories) {
+    params = '?' + qs.build({
+      ldaps: 1,
+      client_id: this.baseOptions.clientID
+    });
+  }
+
+  url = urljoin(this.baseOptions.rootUrl, 'user', 'ssodata', params);
+
+  return this.request
+    .get(url)
+    .end(responseHandler(cb));
+};
+
 Authentication.prototype.userInfo = function (accessToken, cb) {
   var url;
 


Test patch:
diff --git a/test/authentication/authentication.test.js b/test/authentication/authentication.test.js
index 6a626c5..0ff6ec2 100644
--- a/test/authentication/authentication.test.js
+++ b/test/authentication/authentication.test.js
@@ -285,7 +285,7 @@ describe('auth0.authentication', function () {
       this.auth0.oauthToken.restore();
     })
 
-    it('should call delegation with all the options', function(done) {
+    it('should call oauthToken with all the options', function(done) {
       stub(this.auth0, 'oauthToken', function(options, cb) {
         expect(options).to.eql({
           username: 'someUsername',
@@ -361,4 +361,88 @@ describe('auth0.authentication', function () {
 
   });
 
+  context('getSSOData', function () {
+    before(function() {
+      this.auth0 = new Authentication({
+        domain: 'me.auth0.com',
+        clientID: '...',
+        redirectUri: 'http://page.com/callback',
+        responseType: 'code',
+        _sendTelemetry: false
+      });
+    });
+
+    afterEach(function(){
+      request.get.restore();
+    })
+
+    it('should call ssodata with all the options', function(done) {
+      stub(request, 'get', function(url) {
+        expect(url).to.be('https://me.auth0.com/user/ssodata/')
+        return new RequestMock({
+          headers: {
+            'Content-Type': 'application/json'
+          },
+          cb: function(cb) {
+            cb(null, {
+              body: {
+                sso:false
+              }
+            });
+          }
+        });
+      });
+
+      this.auth0.getSSOData(function(err, data) {
+        expect(err).to.be(null);
+        expect(data).to.eql({
+          sso:false
+        });
+        done();
+      })
+    });
+  });
+
+  context('getSSOData', function () {
+    before(function() {
+      this.auth0 = new Authentication({
+        domain: 'me.auth0.com',
+        clientID: '...',
+        redirectUri: 'http://page.com/callback',
+        responseType: 'code',
+        _sendTelemetry: false
+      });
+    });
+
+    afterEach(function(){
+      request.get.restore();
+    })
+
+    it('should call ssodata with all the ad options', function(done) {
+      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'
+          },
+          cb: function(cb) {
+            cb(null, {
+              body: {
+                sso:false
+              }
+            });
+          }
+        });
+      });
+
+      this.auth0.getSSOData(true, function(err, data) {
+        expect(err).to.be(null);
+        expect(data).to.eql({
+          sso:false
+        });
+        done();
+      })
+    });
+  });
+
 })
\ No newline at end of file