Commit 1a2c4aac authored by Robert Knight's avatar Robert Knight

Only clear the auth cache after login/logout when using cookie-based auth

When using cookie-based auth, login / logout happens via HTTP requests
made by the "session" service and the auth service has to be explicitly
notified afterwards via `auth.clearCache()`.

When using OAuth-based auth on the other hand, login / logout happens
through the auth service itself, so there is no need to ask the auth
service to clear cached credentials afterwards.
parent e7f1793c
...@@ -150,7 +150,12 @@ function session($http, $q, $resource, $rootScope, analytics, annotationUI, auth ...@@ -150,7 +150,12 @@ function session($http, $q, $resource, $rootScope, analytics, annotationUI, auth
lastLoadTime = Date.now(); lastLoadTime = Date.now();
if (userChanged) { if (userChanged) {
if (!getAuthority()) { if (!auth.login) {
// When using cookie-based auth, notify the auth service that the current
// login has changed and API tokens need to be invalidated.
//
// This is not needed for OAuth-based auth because all login/logout
// activities happen through the auth service itself.
auth.clearCache(); auth.clearCache();
} }
...@@ -223,12 +228,17 @@ function session($http, $q, $resource, $rootScope, analytics, annotationUI, auth ...@@ -223,12 +228,17 @@ function session($http, $q, $resource, $rootScope, analytics, annotationUI, auth
return reload(); return reload();
}); });
} else { } else {
loggedOut = resource.logout().$promise; loggedOut = resource.logout().$promise.then(() => {
// When using cookie-based auth, notify the auth service that the current
// login has changed and API tokens need to be invalidated.
//
// This is not needed for OAuth-based auth because all login/logout
// activities happen through the auth service itself.
auth.clearCache();
});
} }
return loggedOut.then(function () { return loggedOut.catch(function (err) {
auth.clearCache();
}).catch(function (err) {
flash.error('Log out failed'); flash.error('Log out failed');
analytics.track(analytics.events.LOGOUT_FAILURE); analytics.track(analytics.events.LOGOUT_FAILURE);
return $q.reject(new Error(err)); return $q.reject(new Error(err));
......
...@@ -295,11 +295,8 @@ describe('session', function () { ...@@ -295,11 +295,8 @@ describe('session', function () {
}); });
}); });
it('does not clear the access token when the host page provides a grant token', function () { it('does not clear the access token when using OAuth-based authorization', function () {
fakeServiceConfig.returns({ fakeAuth.login = Promise.resolve();
authority: 'publisher.org',
grantToken: 'a.jwt.token',
});
session.update({userid: 'different-user', csrf: 'dummytoken'}); session.update({userid: 'different-user', csrf: 'dummytoken'});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment