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.
- Enter the ClientID and select the client protocol as OpenID-connect and click on Save.
- 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.
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 | openid |
Client Authentication | Send as Basic Auth Header |
- Copy the Access Token or click on Use Token.
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.
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
Post a Comment