Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I authenticate my GET requests as a different user in Confluence?

Ben Li August 1, 2019

I've been trying to get a Jira dashboard gadget to display in a confluence page, specifically the gantt chart from the Jira BigPicture plugin. Since the gadget when displayed in Confluence will vary depending on whether or not the user has been approved, my goal is to circumvent this feature.

What I've discovered is that using inspect element or a rest client to pull a page as an approved user will allow me to grab the code for a gadget that can be displayed. However, when I try to use javascript (using the confluence html macro), or a Java servlet, or use the REST api to pull the body.view code, I cannot seem to get the code to either authenticate as an approved user, or pull valid code.

 

Does anybody have any thoughts or approaches I can do?

1 answer

0 votes
Jack Nolddor _Sweet Bananas_
Atlassian Partner
August 1, 2019

Hi,
You can use Basic-Auth to call Jira REST API.
Assuming you are using jQuery to make an Ajax call, this should work if you use an autorized user account and their related password:

Use jQuery's beforeSend callback to add an HTTP header with the authentication information:

beforeSend: function (xhr) {    
xhr
.setRequestHeader ("Authorization", "Basic " + btoa(username + ":" + password)); },
Ben Li August 2, 2019

I've tried setting the authentication in the header of my ajax calls, but it seems like Confluence overwrites this when I make the request, as It appears that I'm still authenticated as the current user rather than the authorized user. It is still the case with with beforeSend.

 

Thanks for the new option though!

Ben Li August 2, 2019

For context, here's the code I'm using to grab another page and insert it into an existing div.

 

<div id="test">
<p>
hi
</p>
</div>

<script>
$("#test").html("<p>getting gantt chart...</p>");
url = "http://localhost:8090/display/ds/gantt";
$.ajax({
url: url,
type: "GET",
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic " + btoa("admin" + ":" + "admin"));
},
}).done(function(data){
var start = data.search('<p><div class="gadgetContainer').toString();
var end = data.search('</iframe></div></p>');
//var mid = data.search('<a');
$("#test").html(data.substring(start, end+19) + "</iframe></div></p>");
console.log(data.substring(start, end+19) + "</iframe></div></p>");
//$("#test").html("<p>" + "dab" + "</p>");
}).fail(function (e){
$("#test").html("<p>Failed to get chart</p>");
});
</script>

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events