Commit cebad539 authored by Steve Johnson's avatar Steve Johnson

Finished integrating remote IDP support

parent 810caf3a
......@@ -126,6 +126,14 @@ var Url = (function() {
return resolveURL("authenticate", "php/auth/authenticate.php");
};
obj.idpLogin = function() {
return resolveURL("idpLogin", "php/auth/idp_login.php");
};
obj.idpLogout = function() {
return resolveURL("idpLogin", "php/auth/idp_logout.php");
};
obj.discovery = function() {
return resolveURL("discovery", "php/dial/discovery.php");
};
......
......@@ -17,7 +17,8 @@ body {
}
.hidden {
opacity: 0;
xopacity: 0;
display: none;
}
#home {
......
......@@ -28,11 +28,8 @@
<script type="text/javascript" src="../js/url.js" ></script>
<script type="text/javascript" src="login.js" ></script>
<!--style>
html, body, #loginView {
min-height: 480px !important;
}
</style-->
<style>
</style>
</head>
......@@ -93,10 +90,12 @@
<a data-role='button' id='guestButton' style='width: 80%; margin: auto; text-align: center;' onclick='clickGuestButton(); return false;'href='#'>Use Phone</a>
<br>
</div>
<div class="hidden" data-role="fieldcontain" data-theme='a' id="resetpanel" style='font-family: verdana; font-size: 14px;'>
<a data-role='button' id='logoutButton' style='width: 60%; margin: auto; text-align: center;' onclick='clickLogoutButton(); return false;'href='#'>IDP Logout</a>
</div>
<br><br>
<br><br>
......
......@@ -18,6 +18,12 @@ var EAlertType_Error = 3;
function initLogin() {
sizeRemotePage();
var cookies = getCookies();
if (cookies.MSE_RedirectUseIDP && cookies.MSE_RedirectUseIDP == 'true') {
$('#resetpanel').removeClass('hidden');
$('#loginpanel').addClass('hidden');
}
window.addEventListener('keyup', function(event) {
if(event.keyCode == 13){
clickLoginButton();
......@@ -28,11 +34,35 @@ function initLogin() {
$('#hostLabel').text(baseurl);
}
// Return the document's cookies as an object of name/value pairs.
// Assume that cookie values are encoded with encodeURIComponent().
function getCookies() {
var cookies = {}; // The object we will return
var all = document.cookie; // Get all cookies in one big string
if (all === "") // If the property is the empty string
return cookies; // return an empty object
var list = all.split("; "); // Split into individual name=value pairs
for(var i = 0; i < list.length; i++) { // For each cookie
var cookie = list[i];
var p = cookie.indexOf("="); // Find the first = sign
var name = cookie.substring(0,p); // Get cookie name
var value = cookie.substring(p+1); // Get cookie value
value = decodeURIComponent(value); // Decode the value
cookies[name] = value; // Store name and value in object
}
return cookies;
}
function prefill() {
document.getElementById('username').value = 'sglennon';
document.getElementById('password').value = 'Pa$$word';
}
function clickLogoutButton() {
parent.Remote.logoutIDP();
}
function clickLoginButton() {
var KAppMsg_LoginFailed = "Login Failed";
......
......@@ -58,6 +58,20 @@
display: inline-block;
}
#cbLabel {
width: 100%;
max-width: 160px;
margin: auto;
margin-top: 20px;
xmargin-bottom: 20px;
text-align: center;
display: inline-block;
border: none;
background-color: transparent;
}
#url #selectButton {
max-width: 400px;
}
......@@ -72,6 +86,60 @@
#cancelButton {
margin-left: 10px;
}
/* remove rounded corners */
.xui-btn-corner-all {
-moz-border-radius: 0px;
-webkit-border-radius: 0px;
border-radius: 0px;
}
/* remove border between each item */
.ui-btn-inner{
border: 0;
}
/* remove margin between items */
fieldset .ui-radio {
margin: 0;
}
/* change background, remove other border, unbold text */
.ui-btn-up-a, .ui-btn-hover-a, .ui-btn-down-a {
background: #4f83bc;
background-image: none;
border: 0;
font-weight: normal;
}
/* change background, remove other border, unbold text */
#cbLabel.ui-btn-up-a, #cbLabel.ui-btn-hover-a, #cbLabel.ui-btn-down-a {
xbackground: #4f83bc;
background-image: none;
border: 0;
font-weight: normal;
}
/* change color of radio background */
.ui-checkbox-on .ui-icon, .ui-radio-on .ui-icon {
xbackground-color: #456;
}
.ui-checkbox-off .ui-icon {
background-color: #222;
}
.ui-body-a, .ui-overlay-a {
background: #444;
}
.ui-input-text {
background: #222;
}
.ui-checkbox input{
display: none;
}
</style>
</head>
......@@ -90,15 +158,15 @@
<div id='inputfields' style='margin: 24px;'>
<center>
<label id="urlLabel">
New Base URL (eg. /atgdev):
Base URL (eg. /atgdev):
</label>
</center>
<center>
<input type='text' id='uri' style='width: 225px;' autofocus='autofocus' autocapitalize='off' autocorrect='off'
onchange='onInputTextChange();' onkeypress='this.onchange();' onpaste='this.onchange();' oninput='this.onchange();'>
<label id="cbLabel" class="hidden"><input id="cbUseIDP" type="checkbox" name="checkbox-0" data-theme="a">Use IDP</label>
</center>
<br>
</div>
<!-- login button -->
......
var newBaseUri = "";
// This is used to determine whether the proposed base uri is valid. remote.html must exist.
var remoteUri = "mse/remote/remote.html";
var remoteUriIdp = "mse/php/auth/idp_login.php";
var qparams = "";
// This is the uri baked into the application that redirects to the selected location.
......@@ -8,35 +9,52 @@
function initLogin() {
// Get query params from redirect uri.
var qp = queryParams();
var redirectUri = decodeURIComponent(qp.redirect_uri);
var qindex = redirectUri.indexOf('?');
if (qindex != -1) {
qparams = redirectUri.substring(qindex);
console.log("qstring: "+qparams);
// Get query params from redirect uri.
var qp = queryParams();
var redirectUri = decodeURIComponent(qp.redirect_uri);
var qindex = redirectUri.indexOf('?');
if (qindex != -1) {
qparams = redirectUri.substring(qindex);
console.log("qstring: "+qparams);
}
window.addEventListener('keyup', function(event) {
if(event.keyCode == 13){
onSelect();
}
}, true);
window.addEventListener('keyup', function(event) {
if(event.keyCode == 13){
onSelect();
}
}, true);
var path = location.pathname.replace("/mse/remote/loginSettings.html", "");
console.log("current path: "+path);
document.getElementById('uri').value = path;
onInputTextChange();
onInputTextChange();
}
function onSelect() {
// Logout
document.cookie = 'MSE_Authorized=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/';
// var page = "mse/remote/remote.html";
// Logout
document.cookie = 'MSE_Authorized=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/';
// Set new redirects
var date = new Date();
date.setTime(date.getTime()+(5*365*24*60*60*1000));
var expires = date.toGMTString();
document.cookie = 'MSE_RedirectBase='+newBaseUri+';expires='+expires+';path=/';
// Set new redirects
var date = new Date();
date.setTime(date.getTime()+(5*365*24*60*60*1000));
var expires = date.toGMTString();
document.cookie = 'MSE_BaseRedirect='+newBaseUri+';expires='+expires+';path=/';
if ($('#cbUseIDP').is(':checked')) {
document.cookie = 'MSE_RedirectPageRemote='+remoteUriIdp+';expires='+expires+';path=/';
document.cookie = 'MSE_RedirectUseIDP=true;expires='+expires+';path=/';
}
else {
// Clear cookie to use default page
document.cookie = 'MSE_RedirectPageRemote=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/';
document.cookie = 'MSE_RedirectUseIDP=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/';
}
// Redirect to routing uri (remote.html in this folder)
location.replace(routingUri+qparams);
......@@ -45,7 +63,11 @@
function onCancel() {
// Redirect to routing uri (remote.html in this folder)
location.replace(routingUri+qparams);
// location.replace(routingUri+qparams);
// No, redirect to caller instead.
var qp = queryParams();
location.replace(qp.redirect_uri);
}
function onReset() {
......@@ -54,7 +76,9 @@
document.cookie = 'MSE_Authorized=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/';
// Clear redirects
document.cookie = 'MSE_BaseRedirect=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/';
document.cookie = 'MSE_RedirectBase=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/';
document.cookie = 'MSE_RedirectPageRemote=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/';
document.cookie = 'MSE_RedirectUseIDP=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/';
// Redirect to routing uri (remote.html in this folder)
location.replace(routingUri+qparams);
......@@ -93,6 +117,7 @@
newBaseUri = uri;
// Check for remote.html
var testUri = uri + remoteUri;
var request = new XMLHttpRequest();
request.open("HEAD", testUri, true);
......@@ -102,6 +127,40 @@
}
}
request.send(null);
// Check for idp_login.php
var testUri2 = uri + remoteUriIdp;
var request2 = new XMLHttpRequest();
request2.open("HEAD", testUri2, true);
request2.onreadystatechange = function() {
if (request2.readyState == 4) {
if (request2.status == 200) {
$('#cbLabel').removeClass('hidden');
var page = readCookie("MSE_RedirectUseIDP");
if (page && page == 'true') {
// Use this if we upgrade to version 1.9 or higher
//$('#cbUseIDP').prop('checked', true).checkboxradio('refresh');
//$("#cbUseIDP").attr("checked", "checked").checkboxradio("refresh");
// jquery is broken. Do it manually
$('.ui-icon').removeClass('ui-icon-checkbox-off ui-checkbox-off').addClass('ui-icon-checkbox-on ui-checkbox-on');
$('#cbLabel').removeClass('ui-checkbox-off').addClass('ui-checkbox-on');
}
else {
// Use this if we upgrade to version 1.9 or higher
//$('#cbUseIDP').prop('checked', false).checkboxradio('refresh');
//$("#cbUseIDP").removeAttr("checked").checkboxradio("refresh");
// jquery is broken. Do it manually
$('#cbLabel').removeClass('ui-checkbox-on').addClass('ui-checkbox-off');
}
}
else {
$('#cbLabel').addClass('hidden');
}
}
}
request2.send(null);
}
}, 200)
......@@ -121,3 +180,18 @@ function queryParams() {
})();
return uriParams;
}
(function(){
var cookies;
function readCookie(name,c,C,i){
if(cookies){ return cookies[name]; }
c = document.cookie.split('; ');
cookies = {};
for(i=c.length-1; i>=0; i--){
C = c[i].split('=');
cookies[C[0]] = C[1];
}
return cookies[name];
}
window.readCookie = readCookie;
})();
......@@ -91,6 +91,16 @@ var Remote = (function () {
remote.onLoad = function() {
// Pre-check for not logged in and using external IDP.
var cookie = dojo.cookie(K.cookieAuthorized);
if (!cookie || cookie == 'deleted') {
// Not logged in
cookie = dojo.cookie("MSE_RedirectUseIDP");
if (cookie && cookie == 'true') {
window.location.replace(Url.idpLogin()+window.location.search);
}
}
var mobileAgent = window.mobilecheck();
var desktop = navigator.userAgent.indexOf("simulated") > -1;
......@@ -1266,6 +1276,12 @@ var Remote = (function () {
window.location.replace(settingsUri);
}
remote.logoutIDP = function() {
document.cookie = "MSE_Authorized" + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
var uri = Url.idpLogout()+window.location.search;
window.location.replace(uri);
}
return remote;
}());
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