diff --git a/index.js b/index.js index 8f9cc23b..12d28118 100644 --- a/index.js +++ b/index.js @@ -1642,15 +1642,34 @@ Auth0.prototype.getDelegationToken = function (options, callback) { * auth0.logout({returnTo: 'http://logout'}); * // redirects to -> 'https://yourapp.auth0.com/logout?returnTo=http://logout' * + * @example + * + * auth0.logout(null, {version: 'v2'}); + * // redirects to -> 'https://yourapp.auth0.com/v2/logout' + * + * @example + * + * auth0.logout({returnTo: 'http://logout'}, {version: 2}); + * // redirects to -> 'https://yourapp.auth0.com/v2/logout?returnTo=http://logout' + * * @method logout * @param {Object} query */ -Auth0.prototype.logout = function (query) { - var url = joinUrl('https:', this._domain, '/logout'); +Auth0.prototype.logout = function (query, options) { + var pathName = '/logout'; + options = options || {}; + + if (options.version == 'v2') { + pathName = '/v2' + pathName + } + + var url = joinUrl('https:', this._domain, pathName); + if (query) { url += '?' + qs.stringify(query); } + this._redirect(url); }; diff --git a/test/tests.js b/test/index.tests.js similarity index 99% rename from test/tests.js rename to test/index.tests.js index 6fd65fe9..894feb05 100644 --- a/test/tests.js +++ b/test/index.tests.js @@ -310,7 +310,7 @@ describe('Auth0', function () { }) }); - describe.only('parseHash', function () { + describe('parseHash', function () { context('response_type=token + scope=openid offline_access + state', function() { before(function() { var hash = '#access_token=AdyWpLVbQi2GA0fy&refresh_token=8m8M2Dk7BWsmpyumpguR4ZVKpZDy6bhFrZacaq6kmEVtt&id_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2duYW5kcmV0dGEuYXV0aDAuY29tLyIsInN1YiI6ImF1dGgwfDU3MmNhOWYzMGRjMjhkOGQ3YmY3MzRhYSIsImF1ZCI6Iks2bkFFT2dFZVN3b2dDR3Y2TjZtOXdOZlFodmJGQW0wIiwiZXhwIjoxNDcwOTYzOTQyLCJpYXQiOjE0NzA5Mjc5NDJ9.KcxIWhnTHeL_kNwUq74ef3REOCFDxiOH_NiNMqNNZks&token_type=Bearer&state=hello'; diff --git a/test/logout.js b/test/logout.js deleted file mode 100644 index 5c742f33..00000000 --- a/test/logout.js +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Config mocha - */ - -mocha.timeout(60000); -mocha.globals(['jQuery*', '__auth0jp*']); - -/** - * Test Logout - */ - -describe('logout', function () { - it('should redirect to the logout url', function (done) { - var auth0 = Auth0({ - domain: 'mdocs.auth0.com', - callbackURL: 'http://localhost:3000/', - clientID: 'ptR6URmXef0OfBDHK0aCIy7iPKpdCG4t' - }); - - auth0._redirect = function (url) { - expect(url).to.equal('https://mdocs.auth0.com/logout'); - done(); - }; - - auth0.logout(); - }); - - it('should redirect to the logout url with params', function (done) { - var auth0 = Auth0({ - domain: 'mdocs.auth0.com', - callbackURL: 'http://localhost:3000/', - clientID: 'ptR6URmXef0OfBDHK0aCIy7iPKpdCG4t' - }); - - auth0._redirect = function (url) { - expect(url).to.equal('https://mdocs.auth0.com/logout?returnTo=http%3A%2F%2Flogout'); - done(); - }; - - auth0.logout({returnTo: 'http://logout'}); - }); - -}); diff --git a/test/logout.tests.js b/test/logout.tests.js new file mode 100644 index 00000000..162ed52f --- /dev/null +++ b/test/logout.tests.js @@ -0,0 +1,81 @@ +/** + * Config mocha + */ + +mocha.timeout(60000); +mocha.globals(['jQuery*', '__auth0jp*']); + +/** + * Test Logout + */ + +describe('logout', function () { + + describe('v1', function() { + + it('should redirect to the logout url', function (done) { + var auth0 = Auth0({ + domain: 'mdocs.auth0.com', + callbackURL: 'http://localhost:3000/', + clientID: 'ptR6URmXef0OfBDHK0aCIy7iPKpdCG4t' + }); + + auth0._redirect = function (url) { + expect(url).to.equal('https://mdocs.auth0.com/logout'); + done(); + }; + + auth0.logout(); + }); + + it('should redirect to the logout url with params', function (done) { + var auth0 = Auth0({ + domain: 'mdocs.auth0.com', + callbackURL: 'http://localhost:3000/', + clientID: 'ptR6URmXef0OfBDHK0aCIy7iPKpdCG4t' + }); + + auth0._redirect = function (url) { + expect(url).to.equal('https://mdocs.auth0.com/logout?returnTo=http%3A%2F%2Flogout'); + done(); + }; + + auth0.logout({returnTo: 'http://logout'}); + }); + + }); + + describe('v2', function() { + + it('should redirect to the logout url', function (done) { + var auth0 = Auth0({ + domain: 'mdocs.auth0.com', + callbackURL: 'http://localhost:3000/', + clientID: 'ptR6URmXef0OfBDHK0aCIy7iPKpdCG4t' + }); + + auth0._redirect = function (url) { + expect(url).to.equal('https://mdocs.auth0.com/v2/logout'); + done(); + }; + + auth0.logout(null, {version: 'v2'}); + }); + + it('should redirect to the logout url with params', function (done) { + var auth0 = Auth0({ + domain: 'mdocs.auth0.com', + callbackURL: 'http://localhost:3000/', + clientID: 'ptR6URmXef0OfBDHK0aCIy7iPKpdCG4t' + }); + + auth0._redirect = function (url) { + expect(url).to.equal('https://mdocs.auth0.com/v2/logout?returnTo=http%3A%2F%2Flogout'); + done(); + }; + + auth0.logout({returnTo: 'http://logout'}, {version: 'v2'}); + }); + + }); +});