Forums

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

Authenticating url on server side

Hari Prasath P
Contributor
October 9, 2018

In client side I have written my code as below,

$.ajax({
type: "GET",
beforeSend: function (request) {
var jwt = document.head.querySelector("[name~=token][content]").content;
request.setRequestHeader("Authorization", 'JWT '+ jwt);
},
url: "/test",
success: function(data){
alert("success");
}
});

using this ajax request from client side I want to get the data on server side by authenticating the jwt token sent from client side. Server side(router code) is below,

app.get('/test', addon.checkValidToken(), function(req, res){
....
});

So, how can I authenticate or validate the url using jwt token by sending through request.SetHeaderRequest? I referred this url, but I couldn't figure out any solution for it.

1 answer

0 votes
Daniel Eads
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 11, 2018

Hey Hari,

I'm not a developer (giant disclaimer!) but I did read through the Atlassian Connect document you linked and noticed that the document expects you to have set the token somewhere client-side already. I see you've got a line to try and fetch it from the document head. Have you double-checked that it's actually set? Otherwise it looks good to me (again, not a developer) based on the Connect documentation.

We also have a dedicated Developer Community that might be good to check out for plugin development related questions. Since the topics are more focused, it's easier for other developers to watch the questions coming in and provide guidance.

Cheers,
Daniel

Hari Prasath P
Contributor
October 12, 2018

Hi @Daniel Eads,

Yes the value is set to the document head. But, authorization fails as that JWT token on server side throws the error 401. Also found a topic similar to my case in developer community, unfortunately there was no solution. So, I have posted a topic in developer community. Thanks a lot.

Cheers,

Hari

Suggest an answer

Log in or Sign up to answer