How to write an OIDCProtocolMapper using Spring dependency injection?

I’d like to use Spring dependency injection in a ProtocolMapper.

Ideally, I’d like to use spring-boot to make this mapper an OAuth2 client.

My intentions details:

  • authorization-server : keycloak
  • client: the mapper
  • resource-server: a web-service exposing some user authorization data

The mapper authenticates using client credentials flow, gets a token with “AUTHORIZATION_SERVER_EXTENSION” role for himself and then, for each token issued for users, the mapper retrieves user grants from a web-service (which requires “AUTHORIZATION_SERVER_EXTENSION” role to return user grants)

Currently the mapper works without security and I’d like to use spring-security to handle OAuth2 flow but I couldn’t get Spring application-context to load correctly at mapper initialization.