Category Archives: Jira

Accessing Jira with OAuth Authenticated request

Posted on by 0 comment

Based on Jira OAuth authentication using DotNetAuth, we can successfully get the access token, and are able to make an authenticated request. Now we plan to use Atlassian.SDK to access Jira with oAuth authentication, but currently Atlassian.SDK only supports basic authentication. So we will need to inject little bit extra code to make this happen.

Used packages

  • Atlassian.SDK 8.5.0
  • RestSharp 105.2.3
  • DotNetAuth
  • Current DotNetAuth 1.0.5 nuget package uses old RestSharp version, and it doesn’t work with RestSharp 105.2.3, so small changes is required to align with this new RestSharp. The original DotNetAuth code can be downloaded from here.

    Integrate DotNetAuth in RestSharp RestClient

    A customized Authenticator is required to let RestClient know how to do the authenticate with DotNetAuth. This will be used when creating the RestClient.

    Once we have OAuth1aAuthenticator, we can create Rest Client with code below,

    Integrate oAuth in Atlassian.SDK

    Create a new class (JiraOAuth) which inheritants from Jira.Jira. In it, a static method called CreateRestClient is created which accepts oAuth authentication details and will return Jira instance.

    Then we can call below to create Jira instance.

    Now we have oAuth authentication support in Atlassian.SDK, the only difference is to use the new CreateRestClient to create the Jira instance, all the rest will remain the same as using basic authentication.

    Category: C#, Jira, OAuth

    Jira OAuth authentication using DotNetAuth

    Posted on by 8 comments

    In this post, we will try to connect to Jira with oAuth authentication in DotNet, I did some research, and mainly followed the instructions on Is there any JIRA OAuth implementation example in .NET and JIRA REST API Example – OAuth authentication

    Generate self-signed certificate

    OpenSSL is used for generating the certificate,

    public.pem will be required in public key field of your application in Jira application links
    private.pcks8 will be required in the client (variable consumerSecret)

    Configuring Jira

    First we need to go to Jira administration – application to register a new application link. Detailed step is the same as the step 1 of the JIRA REST API Example – OAuth authentication.

    Using PKCS8 format private key in C#

    Jira currently is using RSA-SHA1 as the aAuth signing type. Class RSACryptoServiceProvider will be used for the sign, but it only supports xml format key. So we need to convert the PKCS8 format to supported XML format, for which opensslkey is used here.(opensslkey can be downloaded from here)

    Sample Code

    Below is the code, I put everything together. After the successful authentication, we should receive accessToken and accessTokenSecret; and send oAuth authenticated request with those information.

    Category: C#, Jira, OAuth