Skip to content

Commit 408fc0e

Browse files
committed
temp checkin
1 parent c95b933 commit 408fc0e

8 files changed

Lines changed: 504 additions & 55 deletions

File tree

‎dist/oidc-client.js‎

Lines changed: 162 additions & 2 deletions
Large diffs are not rendered by default.

‎dist/oidc-client.min.js‎

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

‎index.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const AccessTokenEvents = require('./src/AccessTokenEvents');
1010
export const MetadataService = require('./src/MetadataService');
1111
export const CordovaPopupNavigator = require('./src/CordovaPopupNavigator');
1212
export const CordovaIFrameNavigator = require('./src/CordovaIFrameNavigator');
13+
export const SessionMonitor = require('./src/SessionMonitor');
1314

1415
export default {
1516
Log,
@@ -20,5 +21,6 @@ export default {
2021
AccessTokenEvents,
2122
MetadataService,
2223
CordovaPopupNavigator,
23-
CordovaIFrameNavigator
24+
CordovaIFrameNavigator,
25+
SessionMonitor
2426
};

‎lib/oidc-client.js‎

Lines changed: 162 additions & 2 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: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/CheckSessionHtml.js‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
export default html;
5+
6+
const html = `
7+
<!DOCTYPE html>
8+
<html>
9+
<head>
10+
<title>Check Session IFrame</title>
11+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
12+
</head>
13+
<body>
14+
<iframe id="op"></iframe>
15+
<script>
16+
window.addEventListener("message", function (e) {
17+
var client_origin = window.location.protocol + "//" + window.location.host;
18+
if (e.origin === client_origin) {
19+
var op_origin = data.op_origin;
20+
21+
var session_state = data.session_state;
22+
var client_id = data.client_id;
23+
24+
var op_iframe = document.getElementById("op");
25+
op_iframe.src = data.check_session_iframe;
26+
if (timer) {
27+
window.clearInterval(timer);
28+
}
29+
var timer = window.setInterval(function () {
30+
op_iframe.postMessage(client_id + " " + session_state, op_origin);
31+
}, data.check_interval || 2000);
32+
}
33+
else if (op_origin && e.origin === op_origin) {
34+
if (e.data === "changed" || e.data === "error") {
35+
window.clearInterval(timer);
36+
timer = null;
37+
op_origin = null;
38+
}
39+
if (e.data === "changed") {
40+
window.parent.postMessage("changed", client_origin);
41+
}
42+
}
43+
});
44+
</script>
45+
</body>
46+
</html>
47+
`;

‎src/CheckSessionIFrame.js‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
import Log from './Log';
5+
import CheckSessionHtml from './CheckSessionHtml';
6+
7+
const DefaultInterval = 2000;
8+
9+
export default class CheckSessionIFrame {
10+
constructor(callback) {
11+
this._callback = callback;
12+
13+
this._boundMessageEvent = this._message.bind(this);
14+
window.addEventListener("message", this._boundMessageEvent, false);
15+
16+
this._frame = window.document.createElement("iframe");
17+
this._frame.style.display = "none";
18+
window.document.body.appendChild(this._frame);
19+
this._frame.document.write(CheckSessionHtml);
20+
}
21+
22+
_message(e) {
23+
Log.info("CheckSessionIFrame._message");
24+
25+
if (e.origin === this._origin &&
26+
e.source === this._popup.window
27+
) {
28+
Log.info("processing message", e.data);
29+
this._callback();
30+
}
31+
}
32+
33+
get _origin() {
34+
return window.location.protocol + "//" + window.location.host;
35+
}
36+
37+
init(client_id, check_session_iframe, session_state, interval) {
38+
let msg = {
39+
client_id: client_id,
40+
check_session_iframe : check_session_iframe,
41+
session_state : session_state,
42+
check_interval: interval || DefaultInterval
43+
};
44+
this._frame.postMessage(msg, this._origin);
45+
}
46+
}

‎src/SessionMonitor.js‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
import Log from './Log';
5+
import MetadataService from './MetadataService';
6+
import CheckSessionIFrame from './CheckSessionIFrame';
7+
8+
export default class SessionMonitor {
9+
10+
constructor(settings, MetadataServiceCtor = MetadataService, CheckSessionIFrameCtor = CheckSessionIFrame) {
11+
if (!settings) {
12+
Log.error("No settings passed to SessionMonitor");
13+
throw new Error("settings");
14+
}
15+
16+
this._settings = settings;
17+
this._metadataService = new MetadataServiceCtor(this._settings);
18+
this._checkSessionIFrame = new CheckSessionIFrameCtor(this._callback);
19+
}
20+
21+
_callback() {
22+
Log.info("SessionMonitor.callback happened");
23+
}
24+
25+
initialize(user) {
26+
let client_id = this._settings.client_id;
27+
let session_state = user.session_state;
28+
let interval = this._settings.checkSessionInterval;
29+
30+
return this._promise = this._metadataService.getCheckSessionIframe(url => {
31+
this._checkSessionIFrame.init(client_id, url, session_state, interval);
32+
});
33+
}
34+
}

0 commit comments

Comments
 (0)