Basic authentication failed but email address: API token succeed

Pak Yu January 24, 2019

I was following this instruction to use curl to retrieve JIRA issues  (https://developer.atlassian.com/cloud/jira/software/jira-rest-api-basic-authentication/ ).

I was able to use -u "email_adrres:API_token"  (return with JSON data ) but I was not able to use Basic authentication (401 error).  I used the  decoded "email_adrres:API_token" with basic 64

2 answers

1 accepted

1 vote
Answer accepted
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 28, 2019

You cited the Jira Server documentation, but your question is tagged with a Jira-cloud question.  This is confusing, because the documentation for one platform does not always apply exactly to the other.  If you're using Jira Cloud, then I would recommend trying to follow the steps in https://developer.atlassian.com/cloud/jira/software/jira-rest-api-basic-authentication/ instead.

If this doesn't help, could you let us know more about which way you're trying to make this REST call? (using curl, postman, or some other utility for examples)  I would be interested to see the specific syntax you are trying to use here if you're using curl for example.

Pak Yu January 28, 2019

Thanks for pointing that out. However, in this case the command is the same with curl (Linux). I was trying to use basic auth headers method.

 

I first encode the email_address:API_token with this command (on linux):

openssl enc -base64 <<< "myusername@email.com:API token"

then I use this curl command ( the below command is just the example from the doc)  :

curl -D- \
   -X GET \
   -H "Authorization: Basic ZnJlZDpmcmVk" \
   -H "Content-Type: application/json" \
   "https://your-domain.atlassian.net/rest/api/2/issue/QA-31"

 Then I got the 401 error.

 

However, I am able to get the JSON data when i use this command:

curl -D- \
   -u myusername@email.com:api_token \
   -X GET \
   -H "Content-Type: application/json" \    
"https://your-domain.atlassian.net/rest/api/2/issue/QA-31"


  

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 30, 2019

Hi Pak,

Thanks for letting me know the steps you are taking here.  I think I can see the problem now.   The method you are using to encode the string is known to include an additional carriage return.   Check out this comment https://superuser.com/questions/120796/how-to-encode-base64-via-command-line/133253#133253

From that thread:

Openssl can be used more succinctly:

echo -n 'input' | openssl base64

[ echo -n -> must be used, or encoding will be done including new line character ]

I tried this in my own command line.  I noticed that when I use the steps you followed (and when I excluded the '-n' parameter from this method), I got an additional 4 characters on the end of my encoded string.  However when I used the command line statement of:

echo -n 'user@example.com:apitokenstring' | openssl base64

The encoded string was 4 characters shorter than with your steps or without the -n.  It looks like the carriage return is getting added to your string and in turn throwing off the string.

I hope this helps.

Andy

Pak Yu January 30, 2019

Thanks, Andy. It works. I wouldn't have thought of that .

0 votes
vishal mantri January 27, 2020

Using the VBScript, can you please let us know how to perform the Basic authentication

Suggest an answer

Log in or Sign up to answer