JIRA JSONP Demo

HTML

<!DOCTYPE html>
<html>

  <body>

    <div class="loggedOut">
      <p>
        Looks like you're not logged in.
      </p>
      <p>
        Make sure you log into
        <a href="https://jira.atlassian.com" target="_blank">https://jira.atlassian.com</a> first then come back and refresh the page.
      </p>
    </div>
    <div class="loggedIn" style="display:none">
      <p>
        Hello <b><span class="displayName"></span></b>!
      </p>
      <p>
        Looks like you belong to the following groups: <span class="groups"></span>
      </p>
      <hr/>

      <b>GET /rest/auth/1/session</b>
      <pre class="sessionOut"></pre>

      <br/>

      <b>GET /rest/api/2/user?username=<span class="username"></span>&expand=groups</b>
      <pre class="userOut"></pre>
    </div>

    <script src="https://jira.atlassian.com/rest/auth/1/session?jsonp-callback=authCallback" type="text/javascript"></script>

  </body>

</html>

JavaScript

// Called after /session is called getting the username

function authCallback(d) {
  var head = document.getElementsByTagName('head')[0];
  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.src = 'https://jira.atlassian.com/rest/api/2/user?username=' + d.name + '&expand=groups&jsonp-callback=groupsCallback';
  head.appendChild(script);
  $('.sessionOut').html(JSON.stringify(d, null, 2));
  $('.loggedOut').hide();
  $('.loggedIn').show();
}

// Called after /user?username= is called getting the user's displayName and groups

function groupsCallback(d) {
  var names = $.map(d.groups.items, function(i, e) {
    return i.name;
  });
  $('.username').html(d.name);
  $('.displayName').html(d.displayName);
  $('.groups').html(names.join(', '));
  $('.userOut').html(JSON.stringify(d, null, 2));
}