REST API Authentication using Keycloak as OAuth Provider

REST API Authentication 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

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.
FieldValue
Grant typeAuthorization Code or Client Credentials
Callback URLEnter the Application's base URL if you dont have a callback URL
Auth URLhttp://{host_name}/auth/realms/{realm_name}/protocol/openid-connect/auth
Access token URLhttp://{host_name}/auth/realms/{realm_name}/protocol/openid-connect/token
Client IDEnter the Keycloak Client ID
Client secretEnter the Keycloak  Client secret
Scopeopenid
Client AuthenticationSend 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

Comments

Popular posts from this blog

Email Sending through O365 using OAuth Protocol

IoT Technology

What is reverse proxy?