UNPKG

hellojs-xiaotian

Version:

A clientside Javascript library for standardizing requests to OAuth2 web services (and OAuth1 - with a shim)

74 lines (62 loc) 1.81 kB
<!DOCTYPE html> <link rel="stylesheet" href="/adorn/adorn.css"/> <script src="/adorn/adorn.js" async></script> <script src="client_ids.js"></script> <script src="../src/hello.polyfill.js"></script> <script src="../src/hello.js"></script> <script src="../src/modules/github.js"></script> <title>hello( github )</title> <h1>hello( github )</h1> <button id='github' onclick="profile('github');">Get Profile</button> <script class="pre"> function profile(network) { var github = hello(network); github.login().then(function() { // get user profile data return github.api('me'); }) .then(function(p) { document.getElementById(network).innerHTML = "<img src='"+ p.thumbnail + "' width=24/>Connected to "+ network +" as " + p.name; }); } </script> <h2>Get user email</h2> <button onclick="userEmail('github', 'email');">Get email</button> <pre id="email"></pre> <script class="pre"> function userEmail(network, target) { var github = hello(network) github.login({ scope:'email' }) .then(function() { // Get a bespoke endpoint from github return github.api('/user/emails'); }).then(function(r) { document.getElementById(target).innerHTML = JSON.stringify(r, null, 2); }); } </script> <h2>List user repos</h2> <button onclick="userRepos('github', 'repo_list');">Get a list of repos</button> <pre id="repo_list"></pre> <script class="pre"> function userRepos(network, target) { var github = hello(network) github.login() .then(function() { // Get a bespoke endpoint from github return github.api('/user/repos'); }).then(function(r) { document.getElementById(target).innerHTML = JSON.stringify(r, null, 2); }); } </script> <script class="pre"> hello.init({ github : GITHUB_CLIENT_ID },{ redirect_uri : '../redirect.html', // oauth_proxy : OAUTH_PROXY_URL }); </script>