keycloak-scim/adapters/oidc/js/src/main/resources/login-status-iframe.html

100 lines
2.9 KiB
HTML
Raw Normal View History

2016-02-03 10:20:22 +00:00
<!--
2016-11-29 08:49:58 +00:00
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
~ and other contributors as indicated by the @author tags.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
2016-02-03 10:20:22 +00:00
2016-10-19 10:07:31 +00:00
<html>
<body>
2016-11-29 08:49:58 +00:00
<script>
var init;
2016-10-19 10:07:31 +00:00
2016-11-29 08:49:58 +00:00
function checkState(clientId, origin, sessionState, callback) {
var cookie = getCookie();
if (!cookie) {
callback('changed');
2016-11-29 08:49:58 +00:00
} else if (!init) {
var req = new XMLHttpRequest();
var url = location.href + "/init";
url += "?client_id=" + encodeURIComponent(clientId);
url += "&origin=" + encodeURIComponent(origin);
req.open('GET', url, true);
req.onreadystatechange = function () {
if (req.readyState === 4) {
if (req.status === 204) {
init = {
clientId: clientId,
origin: origin
}
callback('unchanged');
} else if (req.status === 404) {
callback('changed');
} else {
callback('error');
}
}
};
req.send();
2016-10-19 10:07:31 +00:00
} else {
2016-11-29 08:49:58 +00:00
if (clientId === init.clientId && origin === init.origin) {
var c = cookie.split('/');
if (sessionState === c[2]) {
2016-11-29 08:49:58 +00:00
callback('unchanged');
} else {
callback('changed');
}
} else {
callback('error');
}
2016-10-19 10:07:31 +00:00
}
}
2016-11-29 08:49:58 +00:00
function getCookie()
{
var name = 'KEYCLOAK_SESSION=';
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++)
{
var c = ca[i].trim();
if (c.indexOf(name)===0) return c.substring(name.length,c.length);
}
return null;
}
2016-11-29 08:49:58 +00:00
function receiveMessage(event)
{
var origin = event.origin;
var data = event.data.split(' ');
if (data.length != 2) {
return;
2016-11-29 08:49:58 +00:00
}
var clientId = data[0];
var sessionState = data[1];
checkState(clientId, event.origin, sessionState, function(result) {
event.source.postMessage(result, origin);
});
}
2016-11-29 08:49:58 +00:00
window.addEventListener("message", receiveMessage, false);
</script>
2016-10-19 10:07:31 +00:00
</body>
</html>