Repository: auth0/auth0.js
Pull request #602 (2017-12-26 18:20:20)

setting getSSOData timeout to 5s

luisrudge: This is useful for when there's an error in the checkSession call (like invalid web_origin etc). Instead of using the default 60s timeout, it uses 5.

Patch:
diff --git a/docs/Authentication.html b/docs/Authentication.html
index da3c5f3..ae538ad 100644
--- a/docs/Authentication.html
+++ b/docs/Authentication.html
@@ -499,7 +499,7 @@
 <br class="clear">
 
 <footer>
-    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Thu Dec 07 2017 22:32:53 GMT-0200 (-02) using the Minami theme.
+    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Tue Dec 26 2017 16:09:39 GMT-0200 (-02) using the Minami theme.
 </footer>
 
 <script>prettyPrint();</script>
diff --git a/docs/Management.html b/docs/Management.html
index 7b685a7..c701f46 100644
--- a/docs/Management.html
+++ b/docs/Management.html
@@ -294,7 +294,7 @@
 <br class="clear">
 
 <footer>
-    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Thu Dec 07 2017 22:32:53 GMT-0200 (-02) using the Minami theme.
+    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Tue Dec 26 2017 16:09:39 GMT-0200 (-02) using the Minami theme.
 </footer>
 
 <script>prettyPrint();</script>
diff --git a/docs/WebAuth.html b/docs/WebAuth.html
index 9bef371..5377c7d 100644
--- a/docs/WebAuth.html
+++ b/docs/WebAuth.html
@@ -571,7 +571,7 @@
 <br class="clear">
 
 <footer>
-    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Thu Dec 07 2017 22:32:53 GMT-0200 (-02) using the Minami theme.
+    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Tue Dec 26 2017 16:09:39 GMT-0200 (-02) using the Minami theme.
 </footer>
 
 <script>prettyPrint();</script>
diff --git a/docs/authentication_db-connection.js.html b/docs/authentication_db-connection.js.html
index 8139175..03bcf93 100644
--- a/docs/authentication_db-connection.js.html
+++ b/docs/authentication_db-connection.js.html
@@ -154,7 +154,7 @@ module.exports = DBConnection;
 <br class="clear">
 
 <footer>
-    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Thu Dec 07 2017 22:32:53 GMT-0200 (-02) using the Minami theme.
+    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Tue Dec 26 2017 16:09:39 GMT-0200 (-02) using the Minami theme.
 </footer>
 
 <script>prettyPrint();</script>
