Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Successfully authenticated using OAuth 2.0 but I always get a 401

BernardoCoSo August 6, 2024

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.

1 answer

0 votes
Anandhi Arumugam _Cprime_
Community Champion
August 6, 2024

Hi @BernardoCoSo 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.

BernardoCoSo August 6, 2024

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

Anandhi Arumugam _Cprime_
Community Champion
August 6, 2024

@BernardoCoSo Were you able to try this endpoint on a browser or postman? Check if your credentials are right?

BernardoCoSo August 6, 2024

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.

Anandhi Arumugam _Cprime_
Community Champion
August 6, 2024

Did you generate an API token from id.atlassian.com?

BernardoCoSo August 6, 2024

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

Anandhi Arumugam _Cprime_
Community Champion
August 6, 2024

@BernardoCoSo  Please use Basic Auth with emailaddress/API Token and see if that works

BernardoCoSo August 6, 2024
I still get the "Client must be authenticated to access this resource." error message.
Anandhi Arumugam _Cprime_
Community Champion
August 6, 2024

Is this the same on Postman? Can you try with anyother API endpoints?

BernardoCoSo August 6, 2024

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."
Anandhi Arumugam _Cprime_
Community Champion
August 6, 2024

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?

BernardoCoSo August 6, 2024
Supposedly the project exists, but I get this now:

{
    "errorMessages": [
        "No project could be found with key 'KAN123'."
    ],
    "errors": {}
}
Anandhi Arumugam _Cprime_
Community Champion
August 6, 2024

Do you have access to this project? can you view this issue through a browser?

BernardoCoSo August 7, 2024

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!

Anandhi Arumugam _Cprime_
Community Champion
August 7, 2024

Glad it worked!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events