I have a scenario wherein there are multiple apps/service that need to access my Resource:
These are the three external services: service1, service2, service3.
Now I am using the client_credentials grant type for this since this is machine to machine and no user is involved.
What I did is to create 1 client for each service in Keycloak. It works fine, however I need to add some more details in the token, in particular, a human readable name for each client as the client id is named using the recommended naming.
I know how to map user claims to the token, but is it possible to have something similar for my scenario wherein there are no users and I only have the clients?
Yes, go to the Realm of your app, then:
[Create]
;Hardcoded Claim
as Mapper Type
;Click [Save]
.
Update answer with more detail
I know how to map user claims to the token, but is it possible to have something similar for my scenario wherein there are no users and I only have the clients?
Yes, you need to create 'Hardcoded Claim Mapper.
For that:
realm
of your appclients
client
for your use-case(For the OLD Keycloak UI)
Mappers
Create
Mapper type
select Hardcoded claim
Save
(For the NEW Keycloak UI)
Client Scopes
<the client ID of your client>-dedicated
(e.g., test-dedicated in the picture below)Configure a new mapper
(or Add Mapper
> By configuration
if you have already created mappers before for this client)Hardcoded claim
Save
The client will be the client that you are using to authenticate against.