Skip to content

Commit 3221708

Browse files
committed
add flag to revoke tokens on signout
1 parent a3cc180 commit 3221708

6 files changed

+36
-4
lines changed

src/OidcClientSettings.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default class OidcClientSettings {
1818
// metadata related
1919
authority, metadataUrl, metadata, signingKeys,
2020
// client related
21-
client_id, response_type = DefaultResponseType, scope = DefaultScope,
21+
client_id, client_secret, response_type = DefaultResponseType, scope = DefaultScope,
2222
redirect_uri, post_logout_redirect_uri,
2323
// optional protocol
2424
prompt, display, max_age, ui_locales, acr_values, resource,
@@ -37,6 +37,7 @@ export default class OidcClientSettings {
3737
this._signingKeys = signingKeys;
3838

3939
this._client_id = client_id;
40+
this._client_secret = client_secret;
4041
this._response_type = response_type;
4142
this._scope = scope;
4243
this._redirect_uri = redirect_uri;
@@ -73,6 +74,9 @@ export default class OidcClientSettings {
7374
throw new Error("client_id has already been assigned.")
7475
}
7576
}
77+
get client_secret() {
78+
return this._client_secret;
79+
}
7680
get response_type() {
7781
return this._response_type;
7882
}

src/TokenRevocationClient.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ export default class TokenRevocationClient {
3939
}
4040

4141
var client_id = this._settings.client_id;
42-
return this._revoke(url, client_id, accessToken);
42+
var client_secret = this._settings.client_secret;
43+
return this._revoke(url, client_id, client_secret, accessToken);
4344
});
4445
}
4546

46-
_revoke(url, client_id, accessToken) {
47+
_revoke(url, client_id, client_secret, accessToken) {
4748
Log.info("Calling revocation endpoint");
4849

4950
return new Promise((resolve, reject) => {
@@ -63,6 +64,9 @@ export default class TokenRevocationClient {
6364
};
6465

6566
var body = "client_id=" + encodeURIComponent(client_id);
67+
if (client_secret) {
68+
body += "&client_secret=" + encodeURIComponent(client_secret);
69+
}
6670
body += "&token_type_hint=" + encodeURIComponent(AccessTokenTypeHint);
6771
body += "&token=" + encodeURIComponent(accessToken);
6872

src/UserManager.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ export default class UserManager extends OidcClient {
298298
return this.getUser().then(user => {
299299
Log.info("loaded current user from storage");
300300

301-
return this._revokeInternal(user).then(() => {
301+
var revokePromise = this._settings.revokeAccessTokenOnSignout ? this._revokeInternal(user) : Promise.resolve();
302+
return revokePromise.then(() => {
302303

303304
var id_token = args.id_token_hint || user && user.id_token;
304305
if (id_token) {

src/UserManagerSettings.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default class UserManagerSettings extends OidcClientSettings {
2020
silentRequestTimeout,
2121
automaticSilentRenew = false,
2222
monitorSession = true,
23+
revokeAccessTokenOnSignout = false,
2324
accessTokenExpiringNotificationTime = DefaultAccessTokenExpiringNotificationTime,
2425
redirectNavigator = new RedirectNavigator(),
2526
popupNavigator = new PopupNavigator(),
@@ -38,6 +39,7 @@ export default class UserManagerSettings extends OidcClientSettings {
3839
this._accessTokenExpiringNotificationTime = accessTokenExpiringNotificationTime;
3940

4041
this._monitorSession = monitorSession;
42+
this._revokeAccessTokenOnSignout = revokeAccessTokenOnSignout;
4143

4244
this._redirectNavigator = redirectNavigator;
4345
this._popupNavigator = popupNavigator;
@@ -72,6 +74,9 @@ export default class UserManagerSettings extends OidcClientSettings {
7274
get monitorSession() {
7375
return this._monitorSession;
7476
}
77+
get revokeAccessTokenOnSignout() {
78+
return this._revokeAccessTokenOnSignout;
79+
}
7580

7681
get redirectNavigator() {
7782
return this._redirectNavigator;

test/unit/OidcClientSettings.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ describe("OidcClientSettings", function () {
4747
});
4848
});
4949

50+
describe("client_secret", function () {
51+
it("should return value from initial settings", function () {
52+
let subject = new OidcClientSettings({
53+
client_secret: 'secret'
54+
});
55+
subject.client_secret.should.equal("secret");
56+
});
57+
});
58+
5059
describe("response_type", function () {
5160
it("should return value from initial settings", function () {
5261
let subject = new OidcClientSettings({

test/unit/UserManagerSettings.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,13 @@ describe("UserManagerSettings", function () {
155155
subject.userStore.should.equal(temp);
156156
});
157157
});
158+
159+
describe("revokeAccessTokenOnSignout", function() {
160+
it("should return value from initial settings", function() {
161+
let subject = new UserManagerSettings({
162+
revokeAccessTokenOnSignout : true
163+
});
164+
subject.revokeAccessTokenOnSignout.should.equal(true);
165+
});
166+
});
158167
});

0 commit comments

Comments
 (0)