UNPKG

hellojs-xiaotian

Version:

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

108 lines (94 loc) 2.78 kB
<!DOCTYPE html> <link rel="stylesheet" href="/adorn/adorn.css"/> <script src="/adorn/adorn.js" async></script> <script src="client_ids.js"></script> <link rel="stylesheet" href="./helper/alert.css"/> <title>hello( slack )</title> <h1>hello( slack )</h1> <blockquote> <p>Checkout the <a href="https://api.slack.com/">Slack API</a>.</p> <p>The API uses the explicit OAuth2 grant flow, therefore requires an <a href="../#oauth-proxy">oauth_proxy</a>.</p> </blockquote> <button onclick="login();" id="profile">Login Slack</button> <script src="../src/hello.js" class="pre"></script> <script class="pre"> hello.init({ slack: { name: 'Slack', oauth: { version: 2, auth: 'https://slack.com/oauth/authorize', grant: 'https://slack.com/api/oauth.access', response_type: 'code' }, refresh: false, scope: { basic: 'identify, read' }, scope_delim: ',', base: 'https://slack.com/api/', get: { me: function(p, callback) { // The identity profile does not include the picture if (p.query.id) { callback('users.info?user=@{id}'); } else { // Get the user id hello('slack').api('auth.test').then(function(r) { callback('users.info?user=' + r.user_id); }); } } }, wrap: { me: function(o) { // A basic identity profile as provided by 'auth.test' if (typeof(o.user) === 'string') { o.name = o.user; o.id = o.user_id; } // A more elaborate user profile as provided by 'users.info' else if (typeof(o.user) === 'object') { var _ = o.user; o.name = _.name; o.id = _.id; o.email = _.profile.email; o.thumbnail = _.profile.image_48; o.picture = _.profile.image_512; } } }, xhr: function (p, qs) { qs.token = qs.access_token; delete qs.access_token return true; }, form: false, jsonp: false } }); </script> <script class="pre"> var profile = document.getElementById('profile'); function login() { var hi = hello('slack'); hi .login() .then(function() { return hi.api('me') }) .then(function(r) { profile.innerHTML = '<img src="' + r.thumbnail + '" width=24/>Connected to Slack.com as ' + r.name; }, console.error.bind(console) ); } </script> <p>Initiate box client</p> <script class="pre"> hello.init({ slack : '11964040065.11961640928' }, { redirect_uri: '../redirect.html', oauth_proxy: OAUTH_PROXY_URL }); </script>