Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Authorize API call using OAuth access token and AJAX

How am I supposed to authorize an API call to create a new session with OAuth? I have gone through the steps to generate an access token, but I am always returned 401 ( "You are not authenticated. Authentication required to perform this operation." )


my call:

$.ajax ({    
url: "https://myjira.com/rest/auth/1/session",

type: 'GET',

beforeSend: function(xhr) {

xhr.setRequestHeader("Authorization", "Bearer <accesstoken>");
xhr.withCredentials = true;
},

success: function(response) {

alert("success");

},

error: function(error) {

alert("error");

}
});

 

Doing this same call using basic authentication works fine, such as:

var username = $("#username").val();
var password = $("#password").val();
$.ajax ({

url: "https://myjira.com/rest/auth/1/session",

type: 'GET',

beforeSend: function(xhr) {

var base64 = btoa(username + ':' + password);
xhr.setRequestHeader("Authorization", "Basic " + base64);
xhr.withCredentials = true;
},

success: function(response) {

alert("success");

},

error: function(error) {

alert("error");

}
});

 

How am I supposed to authorize this call for a new session using oauth? I've spent days now searching for a working example with no luck. Thanks!

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
Community showcase
Posted in Jira Software

Presenting the "Best of 2020" Jira Software roundup!

Catch up with Atlassian Product Managers in our 2020 Demo Den round-up! From Advanced Roadmaps to Code in Jira to Next-Gen Workflows, check out the videos below to help up-level your work in the new ...

7,105 views 8 28
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you