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:
<span> <br>url: "https://myjira.com/rest/auth/1/session",</span><span> <br>type: 'GET',</span><span> <br>beforeSend: function(xhr) {</span><span> <br> xhr.setRequestHeader("Authorization", "Bearer <accesstoken>");<br></span><span> xhr.withCredentials = true;</span><span> <br>},</span><span> <br>success: function(response) {</span><span> <br> alert("success");</span><span> <br>},</span><span> <br>error: function(error) {</span><span> <br> alert("error");</span><span> <br>}</span><span>});</span><span>$.ajax ({</span>
Doing this same call using basic authentication works fine, such as:
var username = $("#username").val();<br>var password = $("#password").val();<br>$.ajax ({ <br>url: "https://myjira.com/rest/auth/1/session", <br>type: 'GET', <br>beforeSend: function(xhr) { <br> var base64 = btoa(username + ':' + password); <br> xhr.setRequestHeader("Authorization", "Basic " + base64); <br> xhr.withCredentials = true; <br>}, <br>success: function(response) { <br> alert("success"); <br>}, <br>error: function(error) { <br> alert("error"); <br>}});
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!