3

I want to make a rest call to my Keycloak server.

According to doc it should be easy: https://www.keycloak.org/docs-api/10.0/rest-api/index.html#_executeactionsemail

So before I'll start codeing I want to prepare Postman call, so my url is

http://localhost:8080/auth/admin/realms/test/users/12345/execute-actions-email

in raw body I'm providing ['UPDATE_PASSWORD']

and what I get is 401 Unauthorized and I can't get what I'm doing wrong?

Body:

enter image description here

Headers are default:

enter image description here

Piotr Żak
  • 2,083
  • 6
  • 29
  • 42

2 Answers2

3

For accessing the Admin Rest API you need to pass on the admin token to REST CALLS:

You would have been prompted to create an admin account as soon as you would have opened {keycloak-url}/auth.

You can use this admin account to obtain the admin token as shown below.

Note that only change you have to do in below call is your keycloak server address and value of admin username and password.

enter image description here

You can pass the token obtain above on to the REST aPIs with Authroization header.

Please refer to my other SO post for a step by step guide to do this.

tryingToLearn
  • 10,691
  • 12
  • 80
  • 114
0

@tryingToLearn thank You so much!

I'll post what I did.

  1. Get token for master realm admin account:

enter image description here

  1. Call reset password service in test realm

enter image description here

I've had wrong body so correct body for this request is ["UPDATE_PASSWORD"] and You can notice 204 in the right bottom corner.

The second question is, is it possible to have special user in any realm, not master realm admin for getting a token?

Piotr Żak
  • 2,083
  • 6
  • 29
  • 42
  • 1
    Regarding second question, I think that's possible but not sure of the steps yet. – tryingToLearn Jun 10 '20 at 07:20
  • I've managed this more gently way, what I did is forward button to {realm}/account so user can make change password himself what means there is no security breakdown which in my opinion would be holding admin credentials and token – Piotr Żak Jun 10 '20 at 11:23
  • That is always the better way. To give user the option to change their password rather than the admin doing it. I assumed earlier that you are doing it through admin only in some special case. – tryingToLearn Jun 10 '20 at 11:36
  • @PiotrŻak For second question: yes, it is enough to create an user which has, as role mappings, "manage-users" for "realm-management" client. – Paolo De Dominicis Oct 06 '21 at 10:05