Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to use v2 logout endpoint #201

Merged
merged 1 commit into from
Sep 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a typo here. It should be {version: 'v2'}.

* // 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);
};

Expand Down
2 changes: 1 addition & 1 deletion test/tests.js → test/index.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
43 changes: 0 additions & 43 deletions test/logout.js

This file was deleted.

81 changes: 81 additions & 0 deletions test/logout.tests.js
Original file line number Diff line number Diff line change
@@ -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'});
});

});
});