Created
February 23, 2017 21:25
-
-
Save bryan-rojas-liquor/a20dd258d855abe7bddda4b91a62ba8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!function(t,e,n){function a(t){var a=e.createElement("script");a.type="text/javascript",a.async=!1,a.src=("https:"===e.location.protocol?"https":"http")+":"+n,(t||e.body||e.head).appendChild(a)}function o(){var t=e.getElementsByTagName("script"),n=t[t.length-1];return n.parentNode} var p=o();t.spotId="sp_HzZnwWye",t.parentElement=p,a(p)}(window.SPOTIM={},document,"//www.spot.im/launcher/bundle.js"); | |
if ( window.SPOTIM && window.SPOTIM.startSSO ) { | |
startSSO(); | |
} else { | |
document.addEventListener('spot-im-api-ready', startSSO, false); | |
} | |
var startSSO = function() { | |
var callback = function (codeA, completeSSOCallback) { | |
//Ajax Call: SSO Token, Code A, User Details - PK & username (must) | |
//completeSSOCallback(codeB); | |
// data.user_id = , data.code_a = codeA; | |
$.get(url, data, function(codeB){ | |
},'json'); | |
}; | |
window.SPOTIM.startSSO(callback) | |
.then( function(result) { | |
//result.type == 'SSO_Complete' or result.type == 'SSO_AlreadyLoggedIn' | |
}) | |
.catch( function(reason) { | |
//reason contains error details | |
}); | |
}; | |
//https://developers.spot.im/sso/frontend-implementation | |
document.addEventListener('spot-im-start-sso', function(event) { | |
var codeA = event.detail.codeA; | |
var callback = event.detail.callback; | |
window.spotImSSOCallback = callback; | |
startSSO(codeA); | |
}, false); | |
function startSSO(codeA) { | |
var httpRequest = new XMLHttpRequest(); | |
httpRequest.onreadystatechange = function() { | |
if (httpRequest.readyState === XMLHttpRequest.DONE) { | |
if (httpRequest.status === 200) { | |
var codeB = httpRequest.responseText; | |
window.spotImSSOCallback(codeB); | |
} | |
} | |
}; | |
httpRequest.open('GET', 'https://api.yoursite.com/sso'); | |
httpRequest.send(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment