Repository: auth0/auth0.js
Pull request #434 (2017-05-16 13:17:48)

Adding `scope` to the parsed hash object


Patch:
diff --git a/src/web-auth/index.js b/src/web-auth/index.js
index 38228b7..45f56cc 100644
--- a/src/web-auth/index.js
+++ b/src/web-auth/index.js
@@ -167,7 +167,8 @@ function buildParseHashResponse(qsParams, appStatus, token) {
     refreshToken: qsParams.refresh_token || null,
     state: qsParams.state || null,
     expiresIn: qsParams.expires_in ? parseInt(qsParams.expires_in, 10) : null,
-    tokenType: qsParams.token_type || null
+    tokenType: qsParams.token_type || null,
+    scope: qsParams.scope || null
   };
 }
 


Test patch:
diff --git a/test/plugins/cordova.test.js b/test/plugins/cordova.test.js
index 5192700..f79d07e 100644
--- a/test/plugins/cordova.test.js
+++ b/test/plugins/cordova.test.js
@@ -155,7 +155,8 @@ describe('auth0.plugins.cordova', function () {
           refreshToken: 'kajshdgfkasdjhgfas',
           state: 'theState',
           expiresIn: null,
-          tokenType: 'Bearer'
+          tokenType: 'Bearer',
+          scope: null
         });
         expect(_this.events).to.eql({});
         done();
@@ -178,7 +179,8 @@ describe('auth0.plugins.cordova', function () {
           refreshToken: null,
           state: 'theState',
           expiresIn: null,
-          tokenType: 'Bearer'
+          tokenType: 'Bearer',
+          scope: null
         });
         expect(_this.events).to.eql({});
         done();
diff --git a/test/web-auth/web-auth.test.js b/test/web-auth/web-auth.test.js
index 41613d9..e0ec205 100644
--- a/test/web-auth/web-auth.test.js
+++ b/test/web-auth/web-auth.test.js
@@ -133,7 +133,7 @@ describe('auth0.WebAuth', function () {
 
       var data = webAuth.parseHash({
         nonce: 'asfd',
-        hash: '#access_token=VjubIMBmpgQ2W2&id_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlF6RTROMFpCTTBWRFF6RTJSVVUwTnpJMVF6WTFNelE0UVRrMU16QXdNRUk0UkRneE56RTRSZyJ9.eyJpc3MiOiJodHRwczovL3dwdGVzdC5hdXRoMC5jb20vIiwic3ViIjoiYXV0a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xppz30GSXoOJLbeBszfrVDCmPhpHKGGMPL1N6HV-3EEF77L34YNAi2JQ-b70nFK_dnYmmv0cYTGUxtGTHkl64UEDLi3u7bV-kbGky3iOOCzXKzDDY6BBKpCRTc2KlbrkO2A2PuDn27WVv1QCNEFHvJN7HxiDDzXOsaUmjrQ3sfrHhzD7S9BcCRkekRfD9g95SKD5J0Fj8NA&token_type=Bearer&state=theState&refresh_token=kajshdgfkasdjhgfas&scope=foo'
       }, function(err, data) {
         expect(err).to.be(null);
         expect(data).to.eql({
@@ -151,7 +151,8 @@ describe('auth0.WebAuth', function () {
           refreshToken: 'kajshdgfkasdjhgfas',
           state: 'theState',
           expiresIn: null,
-          tokenType: 'Bearer'
+          tokenType: 'Bearer',
+          scope: 'foo'
         });
 
         expect(TransactionManager.prototype.getStoredTransaction.calledOnce).to.be.ok();
@@ -188,7 +189,8 @@ describe('auth0.WebAuth', function () {
           refreshToken: 'kajshdgfkasdjhgfas',
           state: 'theState',
           expiresIn: null,
-          tokenType: 'Bearer'
+          tokenType: 'Bearer',
+          scope: null
         });
 
         expect(TransactionManager.prototype.getStoredTransaction.calledOnce).to.be.ok();
@@ -223,7 +225,8 @@ describe('auth0.WebAuth', function () {
           refreshToken: 'kajshdgfkasdjhgfas',
           state: 'theState',
           expiresIn: null,
-          tokenType: 'Bearer'
+          tokenType: 'Bearer',
+          scope: null
         });
 
         expect(TransactionManager.prototype.getStoredTransaction.calledOnce).to.be.ok();
@@ -251,7 +254,8 @@ describe('auth0.WebAuth', function () {
           refreshToken: 'kajshdgfkasdjhgfas',
           state: 'theState',
           expiresIn: null,
-          tokenType: 'Bearer'
+          tokenType: 'Bearer',
+          scope: null
         });
 
         expect(TransactionManager.prototype.getStoredTransaction.calledOnce).to.be.ok();
@@ -448,7 +452,8 @@ describe('auth0.WebAuth', function () {
           refreshToken: null,
           state: null,
           expiresIn: null,
-          tokenType: null
+          tokenType: null,
+          scope: null
         });
 
         expect(TransactionManager.prototype.getStoredTransaction.calledTwice).to.be.ok();
@@ -509,7 +514,8 @@ describe('auth0.WebAuth', function () {
             refreshToken: null,
             state: null,
             expiresIn: null,
-            tokenType: null
+            tokenType: null,
+            scope: null
           });
           done();
         });