Forums

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

How to use Personal Access Token with Jira .NET SDK

Alfredo Pisano
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 29, 2023

I havent found a solution to this problem yet, and the only other similar question on here was resolved but the links of the solution are obsolete.

 

When i try to use the generate JiraClient from this output if i use my password it works, if i use my Personal Access Token (PAT) which i generated on my account from JIRA i get a 401 Error.

return Jira.CreateRestClient(jUrl, userName, userPersonalJiraToken);

1 answer

0 votes
Fabio Villani
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 19, 2025

Hi, 

a bit late to the party, but i solved the problem this way:

Create a class authenticator

 

public class PATTokenAuthentication : RestSharp.Authenticators.IAuthenticator
{
   private string _token;
   public PATTokenAuthentication(string token)
   {
      _token = token;
   }

   public void Authenticate(IRestClient client, IRestRequest request)
   {
      request.AddHeader("Authorization", $"Bearer {_token}");
   }
}

And then use it in the RestSharp settings:

var jira = Jira.CreateRestClient("<URL>", null, null);

jira.RestClient.RestSharpClient.Authenticator = new PATTokenAuthentication("<Your PAT>");

var issuesQuery = from i in jira.Issues.Queryable
orderby i.Created
select i;

var issuesList = issuesQuery.ToList();

issuesList should be populated correctly

Suggest an answer

Log in or Sign up to answer