Successfully authenticated using OAuth 2.0 but I always get a 401
Asked by BernardoCoSo:

I am writing C# code to interact with the Jira API and even though I can get Authenticated using OAuth I still get a 401 whenever I try to call the API.

I am creating my HttpClient class using the "bearer \<token\>" string and I am calling the right endpoints, so I am not sure what the problem could be.


Answers:
author: Anandhi Arumugam
body: Hi [@BernardoCoSo](/t5/user/viewprofilepage/user-id/5561685) Can you share the Endpoint you are trying to reach? Have you checked if the user account that you are using has the required permissions to perform the operation?

Permissions to check:

1. Jira application access

2. Project permission scheme - user part of right roles

3. Are you trying to do an system admin operation? Then the user should have admin access.

Hope this helps.

comments: author: BernardoCoSo
body: Hey Anandhi,

Thank you for the suggestions!

I am trying to use the "rest/api/3/myself" and a few others. I have given myself all the Jira Platform and Management permissions and I am using the scopes it recommends in the "Classic Jira platform REST API authorization URL".


author: Anandhi Arumugam
body: [@BernardoCoSo](/t5/user/viewprofilepage/user-id/5561685) Were you able to try this endpoint on a browser or postman? Check if your credentials are right?


author: BernardoCoSo
body: I think the problem has something to do with exchanging my authorization code for the token. I am getting something that doesn't look like an access token!  

I tried getting the "token" to work in postman but I get the same error.


author: Anandhi Arumugam
body: Did you generate an API token from id.atlassian.com?


author: BernardoCoSo
body: I tried by doing it that way and by using OAuth but none of the ways work.


author: Anandhi Arumugam
body: [@BernardoCoSo](/t5/user/viewprofilepage/user-id/5561685) Please use Basic Auth with emailaddress/API Token and see if that works


author: BernardoCoSo
body: I still get the "Client must be authenticated to access this resource." error message.


author: Anandhi Arumugam
body: Is this the same on Postman? Can you try with anyother API endpoints?


author: BernardoCoSo
body: It's the same in Postman and my C# tool, and when I try with the user endpoint I get:  
"You are not authenticated. Authentication required to perform this operation."


author: Anandhi Arumugam
body: Can you access Jira through UI? Are you using Jira Cloud or Jira DC?

1. Use Basic Auth - Username and API Token  
2. Try GET on /rest/api/2/project/{projectIdOrKey} endpoint

If this still throws 401, Do you have application access on Jira? Can you access your content through the UI?


author: BernardoCoSo
body: Supposedly the project exists, but I get this now:  

{  
"errorMessages": \[  
"No project could be found with key 'KAN123'."  
\],  
"errors": {}  
}


author: Anandhi Arumugam
body: Do you have access to this project? can you view this issue through a browser?


author: BernardoCoSo
body: I was using the wrong key, to do the basic authentication! I changed it on Postman and it worked, I also did it in my code successfully!

Thank you so much for the help and patience!


author: Anandhi Arumugam
body: Glad it worked!


Tags: cloud

jira-cloud