Skip to content

Instantly share code, notes, and snippets.

@waqaskhan137
Created January 23, 2017 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waqaskhan137/37b09838e8afb131e68f7ac2e1212ce3 to your computer and use it in GitHub Desktop.
Save waqaskhan137/37b09838e8afb131e68f7ac2e1212ce3 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>oAuth</title>
<script type="text/javascript" src="/desktop/assets/js/jquery.min.js"></script>
<script>
// Read a page's GET URL variables and return them as an associative array.
function getUrlVars() {
///////////////////// FILL OUT THIS SECTION /////////////////////
var finesseDomain = "192.168.1.61"; // Fill in your Finesse domain
var OAuthRedirectURI = "https://api.ciscospark.com/v1/authorize?client_id=C2cdaaecafa2126ee7d24d3bdf37f4cecfe988d7694af2f558ca3060915ced930&response_type=code&redirect_uri=http%3A%2F%2F192.168.1.88%3A7070%2Foauth.html&scope=spark%3Amessages_write%20spark%3Arooms_read%20spark%3Ateams_read%20spark%3Amessages_read%20spark%3Arooms_write%20spark%3Apeople_read%20spark%3Akms%20spark%3Ateams_write&state=set_state_here"; // Fill in the OAuth redirect URI from the Spark Integration Details page
var OAuthClientId = "C2cdaaecafa2126ee7d24d3bdf37f4cecfe988d7694af2f558ca3060915ced930"; // Fill in the OAuth Client Id from the Spark Integration Details page
var OAuthClientSecret = "33ffb6fb8e603a31504bc65eef2104013a4f077bde222f8b31faf5853006bef5"; // Fill in the OAuth Client Secret from the Spark Integration Details page
////////////////////////////////////////////////////////////////
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
if (hash[0] == "code") {
////alert(hash[0] + " = " + hash[1]);
$.ajax({
url: 'https://api.ciscospark.com/v1/access_token',
type: "post",
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
data: "grant_type=authorization_code&client_id=" + OAuthClientId + "&client_secret=" + OAuthClientSecret + "&redirect_uri=" + encodeURI(OAuthRedirectURI) + "&code=" + hash[1],
success: function(data) {
var cookieName = 'spark_access_token';
var cookieValue = data.access_token;
var myDate = new Date();
myDate.setMonth(myDate.getMonth() + 1);
document.cookie = cookieName +"=" + cookieValue + ";domain=." + finesseDomain + ";path=/";
window.close();
}
});
}
}
return vars;
}
</script>
</head>
<body onLoad="getUrlVars()">
Authenticating...
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment