Skip to content

Commit 3733551

Browse files
committed
add stopCheckSessionOnError flag to not disable check session timer when errors returned DuendeArchive#491
1 parent dd9c4c0 commit 3733551

8 files changed

Lines changed: 106 additions & 36 deletions

‎dist/oidc-client.js‎

Lines changed: 25 additions & 4 deletions
Large diffs are not rendered by default.

‎dist/oidc-client.min.js‎

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/oidc-client.js‎

Lines changed: 25 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/oidc-client.min.js‎

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/CheckSessionIFrame.js‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import { Log } from './Log';
66
const DefaultInterval = 2000;
77

88
export class CheckSessionIFrame {
9-
constructor(callback, client_id, url, interval) {
9+
constructor(callback, client_id, url, interval, stopOnError = true) {
1010
this._callback = callback;
1111
this._client_id = client_id;
1212
this._url = url;
1313
this._interval = interval || DefaultInterval;
14+
this._stopOnError = stopOnError;
1415

1516
var idx = url.indexOf("/", url.indexOf("//") + 2);
1617
this._frame_origin = url.substr(0, idx);
@@ -42,8 +43,10 @@ export class CheckSessionIFrame {
4243
e.source === this._frame.contentWindow
4344
) {
4445
if (e.data === "error") {
45-
Log.error("error message from check session op iframe");
46-
this.stop();
46+
Log.error("CheckSessionIFrame: error message from check session op iframe");
47+
if (this._stopOnError) {
48+
this.stop();
49+
}
4750
}
4851
else if (e.data === "changed") {
4952
Log.debug("CheckSessionIFrame: changed message from check session op iframe");

‎src/SessionMonitor.js‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export class SessionMonitor {
1919
this._userManager.events.addUserUnloaded(this._stop.bind(this));
2020

2121
this._userManager.getUser().then(user => {
22+
// doing this manually here since calling getUser
23+
// doesn't trigger load event.
2224
if (user) {
2325
this._start(user);
2426
}
@@ -40,6 +42,9 @@ export class SessionMonitor {
4042
get _checkSessionInterval() {
4143
return this._settings.checkSessionInterval;
4244
}
45+
get _stopCheckSessionOnError() {
46+
return this._settings.stopCheckSessionOnError;
47+
}
4348

4449
_start(user) {
4550
let session_state = user.session_state;
@@ -56,8 +61,9 @@ export class SessionMonitor {
5661

5762
let client_id = this._client_id;
5863
let interval = this._checkSessionInterval;
64+
let stopOnError = this._stopCheckSessionOnError;
5965

60-
this._checkSessionIFrame = new this._CheckSessionIFrameCtor(this._callback.bind(this), client_id, url, interval);
66+
this._checkSessionIFrame = new this._CheckSessionIFrameCtor(this._callback.bind(this), client_id, url, interval, stopOnError);
6167
this._checkSessionIFrame.load().then(() => {
6268
this._checkSessionIFrame.start(session_state);
6369
});

‎src/UserManagerSettings.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class UserManagerSettings extends OidcClientSettings {
2424
includeIdTokenInSilentRenew = true,
2525
monitorSession = true,
2626
checkSessionInterval = DefaultCheckSessionInterval,
27+
stopCheckSessionOnError = true,
2728
revokeAccessTokenOnSignout = false,
2829
accessTokenExpiringNotificationTime = DefaultAccessTokenExpiringNotificationTime,
2930
redirectNavigator = new RedirectNavigator(),
@@ -46,6 +47,7 @@ export class UserManagerSettings extends OidcClientSettings {
4647

4748
this._monitorSession = monitorSession;
4849
this._checkSessionInterval = checkSessionInterval;
50+
this._stopCheckSessionOnError = stopCheckSessionOnError;
4951
this._revokeAccessTokenOnSignout = revokeAccessTokenOnSignout;
5052

5153
this._redirectNavigator = redirectNavigator;
@@ -90,6 +92,9 @@ export class UserManagerSettings extends OidcClientSettings {
9092
get checkSessionInterval() {
9193
return this._checkSessionInterval;
9294
}
95+
get stopCheckSessionOnError(){
96+
return this._stopCheckSessionOnError;
97+
}
9398
get revokeAccessTokenOnSignout() {
9499
return this._revokeAccessTokenOnSignout;
95100
}

‎test/unit/UserManagerSettings.spec.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,18 @@ describe("UserManagerSettings", function () {
200200
subject.checkSessionInterval.should.equal(2000);
201201
});
202202
});
203+
204+
describe("stopCheckSessionOnError", function() {
205+
it("should return value from initial settings", function() {
206+
let subject = new UserManagerSettings({
207+
stopCheckSessionOnError : false
208+
});
209+
subject.stopCheckSessionOnError.should.be.false;
210+
});
211+
it("should use default value", function () {
212+
let subject = new UserManagerSettings({
213+
});
214+
subject.stopCheckSessionOnError.should.be.true;
215+
});
216+
});
203217
});

0 commit comments

Comments
 (0)