no

How to Get Keycloak Access Token Using Postman

1. Introduction In this article, I will share how we can generate a Keycloak access token using Postman. 1.1 Prerequisites You...

1. Introduction

In this article, I will share how we can generate a Keycloak access token using Postman.

1.1 Prerequisites

  • You must have a docker installed.
  • You must have installed Postman.

2. Setup Keycloak

Before we begin, we need to run an instance of Keycloak in docker first.
docker run -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin -p 8081:8080 -d jboss/keycloak:10.0.2
Keycloak should run on port 8081.

Now, go to your browser and open http://localhost:8081 and you should arrive in Keycloak admin page.

3. Create a Keycloak Realm and Client

Next, we need to create the realm and client that we will be using to generate a token.

During the first serving of the page, Keycloak will ask you to save an admin user and password.
  1. Login to Keycloak.
  2. In the left panel, hover to Master, and click Add Realm.
  3. Enter czetsuyatech.
  4. On the left panel, click Clients.
  5. On the right side, click Create.
  6. Enter auth in the client id and hit Save.
  7. In the client detail page:
    1. Set Access Type=confidential.
    2. Valid Redirect URIs=* (for debugging purposes only)
    3. Web Origins=* (for debugging purposes only)
    4. *Make sure to secure items 2 and 3 in production.
  8. Copy the Secret value in the Credentials tab, we will use it later.

4. Create a Keycloak User

  1. On the left panel, under Manage click Users.
  2. Click Add User.
  3. In the username field, enter czetsuyatech and hit save.
  4. Open the Credentials tab, set the password to czetsuyatech, switch Temporary to OFF.
  5. Click Set Password.

5. Create a Postman Request

Open Postman and create a post request with the following form of URL encoded values.
  • POST request URL: http://192.168.1.101:8081/auth/realms/czetsuyatech/protocol/openid-connect/token
  • Body Parameters
    • x-www-form-urlencoded
    • client_id=auth
    • username=czetsuyatech
    • password=czetsuyatech
    • grant_type=password
    • client_secret=[Get the value from step 3.8]

5.1 Expected Result

Related

keycloak 7931212825745703809

Post a Comment Default Comments

item