Created
November 16, 2012 17:52
-
-
Save eojthebrave/4089404 to your computer and use it in GitHub Desktop.
Yammer | OAuth 2 | Implicit Grant
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
<html> | |
<head> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> | |
<script type="text/javascript" charset="utf-8"> | |
$(function () { | |
var extractToken = function(hash) { | |
var match = hash.match(/access_token=(\w+)/); | |
return !!match && match[1]; | |
}; | |
var CLIENT_ID = ''; | |
var AUTHORIZATION_ENDPOINT = 'https://www.yammer.com/dialog/oauth'; | |
var RESOURCE_ENDPOINT = 'https://www.yammer.com/api/v1/messages/following.json'; | |
var token = extractToken(document.location.hash); | |
if (token) { | |
$('div.authenticated').show(); | |
$('span.token').text(token); | |
$.ajax({ | |
url: RESOURCE_ENDPOINT, | |
method: 'GET' | |
, beforeSend: function (xhr) { | |
xhr.setRequestHeader('Authorization', "OAuth " + token); | |
xhr.setRequestHeader('Accept', "application/json"); | |
} | |
, success: function (response) { | |
var container = $('span.user'); | |
if (response) { | |
container.text(response); | |
} else { | |
container.text("An error occurred."); | |
} | |
} | |
}); | |
} else { | |
$('div.authenticate').show(); | |
var authUrl = AUTHORIZATION_ENDPOINT + | |
"?response_type=token" + | |
"&client_id=" + CLIENT_ID + | |
"&grant_type=authorization_code" + | |
"&redirect_uri=" + window.location; | |
$("a.connect").attr("href", authUrl); | |
} | |
}); | |
</script> | |
<style> | |
.hidden { | |
display: none; | |
} | |
</style> | |
</head> | |
<div class="authenticate hidden"> | |
<a class="connect" href="">Connect</a> | |
</div> | |
<div class="authenticated hidden"> | |
<p> | |
You are using token | |
<span class="token">[no token]</span>. | |
</p> | |
<p> | |
Response is | |
<span class="user">[no response]</span>. | |
</p> | |
</div> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment