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

Basic authentication failed but email address: API token succeed Edited

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 Jan 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.

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 Jan 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

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

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
TAGS

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