Skip to content

Instantly share code, notes, and snippets.

@sohalloran
Created March 22, 2013 16:59
Show Gist options
  • Save sohalloran/5222959 to your computer and use it in GitHub Desktop.
Save sohalloran/5222959 to your computer and use it in GitHub Desktop.
OAuth Tester - user-agent flow
<!--// MAIN PAGE //-->
<!DOCTYPE html>
<html>
<head>
<title>Oauth Tester</title>
<link rel="stylesheet" href="https://app.divshot.com/css/bootstrap.css">
<script type="text/javascript">
var CLIENT_ID = '';
var CALLBACK_URL = '';
// Bootstrap the page once the DOM is ready.
window.onload = function () {
document.getElementById("loginOAuth").onclick=loginOAuth;
}
// call authorize page
function loginOAuth() {
window.open('https://login.salesforce.com/services/oauth2/authorize?response_type=token&client_id='+CLIENT_ID+'&redirect_uri='+CALLBACK_URL, 'Connect','height=524,width=675,toolbar=0,scrollbars=0,status=0,resizable=0,location=0,menuBar=0'
).focus();
}
// passed back from callback page
function setToken(msg) {
// parse url fragment
var h = {};
var item = msg.substring(1).split('&');
for(var i=0; i<item.length; i++) {
var keyval = item[i].split('=');
h[keyval[0]]=keyval[1];
}
var url = decodeURIComponent(h['id']) + '?oauth_token=' + h['access_token'];
console.log(url);
document.getElementById("results").innerHTML = '<a href="' + url + '">Identity URL</a>';
}
</script>
</head>
<body>
<h1 id="header">OAuth Tester</h1>
<div><a id="loginOAuth" href="#">login with OAuth - standalone</div>
<div><span id="results"></div>
</body>
</html>
<!--// CALLBACK PAGE //-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Callback Refresh Window</title>
<script type="text/javascript">
window.opener.setToken(window.location.hash);
self.close();
</script>
</head>
<body></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment