Last updated Dec 8, 2017

Using authentication in your gadget

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

How do I use authentication in my gadget?

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' and 'optional' in the gadget XML:

    1
    2
    <Optional feature="atlassian.util" />
    <Require feature="oauthpopup" />
    #oauth
    
  2. Include the following resources at the beginning of the CDATA section:

    1
    2
    #requireResource("com.atlassian.gadgets.publisher:ajs-gadgets")
    #includeResources()
    

    See note about the path GADGETDEV:below.

  3. Construct a gadget passing the URL in the useOauth param:

    1
    2
    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:

    1
    2
    AJS.$.ajax({
      url: "/rest/gadget/1.0/filtersAndProjects",
      type: "GET",
      data: ({projectsOnly : "true"}),
      dataType: "json",
      success: function(msg) {
        alert(msg);
      }
    });
    

 

Path to JavaScript Framework

The path to the Atlassian Gadgets JavaScript Framework is as follows:

  • In Atlassian Gadgets 1.0.x, the JavaScript framework is available in JIRA only and is not part of the Atlassian Gadgets framework. The path in JIRA 4.0.x is: #requireResource("com.atlassian.jira.gadgets:common").
  • In Atlassian Gadgets 2.0 and later, the JavaScript framework has been extracted from JIRA and made part of the Gadgets framework. The path is: #requireResource("com.atlassian.gadgets.publisher:ajs-gadgets")

Gadget Developers' JavaScript Cookbook Using the Atlassian Gadgets JavaScript Framework

Rate this page: