REST API Authentication On Atlassian using Keycloak as OAuth Provider

REST API Authentication plugin, will let you authenticate the 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 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 of any application (Jira, Confluence, Bitbucket). Here we will go through a guide to configure Azure AD 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 Keycloak server:

  • In your Keycloak admin console, select the realm that you want to use.
  • Go to Clients in the left navigation bar and click on Create.
Rest API OAuth, API token, API Key authentication for Jira and Confluence Keycloak Registration
  • Enter the ClientID and select the client protocol as OpenID-connect and click on Save.
Rest API OAuth, API token, API Key authentication for Jira and Confluence Keycloak
  • Select access type as Confidential,  enter the redirect URL and click on save (Enter the Application's Base URL).
  • To get Client Secret Navigate to Clients, select Client Id and navigate to the Credentials tab.
Rest API OAuth, API token, API Key authentication for Jira and Confluence Keycloak
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 the Application's base URL if you dont have a callback URL
Auth URL http://{host_name}/auth/realms/{realm_name}/protocol/openid-connect/auth
Access token URL http://{host_name}/auth/realms/{realm_name}/protocol/openid-connect/token
Client ID Enter the Keycloak Client ID
Client secret Enter the Keycloak  Client secret
Scope Blank
Client Authentication Send as Basic Auth Header
Note: For Host_name and Realm_name enter the Keycloak hostname and realmname.   Rest API OAuth, API token, API Key authentication for Jira and Confluence Keycloak-AccessToken
  • Copy the Access Token or click on Use Token.
A sample access token from Keycloak Provider looks like this.
A834c0606ba71336423013699db8e971

Step 3: Fetch Username through Keycloak:

  • Choose the method type as "GET".
  • Enter the interoception Endpoint from the plugin to fetch the username in the Request URL. For Keycloak it is "http://{host_name}/auth/realms/{realm_name}/protocol/openid-connect/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 ConfluenceKeycloak-Username
Request:
     curl 
     -X GET 
     -H "Authorization: Bearer <Access Token>" 
     -H "Content-type: application/json" 
     http://{hostname}/auth/realms/{realm_name}/protocol/openid-connect/userinfo
Copy the attribute value against the username, you will need to configure it in plugin. In this example, the value is "preferred_username".

Step 4:Configure the Rest API plugin:

Step 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 Keycloak as OAuth Provider.
  • Enter the Host Name and the Realm name from Keyclok.
  • 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.

 Rest API OAuth, API token, API Key authentication for Jira and Confluence

Step 2: Disable Basic Authentication:
  • Disabling this will restrict all the REST API call made using Basic Authentication.

Step 5: User Restriction:

Step 1: Group Based Restriction:
  • Navigate to User Restriction Tab and then Group Based Restriction.
  • Check the Restrict Access to API.
  • Enter the Group to allow user to access Rest API.
  • Save the settings.
Step 2: IP Restriction:
  • Navigate to User Restriction Tab and then IP Restriction.
  • Check the Restrict Access to API by IP address.
  • Add IP Address or range to allow Rest API.
  • Save the settings.
Rest API OAuth, API token, API Key authentication for Jira and Confluence-UserRestrictionTab

Step 6: 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 Jira.
  • Go to the Postman application select method type as GET and enter the Request URL. For eg. http://{Jira_Base_URL}/rest/api/2/project
  • 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://{jira_base_url}/rest/api/2/project
  • This will return all projects which are visible for the current userstatus 200.
  • If the token is invalid or missing, the call will return a 401 Unauthorized response
  • 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.
 Rest API OAuth, API token, API Key authentication for Jira and Confluence Keycloak  
  • 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
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.
  • Call any REST API. 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


Our Other Apps: SAML SSO Apps | OAuth Apps | 2FA Apps | Crowd Apps | REST API Apps | Kerberos/NTLM Apps | User Sync Apps |
                             Bitbucket Git Authentication App | Jenkins SSO | SonarQube SSO

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

Hello there!

Need Help? We are right here!

support
Contact miniOrange Support
success

Thanks for your inquiry.

If you dont hear from us within 24 hours, please feel free to send a follow up email to info@xecurify.com