Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Corrected links that should have been relative instead of absolute.

This page is part of the Gadget Developers' JavaScript Cookbook.

How do I use authentication in my gadget?

Excerpt

Specify the appropriate features as 'required' in your gadget XML, include the necessary resources in the CDATA section, and use the useOauth parameter when constructing your gadget:

  1. Specify the appropriate features as 'required' in the gadget XML:
    Code Block
    xml
    xml
    <Require feature="oauthpopup" />
    #oauth
    
  2. Include the following resources at the beginning of the CDATA section:
    Code Block
    xml
    xml
    #requireResource("com.atlassian.jira.gadgets:common")
    #includeResources()
    
  3. Construct a gadget passing the URL in the useOauth param:
    Code Block
    javascript
    javascript
    var gadget = AJS.Gadget({
      baseUrl: "__ATLASSIAN_BASE_URL__",
      useOauth: "/rest/gadget/1.0/currentUser",
      ...
    
  4. Any Ajax call will now go through the authentication steps if required.For example:
    Code Block
    javascript
    javascript
    AJS.$.ajax({
      url: "/rest/gadget/1.0/filtersAndProjects",
      type: "GET",
      data: ({projectsOnly : "true"}),
      dataType: "json",
      success: function(msg) {
        alert(msg);
      }
    });
    

RELATED TOPICS

Gadget Developers' JavaScript Cookbook
Using the Atlassian Gadgets JavaScript Framework