2
votes

I want to create a new user in keycloak using postman.

I get a token running

https://xxxxxx/auth/realms/MyRealm/protocol/openid-connect/token
header:
    Content-Type:application/x-www-form-urlencoded
body:
    grant_type:password
    client_id:admin-cli
    client_secret:asdf-asdf-asdf-asdf-asdf
    username:testuser1
    password:1234

If I then try to create a new user I get a 404 or 401 depending on the address.

404: https://xxxxxx/auth/realms/MyRealm/users
401: https://xxxxxx/auth/admin/realms/MyRealm/users

header:
    Authorization Bearer asdfasdfasdfasdfasdfasdf
    Content-Type application/json
no body: // The error is the same even with body

I suppose that when using auth/admin I also need a token for the auth/admin but I have no idea how to do it.

If I try to get a token for the same or admin user under auth/admin, in both cases I get a 401.

Using the admin user credentials to get a token under /auth/realms results in a 401 Invalid user credentials.

Any ideas?

Is testuser1 realm admin? You need admin to call keycloak api. Maybe you mistyped admin username and password, because if you use the same call with admin credentials it has to work.andrija