Skip to content

Instantly share code, notes, and snippets.

@sarfarazansari
Created April 11, 2018 09:42
Show Gist options
  • Save sarfarazansari/76a8157cb54a0e26f3e976ce0d6d0b0c to your computer and use it in GitHub Desktop.
Save sarfarazansari/76a8157cb54a0e26f3e976ce0d6d0b0c to your computer and use it in GitHub Desktop.
sso js
var options = {
height: 684, // sets the height in pixels of the window.
width: 585, // sets the width in pixels of the window.
toolbar: 0, // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
scrollbars: 0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
status: 0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
resizable: 0, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
left: 0, // left position when the window appears.
top: 0, // top position when the window appears.
center: 0, // should we center the window? {1 (YES) or 0 (NO)}. overrides top and left
createnew: 0, // should we create a new window for each occurance {1 (YES) or 0 (NO)}.
location: 0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
menubar: 0 // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
};
function popupWindow(url, title, options) {
// Fixes dual-screen position Most browsers Firefox
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
var left = ((width / 2) - (options.width / 2)) + dualScreenLeft;
var top = ((height / 2) - (options.height / 2)) + dualScreenTop;
var parameters = "location=" + options.location +
",menubar=" + options.menubar +
",height=" + options.height +
",width=" + options.width +
",toolbar=" + options.toolbar +
",scrollbars=" + options.scrollbars +
",status=" + options.status +
",resizable=" + options.resizable +
",screenX=" + options.left +
",screenY=" + options.top +
",left=" + left +
",top=" + top;
var loginWindow = window.open(url, title, parameters);
// Puts focus on the newWindow
if (window.focus) {
loginWindow.focus();
}
}
function ssoButton(ssoDiv) {
var redirectUrl = 'https://viasocket.com/sso?redirect_uri=' + ssoDiv.getAttribute('data-redirect-uri');
var viewType = 'button';
if (ssoDiv.getAttribute('data-source')) {
redirectUrl += '&src=' + ssoDiv.getAttribute('data-source');
}
if (ssoDiv.getAttribute('data-token-key')) {
redirectUrl += '&token_key=' + ssoDiv.getAttribute('data-token-key');
}
if (ssoDiv.getAttribute('data-view') && ssoDiv.getAttribute('data-view') === 'link') {
viewType = 'link';
}
if (viewType == 'button') {
var element = document.createElement("div");
// element.type = "button";
element.name = "sokt-sso";
element.innerHTML = `<div id="__customBtn">
<div class="__btnWrapper">
<span class="__icon"><img src="https://viasocket.com/app/favicon.png" width="30px" height="30px"style="padding:2px;"></span>
<span class="__buttonText">Sign in</span>
</div>
</div>`;
} else if (viewType == 'link') {
var element = document.createElement("a");
element.type = "button";
element.style.cursor = "pointer";
element.name = "sokt-sso";
element.innerText = "Sign in";
}
element.onclick = function() {
popupWindow(redirectUrl, 'Login with Socket', options)
};
return element
}
window.onload = function(e){
var ssoDiv = document.getElementById('sokt-sso');
ssoDiv.appendChild(ssoButton(ssoDiv));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment