|
<html> |
|
<head> |
|
<title></title> |
|
</head> |
|
<body> |
|
<script src="jsOAuth-1.3.min.js"></script> |
|
<script> |
|
|
|
var config = { |
|
consumerKey: "YOUR-K3Y", |
|
consumerSecret: "YOUR-53CRET", |
|
|
|
requestTokenUrl: "https://api.example.com/oauth/request_token", |
|
authorizationUrl: "https://api.example.com/oauth/authorize", |
|
accessTokenUrl: "https://api.example.com/oauth/access_token" |
|
}; |
|
var oauth = new OAuth(config); |
|
|
|
oauth.fetchRequestToken(openAuthoriseWindow, failureHandler); |
|
|
|
function openAuthoriseWindow(url) |
|
{ |
|
var wnd = window.open(url, 'authorise'); |
|
setTimeout(waitForPin, 100); |
|
|
|
function waitForPin() |
|
{ |
|
if (wnd.closed) |
|
{ |
|
var pin = prompt("Please enter your PIN", ""); |
|
oauth.setVerifier(pin); |
|
oauth.fetchAccessToken(getSomeData, failureHandler); |
|
} |
|
else |
|
{ |
|
setTimeout(waitForPin, 100); |
|
} |
|
} |
|
} |
|
|
|
function getSomeData() |
|
{ |
|
oauth.get("https://api.example.com/oauth/something/?format=json", function (data) { |
|
console.log(data.text); |
|
}, failureHandler); |
|
} |
|
|
|
function failureHandler(data) |
|
{ |
|
console.error(data); |
|
} |
|
</script> |
|
</body> |
|
</html> |