REST API Authentication On Atlassian using Azure B2C as OAuth Provider


Enhance API Security for Jira REST APIs with OAuth/API Token plugin will let you authenticate any application (Jira, Confluence, Bitbucket) APIs using any third-party OAuth/OIDC provider or API Tokens. The app supports Azure AD, Keycloak, Okta, AWS Cognito, Google, Github, Slack, Gitlab, Facebook, and any custom provider.

Atlassian provides REST APIs to perform several operations such as Create Page, Delete Page, Add Comment, Create Space, etc. However, it supports only two authentication methods for REST APIs:
  1. Basic Authentication
  2. Using OAuth 1.0
The Enhance API Security for Jira REST APIs with OAuth/API Token plugin allows you to use any third party OAuth 2.0 provider/ OpenID connect to authenticate REST APIs of any application (Jira, Confluence, Bitbucket). Here we will go through a guide to configure Azure AD as Provider.

You can refer the steps to configure REST API Authentication using API Token from the video or documentation given below

Download And Installation



  • Log into your Atlassian instance as an admin.
  • Navigate to the settings menu and click Manage Apps.
  • Click Find new apps or Find new add-ons from the left-hand side of the page.
  • Locate Enhance API Security for Jira REST APIs with OAuth/API Token app.
  • Click Try free to begin a new trial or Buy now to purchase a license.
  • Enter your information and click Generate license when redirected to MyAtlassian.
  • Click Apply license.

Step 1: Configure Azure B2C Server:

  • Sign in to Azure portal.
  • Go to Home and search Azure B2C in search bar and select Azure AD B2C.
Rest API OAuth, API token, API Key authentication for Jira and Confluence azure-AD-B2C  
  • Click on Applications and then on Add option to add a new application.
Rest API OAuth, API token, API Key authentication for Jira and Confluence add_application
  • Configure following options to create new application.
    • Enter a name for your application under the Name text field.
    • Select Yes from the options in front of Web APP and Yes from options in front of Allow Implicit Flow.
    • Copy Callback URL from the miniOrange OAuth Client plugin (Configure OAuth tab) and save it under the Reply URL textbox.
    • Click on the Create button to create your application.
Rest API OAuth, API token, API Key authentication for Jira and Confluence new application1
  • Click on the Applications option under the Manage Menu in the left navigation bar and you will find your application listed there. Click on your application.
Rest API OAuth, API token, API Key authentication for Jira and Confluence app_ID  
  • Copy your Application ID and save it. Then, click on the Keys option to generate a key. This will be your ClientID and Client Secret. Also Copy the Directory ID this will be your Tenant ID.
  Note: Copy the ClientID and Client Secret.

Step 2: Fetch Access token through POSTMAN:

  • Open the Postman Application (Here is the link to download Postman Application).
  • Go to Authorization tab.
  • From the dropdown select type as OAuth 2.0 and  click on Get access token.
  • Add the following information from the table below.
  • Postman starts the authentication flow and prompts you to use the access token.
  • Select Add token to the header.
Field Value
Grant type Authorization Code or Client Credentials
Callback URL Enter your application's base URL if you dont have a callback URL
Auth URL https://login.microsoftonline.com/<tenantID>/oauth2/authorize
Access token URL https://login.microsoftonline.com/<tenantID>/oauth2/token
Client ID Enter the Azure B2C Client ID
Client secret Enter the Azure B2C  Client secret
Scope OpenID
Client Authentication Send as Basic Auth Header
Rest API OAuth, API token, API Key authentication for Jira and Confluence Access token  
  • Copy the Access Token or click on Use Token.
A sample access token from Azure B2C Provider looks like this.
A834c0606ba71336423013699db8e971

Step 3: Fetch Username through Azure B2C:

  • Choose the method type as "GET".
  • Enter the interoception Endpoint from the plugin to fetch the username in the Request URL. For Azure B2C it is "https://login.windows.net/common/openid/userinfo".
  • Go to the Authorization tab select the Bearer Token and enter the access token here.
  • Add the header "content-type: application/json" and click on Send.
Rest API OAuth, API token, API Key authentication for Jira and Confluence Azure_user
Request:
     curl 
    -X GET 
    -H "Authorization: Bearer <Access Token>" 
    -H "Content-type: application/json" 
    https://login.windows.net/common/openid/userinfo
Copy the attribute value against the username, you will need to configure it in plugin. In this example, the value is "givenName".  

Step 4: Configure the Rest API plugin:

1: Enable Rest API Authentication:
  • After installing the app, click on Configure to configure plugin.
  • Select the Authentication type and navigate to Oauth/OIDC tab, then click on Configure.
  • From the drop down select Azure B2C as OAuth Provider.
  • Enter the attribute value against which we received the username in the Postman response.
  • Save the settings.
  • Now navigate to the Global Settings tab.
  • Here you will have to Enable the Authentication through Enable REST API Authentication and click on Save.
  • To configure the username attribute, click on Get username/email Attribute button.
  • Rest API OAuth, API token, API Key authentication for Jira and Confluence Azure AD

  • Paste the OAuth 2.0 Access token obtained from the OAuth provider and click on Get response.
  • In the received response, copy the JSON attribute against which you are receiving the username/email of the user in the local directory and paste it into the Username/Email Attribute input field, and click on Save.

Step 5: Test REST API using access token:

API keys and Tokens can be tested with the Test tokens feature. Select the type - Basic/Bearer, paste the token and click on Test token button.

Rest API OAuth, API token, API Key authentication for Jira and Confluence Confluence-Rest-API-AzureAD B2C

Click here to get a  FREE TRIAL  of Bitbucket REST API Plugin

  • Call Confluence REST API endpoint. Include the access token in the Authorization header. Here’s an example of fetching content from Confluence.
  • Go to the Postman application select method type as GET and enter the Request URL. For eg. http://{Confluence_Base_URL}/confluence/rest/api/content/
  • In the Authorization tab select type as Bearer Token.
Token  
  • In the Header tab add the header “content-type: application/json and send the request.
Result
Request:
     curl
                             -X GET
                             -H "Authorization: Bearer <Access Token>"
                             -H "Content-type: application/json"
                             http://{confluence_base_url}/confluence/rest/api/content/
                    
  • This will show the content in Confluence and will return the status 200.
  • If the token is invalid or missing, the call will return a 401 Unauthorized response

Click here to get a  FREE TRIAL  of Bitbucket REST API Plugin

  • Call Bitbucket REST API endpoint. Include the access token in the Authorization header. Here’s an example of fetching content from Bitbucket.
  • Go to the Postman application select method type as GET and enter the Request URL. For eg. http://{Bitbucket_Base_URL}/rest/api/1.0/dashboard/pull-requests
  • In the Authorization tab select type as Bearer Token.
Rest API OAuth, API token, API Key authentication for Jira and Confluence Confluence-Rest-API-AzureAD B2C  
  • In the Header tab add the header “content-type: application/json and send the request.
Rest API OAuth, API token, API Key authentication for Jira and Confluence Confluence-Rest-API-AzureAD B2C
Request:
     curl 
     -X GET  
     -H "Authorization: Bearer <Access Token>" 
     -H "Content-type: application/json" 
     http://{bitbucket_base_url}/rest/api/1.0/dashboard/pull-requests/
  • This will Retrieve a page of pull requests where the current authenticated user status 200.
  • If the token is invalid or missing, the call will return a 401 Unauthorized response