REST API Authentication On Atlassian using Salesforce as OAuth Provider

Atlassian provides REST APIs to perform a number of 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 REST API Authentication plugin allows you to use any third party OAuth 2.0 provider/ OpenID connect to authenticate REST APIs. Here we will go through a guide to configure Salesforce as Provider.

Download And Installation

  • Log into your atlassian instance as 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 Api Token/OAuth Authentication 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 Salesforce server:

  • Login to your Salesforce account.
  • From the left pane, select Build and click on Create > Apps.
  • Scroll down and click on New under Connected apps.
  • You will be taken to the application settings page. Configure the application like so.
  • Check the Enable OAuth Settings and you will be shown more options to configure, Such as, Callback URL (Enter the Application’s Base URL.) and Scopes. Select the scopes as required and save settings.
 
  • You will be taken to the Application Management page. Here, you will find Consumer ID and Consumer Secret.
  Note: Copy the Consumer ID and Consumer Secret it will be your 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 the Application's base URL if you dont have a callback URL
Auth URL https://login.salesforce.com/services/oauth2/authorize
Access token URL https://login.salesforce.com/services/oauth2/token
Client ID Enter the Salesforce Client ID.
Client secret Enter the Salesforce  Client secret
Scope api
Client Authentication Send client credentials in body
Salesforce as OAuth Provider
  • Copy the Access Token or click on Use Token.
A sample access token from Salesforce Provider looks like this.
A834c0606ba71336423013699db8e971

Step 3: Fetch Username through Salesforce:

  • Choose the method type as "GET".
  • Enter the interoception Endpoint from the plugin to fetch the username in the Request URL. For Salesforce it is "https://login.salesforce.com/services/oauth2/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.
  Request:
     curl 
     -X GET 
     -H "Authorization: Bearer <Access Token>" 
     -H "Content-type: application/json" 
     https://login.salesforce.com/services/oauth2/userinfo
Copy the attribute value against the username, you will need to configure it in plugin. In this example, the value is "preferred_username".

Configure the Rest API plugin:

Step 1: Enable Rest API Authentication:

  • After installing the app, navigate to the Global Settings tab.
  • Here you will have to Enable the Authentication through Enable REST API Authentication and click on Save.
  • Go to the OAuth/OIDC tab and in the dropdown provided select Salesforce as the OAuth provider.
  • Enter the attribute value against which we received the username in the Postman response.
  • Save the settings.

Step 2: Disable Basic Authentication:

  • Disabling this will restrict all the REST API call made using Basic Authentication.

Test REST API using access token:

  • Call any REST API. 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.
Confluence-Rest-API-Keycloak  
  • In the Header tab add the header “content-type: application/json and send the request.
Confluence-Rest-API-Keycloak 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



If you are looking for anything which you cannot find, please drop us an email on info@xecurify.com