Repository navigation
KEYCLOAK-17851 change emailVerified User field with UserAttributeMappers (conditional trust email) - #8018
KEYCLOAK-17851 change emailVerified User field with UserAttributeMappers (conditional trust email)#8018cgeorgilakis wants to merge 3 commits into
Conversation
45c55c7 to
ed6cd2e
Compare
4bde962 to
9ad429d
Compare
|
I have rebased into current master taking into account changes in TokenEndpoint. |
2610776 to
ef73979
Compare
|
GitLab IdP implementation have been added. |
|
I think this can already be achieved with protocol mappers if I'm not mistaken. If it can't be done already, then I'd rather see an approach using mappers than adding a specific config option for it. |
Could you provide us how we could achieve conditional email verification with protocol mappers? I have added a Google Attribute Importer mapper with Social Profile JSON Field Path = email_verified and User Attribute Name= emailVerified. When I logged in with my google account Keycloak did not set emailVerified UserEntity field to true ( requested for email verification). Keycloak only have added an User Attribute emailVerified with value true to my account. From Keycloak code:
I do not have problem implementing it as a mapper. How do you want to do it? |
I'm not 100% sure how it should be implemented, but in general with a mapper we can allow different sync-modes, and also ability to either hard-code it, or map it to a claim from the incoming token. Those wouldn't be possible if it's a config option. There's (weirdly) two types of user attribute mappers, one for generic attributes, and a different one for fields. I thought we made some improvements here. @pedroigor @mposolda could you provide some thoughts on this? |
+1 to use the mapper. I think that if "emailVerified" is not available in BrokeredIdentityContext, it will be nice to add it there to make sure that propagating "emailVerified" attribute sent from the broker will allow to configure "emailVerified" of the user on Keycloak side. So I agree that this PR may require some changes in BrokeredIdentityContext class and maybe other similar classes to make it possible to implement this. Also it will be good to decide based on the "sync" mode whether the attribute should be updated during "update" call from broker or not. IMO it will be nice if behaviour for "emailVerified" is same as for all other attributes regarding sync mode. |
|
I have implemented conditional email verified with mapper in separate branch. Take a look at 70-verified-mapper. I could force push it here. Do you want any change in documentation? |
9fb4279 to
5bdef65
Compare
|
@mposolda @stianst @pedroigor I have force pushed emailVerified with UserAttributeMappers and I have rebased to current master. |
Honestly, I'm rather confused with the whole BrokeredIdentityContext thing. The email_verified claim is in the ID token, so isn't this as simple as adding a mapper that maps "email_verified" to User#emailVerified? @mposolda ? Something like: |
The problem is that User field emailVerified does not exist in BrokeredIdentityContext. preprocessFederatedIdentity and updateBrokeredUser methods of UserAttributeMappers set values to this object. See for example https://github.com/keycloak/keycloak/blob/main/services/src/main/java/org/keycloak/broker/oidc/mappers/UserAttributeMapper.java . The provided example in Keycloak main will add a user attribute emailVerified! You could test it in a running Keycloak with Google identity provider that releases email_verified claim. |
There was a problem hiding this comment.
@cgeorgilakis Thanks, added the comment inline (It was added as inline comment, but it is general comment related to this PR)
There was a problem hiding this comment.
I am not sure why there is a need for special handling of "emailVerified" attribute on this particular place? As I can see that none of other "special" attributes" (username, email, firstName, lastname) is handled here in this class.
IMO it will be better to make sure that all the places in the model classes like org.keycloak.models.jpa.UserAdapter and org.keycloak.models.map.user.MapUserAdapter are updated to make sure that:
user.setAttribute("emailVerified", "true") works as expected and calls setEmailVerified internally inside the UserAdapter itself. Similarly will be good if all other methods like user.setSingleAttribute, user.getAttribute, user.getFirstAttribute are updated to properly handle "emailVerified" attribute and delegate to the particular "setEmailVerified" or "getEmailVerified" property internally. I see you updated just single place in these classes, but not all places where other special attributes are handled.
In other words, will be good to handle emailVerified in the same places in the codebase when all other mess related to other "special attributes" (username, email, firstName, lastname) is handled. But will be good to avoid introduce more mess to other places :-)
I guess that if you properly update model classes, there won't be even need to update any brokering stuff at all (not even introduce BrokeredIdentityContext.setEmailVerified() and BrokeredIdentityContext.getEmailVerified() methods. As calling of user.setAttribute("emailVerified", "true") will be effectively same as user.setEmailVerified(true) and similarly for getters. But maybe I am too optimistic here :-)
There was a problem hiding this comment.
This if is needed here. See my general comment.
|
You are partially right. I have been confused by the method difference. Moreover,some checks for "special attributes" like in method updateBrokeredUser in class org.keycloak.broker.oidc.mappers.UserAttributeMapper is doing twice. If you want I could make a separate PR for this. Changes in methods ( setAttribute etc) of UserModel is enough only for updateBrokeredUser ( User update). When User is first time created ( method preprocessFederatedIdentity), values is written to BrokeredIdentityContext (use USER_ATTRIBUTES_PREFIX for UserAttributes, fields for email, names). If I does not introduce emailVerified field, changes are more complex. When User first time login with Social Providers, base values ( email, first name, last name) are taken in other point( see OIDCIdentityProvider). So, preprocessFederatedIdentity works only for User attributes. For email verified we need the commented if. I will do needed changes described in my comment trying to keep changes in the same places as "special attributes". After checking tests and real scenario for Google email verified, I will ping you. |
|
I have tested successfully my latest changes. For details see my previous comment. I also have closed related documentation PR( based on previous implementation). Do you want any addition in documentation for this PR? |
31cd597 to
92daf00
Compare
92daf00 to
435fdb5
Compare
|
I have rebased to current master. @pedroigor @mposolda could you proceed with this PR review in order to be able to conditionally verified email for Identity Providers Users. |
435fdb5 to
3801ff1
Compare
…field Closes#12013
6afa5a2 to
6919fdf
Compare
|
I have changed message based on new github issue and I have rebased. |
|
this is mega-useful for identity brokering situations, would love if this could be looked into. ❤️ |
|
@pedroigor @cgeorgilakis TBH I am still missing a bit why this PR needs to do any changes in the class For example, I see that:
In other words, I guess that when you update the models to have the |
|
AbstractJsonUserAttributeMapper is iherited by the classes FacebookUserAttributeMapper, GitHubUserAttributeMapper, GoogleUserAttributeMapper, InstagramUserAttributeMapper, LinkedInUserAttributeMapper, MicrosoftUserAttributeMapper, OpenshiftV4AttributeMapper, PayPalUserAttributeMapper and StackoverflowUserAttributeMapper. |
|
@mposolda I have made a change in Let's see if all test will be passed. |
|
@cgeorgilakis Sorry for the late feedback. I honestly still don't understand why there needs to be "if" condition added in |
@mposolda If User does not exist in Keycloak, method I can not understand why. |
|
Could you please tell me if the this PR is related to any issue? |
|
|
For SAML Identity Providers the logic is different. SAML Identity Providers release a list of email verified. Could you proceed with PR review? |
|
Hi, |
|
@cgeorgilakis I am closing as the PR is opened for long time without conclusion. I don't have much to add to my previous comment #8018 (comment) and to other comments. We should handle |
|
@mposolda you could see my comment in github issue. |
Documentation PR : keycloak/keycloak-documentation#1171