diff --git a/docs/authentication_index.js.html b/docs/authentication_index.js.html
index f65ed38..8bce719 100644
--- a/docs/authentication_index.js.html
+++ b/docs/authentication_index.js.html
@@ -407,7 +407,8 @@ Authentication.prototype.getSSOData = function(withActiveDirectories, cb) {
     {
       responseType: 'token id_token',
       scope: 'openid profile email',
-      connection: ssodataInformation.lastUsedConnection
+      connection: ssodataInformation.lastUsedConnection,
+      timeout: 5000
     },
     function(err, result) {
       if (err) {
@@ -431,7 +432,7 @@ Authentication.prototype.getSSOData = function(withActiveDirectories, cb) {
           name: ssodataInformation.lastUsedConnection
         },
         lastUsedUserID: result.idTokenPayload.sub,
-        lastUsedUsername: result.idTokenPayload.name || result.idTokenPayload.email,
+        lastUsedUsername: result.idTokenPayload.email || result.idTokenPayload.name,
         lastUsedClientID: clientId,
         sessionClients: [clientId],
         sso: true
@@ -541,7 +542,7 @@ module.exports = Authentication;
 <br class="clear">
 
 <footer>
-    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Thu Dec 07 2017 22:32:53 GMT-0200 (-02) using the Minami theme.
+    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Tue Dec 26 2017 16:09:39 GMT-0200 (-02) using the Minami theme.
 </footer>
 
 <script>prettyPrint();</script>
diff --git a/docs/global.html b/docs/global.html
index c8d215a..d56852b 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -161,7 +161,7 @@ After that, you'll have to use the <a href="global.html#parseHash"><code>parseHa
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line460">line 460</a>
+        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line461">line 461</a>
     </li></ul></dd>
     
 
@@ -2332,7 +2332,7 @@ After that, you'll have to use the <a href="global.html#parseHash"><code>parseHa
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line399">line 399</a>
+        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line400">line 400</a>
     </li></ul></dd>
     
 
@@ -2822,7 +2822,7 @@ After that, you'll have to use the <a href="global.html#parseHash"><code>parseHa
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line360">line 360</a>
+        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line361">line 361</a>
     </li></ul></dd>
     
 
@@ -3274,7 +3274,7 @@ After that, you'll have to use the <a href="global.html#parseHash"><code>parseHa
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line585">line 585</a>
+        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line586">line 586</a>
     </li></ul></dd>
     
 
@@ -3357,7 +3357,7 @@ After that, you'll have to use the <a href="global.html#parseHash"><code>parseHa
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line595">line 595</a>
+        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line596">line 596</a>
     </li></ul></dd>
     
 
@@ -3440,7 +3440,7 @@ After that, you'll have to use the <a href="global.html#parseHash"><code>parseHa
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="authentication_index.js.html">authentication/index.js</a>, <a href="authentication_index.js.html#line436">line 436</a>
+        <a href="authentication_index.js.html">authentication/index.js</a>, <a href="authentication_index.js.html#line437">line 437</a>
     </li></ul></dd>
     
 
@@ -4741,7 +4741,7 @@ This only works when 3rd party cookies are enabled in the browser. After the /co
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line560">line 560</a>
+        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line561">line 561</a>
     </li></ul></dd>
     
 
@@ -5071,7 +5071,7 @@ After the /co/authenticate call, you'll have to use the <a href="global.html#par
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line543">line 543</a>
+        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line544">line 544</a>
     </li></ul></dd>
     
 
@@ -7143,7 +7143,7 @@ you should use <a href="global.html#login"><code>login</code></a> or <a href="gl
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line604">line 604</a>
+        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line605">line 605</a>
     </li></ul></dd>
     
 
@@ -7717,7 +7717,7 @@ Tokens signed with other algorithms, e.g. HS256 will not be accepted.</p>
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line413">line 413</a>
+        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line414">line 414</a>
     </li></ul></dd>
     
 
@@ -8088,7 +8088,7 @@ Tokens signed with other algorithms, e.g. HS256 will not be accepted.</p>
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line623">line 623</a>
+        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line624">line 624</a>
     </li></ul></dd>
     
 
@@ -9051,7 +9051,7 @@ Watch out! If you're not using the hosted login page to do social logins, you ha
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line283">line 283</a>
+        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line284">line 284</a>
     </li></ul></dd>
     
 
@@ -10021,7 +10021,7 @@ Watch out! If you're not using the hosted login page to do social logins, you ha
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line445">line 445</a>
+        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line446">line 446</a>
     </li></ul></dd>
     
 
@@ -10293,7 +10293,7 @@ The login will be done using /oauth/token with password-realm grant type.</p>
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line507">line 507</a>
+        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line508">line 508</a>
     </li></ul></dd>
     
 
@@ -11096,7 +11096,7 @@ you should use <a href="global.html#authorize"><code>authorize</code></a> or <a
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="authentication_index.js.html">authentication/index.js</a>, <a href="authentication_index.js.html#line408">line 408</a>
+        <a href="authentication_index.js.html">authentication/index.js</a>, <a href="authentication_index.js.html#line409">line 409</a>
     </li></ul></dd>
     
 
@@ -12056,7 +12056,7 @@ Tokens signed with other algorithms, e.g. HS256 will not be accepted.</p>
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line538">line 538</a>
+        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line539">line 539</a>
     </li></ul></dd>
     
 
@@ -12199,7 +12199,7 @@ Tokens signed with other algorithms, e.g. HS256 will not be accepted.</p>
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="authentication_index.js.html">authentication/index.js</a>, <a href="authentication_index.js.html#line430">line 430</a>
+        <a href="authentication_index.js.html">authentication/index.js</a>, <a href="authentication_index.js.html#line431">line 431</a>
     </li></ul></dd>
     
 
@@ -13159,7 +13159,7 @@ Tokens signed with other algorithms, e.g. HS256 will not be accepted.</p>
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="authentication_index.js.html">authentication/index.js</a>, <a href="authentication_index.js.html#line402">line 402</a>
+        <a href="authentication_index.js.html">authentication/index.js</a>, <a href="authentication_index.js.html#line403">line 403</a>
     </li></ul></dd>
     
 
@@ -13338,7 +13338,7 @@ Tokens signed with other algorithms, e.g. HS256 will not be accepted.</p>
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line251">line 251</a>
+        <a href="web-auth_index.js.html">web-auth/index.js</a>, <a href="web-auth_index.js.html#line252">line 252</a>
     </li></ul></dd>
     
 
@@ -13488,7 +13488,7 @@ Tokens signed with other algorithms, e.g. HS256 will not be accepted.</p>
 <br class="clear">
 
 <footer>
-    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Thu Dec 07 2017 22:32:53 GMT-0200 (-02) using the Minami theme.
+    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Tue Dec 26 2017 16:09:39 GMT-0200 (-02) using the Minami theme.
 </footer>
 
 <script>prettyPrint();</script>
diff --git a/docs/index.html b/docs/index.html
index 415d7ca..11f2b34 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -56,8 +56,10 @@
 <a href="https://npmjs.org/package/auth0-js"><img src="http://img.shields.io/npm/dm/auth0-js.svg?style=flat-square" alt="Downloads"></a></p>
 <p>Client Side Javascript toolkit for Auth0 API</p>
 <blockquote>
-<p>This is a BETA release. The recommended version is <a href="https://auth0.com/docs/libraries/auth0js/v8">https://auth0.com/docs/libraries/auth0js/v8</a></p>
+<p>Auth0.js v9 uses our latest embedded login API. This version <strong>is not supported in centralized login scenarios (i.e. Hosted Login Pages).</strong> If you are using a Hosted Login Page, keep using Auth0.js v8.</p>
 </blockquote>
+<p>Need help migrating from v8? Please check our <a href="https://auth0.com/docs/libraries/auth0js/v9/migration-guide">Migration Guide</a></p>
+<p>If you want to read the full API documentation of auth0.js, see <a href="https://auth0.github.io/auth0.js/index.html">here</a></p>
 <h2>Install</h2><p>From CDN</p>
 <pre class="prettyprint source lang-html"><code>&lt;!-- Latest patch release -->
 &lt;script src=&quot;http://cdn.auth0.com/js/auth0/9.0.0/auth0.min.js&quot;>&lt;/script></code></pre><p>From <a href="https://npmjs.org">npm</a></p>
@@ -107,7 +109,7 @@ Auth0 will call back to your application with the results at the specified <code
     // Now you have the user's information
   });
 });</code></pre><ul>
