Repository navigation
Extract X.509 certificate fields as JWT claims #36799
|
I need to extract specific X.509 certificate fields (IssuerDN and Serial Number) from the user's certificate dynamically and put them as Claims in the generated Access Token. The values cannot be hardcoded as user attributes since a user can have multiple active certificates from different issuers at the same time (and they can change quite often). I've been looking into using a custom Protocol Mapper for this purpose, but going by the signature of the AbstractOIDCProtocolMapper#setClaim(AccessTokenResponse accessTokenResponse, ProtocolMapperModel mappingModel, UserSessionModel userSession, KeycloakSession keycloakSession, ClientSessionContext clientSessionCtx) method, the raw X.509 certificate is not available in the method argument. Am I overlooking something, or is this truly not possible? If so, are there any alternative solutions to extract JWT claims from a X.509 certificate? |
Replies: 1 comment 1 reply
|
@Bragolgirith you can use Keycloak's X509ClientCertificateLookup provider to access the client certificate. Here is a good example of the provider's use. In order to look up the client certificate in your mapper, you will need to grab |
@Bragolgirith you can use Keycloak's X509ClientCertificateLookup provider to access the client certificate. Here is a good example of the provider's use.
In order to look up the client certificate in your mapper, you will need to grab
HttpRequestfromsession.getContext().