'Keycloak returns Unauthorized 401

I'm running bitnami's Keycloak image on my local. what I want to do is; use Keycloak REST APIs. but no matter how hard I try, I'm getting 401.

I have done what's written in the doc. so this is a screenshot of the client. access type is confidential, and a service account is enabled. this is testapi client that I created;

here you can see the service account roles; to view and manage users, I assigned manage-users and view-user roles.

firstly, to get the access_token , I'm using client_id and client_credential. as you can see from here; enter image description here I have no problem getting the access token.

but when I try to get the user list or create a new user, I always get 401. here you can see that I used the SAME access_token that I got from the http://localhost:8092/auth/realms/test/protocol/openid-connect/token

enter image description here

it doesn't make sense. I started to think about smashing the computer.

any help would be greatly appreciated



Solution 1:[1]

it doesnt work like this ,the process of getting users is as below:

First try to get access token for admin

POST http://localhost:8080/realms/master/protocol/openid-connect/token the body of ur request will be x-wwww-url-encoded

client_id = admin-cli
username=admin
password=admin's password
grant_type=password

the response contains access token for admin Second step is to get users of your realm in your case is test

Get http://localhost:8080/admin/realms/test/users

and pass the bearer token of admin in this request

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ardouser