-<li><strong>checkSession(options, callback)</strong>: Allows you to acquire a new token from Auth0 for a user who is already authenticated against the hosted login page for your domain. If the user is not authenticated, the authentication result will be empty and you'll receive an error like this: <code>{error: 'login_required'}</code>.The method accepts any valid OAuth2 parameters that would normally be sent to <code>/authorize</code>.
+<li><strong>checkSession(options, callback)</strong>: Allows you to acquire a new token from Auth0 for a user who already has an SSO session established against Auth0 for your domain. If the user is not authenticated, the authentication result will be empty and you'll receive an error like this: <code>{error: 'login_required'}</code>.The method accepts any valid OAuth2 parameters that would normally be sent to <code>/authorize</code>.
 Everything happens inside an iframe, so it will not reload your application or redirect away from it.</li>
 </ul>
 <pre class="prettyprint source lang-js"><code>auth0.checkSession({
@@ -176,7 +178,7 @@ Everything happens inside an iframe, so it will not reload your application or r
 <br class="clear">
 
 <footer>
-    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Thu Dec 07 2017 22:32:53 GMT-0200 (-02) using the Minami theme.
+    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Tue Dec 26 2017 16:09:39 GMT-0200 (-02) using the Minami theme.
 </footer>
 
 <script>prettyPrint();</script>
diff --git a/docs/management_index.js.html b/docs/management_index.js.html
index d395a98..740f08b 100644
--- a/docs/management_index.js.html
+++ b/docs/management_index.js.html
@@ -173,7 +173,7 @@ module.exports = Management;
 <br class="clear">
 
 <footer>
-    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Thu Dec 07 2017 22:32:53 GMT-0200 (-02) using the Minami theme.
+    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Tue Dec 26 2017 16:09:39 GMT-0200 (-02) using the Minami theme.
 </footer>
 
 <script>prettyPrint();</script>
diff --git a/docs/web-auth_cross-origin-authentication.js.html b/docs/web-auth_cross-origin-authentication.js.html
index 3ef88ed..fcac469 100644
--- a/docs/web-auth_cross-origin-authentication.js.html
+++ b/docs/web-auth_cross-origin-authentication.js.html
@@ -181,7 +181,7 @@ module.exports = CrossOriginAuthentication;
 <br class="clear">
 
 <footer>
-    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Thu Dec 07 2017 22:32:53 GMT-0200 (-02) using the Minami theme.
+    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Tue Dec 26 2017 16:09:39 GMT-0200 (-02) using the Minami theme.
 </footer>
 
 <script>prettyPrint();</script>
diff --git a/docs/web-auth_index.js.html b/docs/web-auth_index.js.html
index 8535955..5b5b3ca 100644
--- a/docs/web-auth_index.js.html
+++ b/docs/web-auth_index.js.html
@@ -220,7 +220,8 @@ WebAuth.prototype.validateAuthenticationResponse = function(options, parsedHash,
   var _this = this;
   var state = parsedHash.state;
   var transaction = this.transactionManager.getStoredTransaction(state);
-  var transactionStateMatchesState = transaction &amp;&amp; transaction.state === state;
+  var transactionState = options.state || (transaction &amp;&amp; transaction.state) || null;
+  var transactionStateMatchesState = transactionState === state;
   if (state &amp;&amp; !transactionStateMatchesState) {
     return cb({
       error: 'invalid_token',
@@ -229,7 +230,7 @@ WebAuth.prototype.validateAuthenticationResponse = function(options, parsedHash,
   }
   var transactionNonce = options.nonce || (transaction &amp;&amp; transaction.nonce) || null;
 
-  var appState = (transaction &amp;&amp; transaction.appState) || null;
+  var appState = options.state || (transaction &amp;&amp; transaction.appState) || null;
 
   var callback = function(err, payload) {
     if (err) {
@@ -720,7 +721,7 @@ module.exports = WebAuth;
 <br class="clear">
 
 <footer>
-    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Thu Dec 07 2017 22:32:53 GMT-0200 (-02) using the Minami theme.
+    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Tue Dec 26 2017 16:09:39 GMT-0200 (-02) using the Minami theme.
 </footer>
 
 <script>prettyPrint();</script>
diff --git a/docs/web-auth_popup.js.html b/docs/web-auth_popup.js.html
index 87bafa7..c883339 100644
--- a/docs/web-auth_popup.js.html
+++ b/docs/web-auth_popup.js.html
@@ -327,7 +327,7 @@ module.exports = Popup;
 <br class="clear">
 
 <footer>
-    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Thu Dec 07 2017 22:32:53 GMT-0200 (-02) using the Minami theme.
+    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Tue Dec 26 2017 16:09:39 GMT-0200 (-02) using the Minami theme.
 </footer>
 
 <script>prettyPrint();</script>
diff --git a/docs/web-auth_redirect.js.html b/docs/web-auth_redirect.js.html
index e2b57e0..a25a034 100644
--- a/docs/web-auth_redirect.js.html
+++ b/docs/web-auth_redirect.js.html
@@ -105,7 +105,7 @@ module.exports = Redirect;
 <br class="clear">
 
 <footer>
-    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Thu Dec 07 2017 22:32:53 GMT-0200 (-02) using the Minami theme.
+    Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.0</a> on Tue Dec 26 2017 16:09:39 GMT-0200 (-02) using the Minami theme.
 </footer>
 
 <script>prettyPrint();</script>
diff --git a/src/authentication/index.js b/src/authentication/index.js
index 9addefd..8bbaead 100644
--- a/src/authentication/index.js
+++ b/src/authentication/index.js
@@ -366,7 +366,8 @@ Authentication.prototype.getSSOData = function(withActiveDirectories, cb) {
     {
       responseType: 'token id_token',
       scope: 'openid profile email',
-      connection: ssodataInformation.lastUsedConnection
+      connection: ssodataInformation.lastUsedConnection,
+      timeout: 5000
     },
     function(err, result) {
       if (err) {


Test patch:
diff --git a/test/authentication/authentication.test.js b/test/authentication/authentication.test.js
index b817517..46660c2 100644
--- a/test/authentication/authentication.test.js
+++ b/test/authentication/authentication.test.js
@@ -264,7 +264,8 @@ describe('auth0.authentication', function() {
       expect(this.webAuthSpy.checkSession.lastCall.args[0]).to.be.eql({
         responseType: 'token id_token',
         scope: 'openid profile email',
-        connection: 'lastUsedConnection'
+        connection: 'lastUsedConnection',
+        timeout: 5000
       });
     });
     it('returns sso:false if checkSession fails', function(done) {