Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过setUserAttribute方法将微信用户的头图映射到Keycloak用户的相应属性字段未生效 #9

Open
wdy321 opened this issue Dec 12, 2022 · 0 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@wdy321
Copy link

wdy321 commented Dec 12, 2022

描述

在WeiXinIdentityProvider类中的extractIdentityFromProfile方法中,尝试将微信用户的头图属性映射到Keycloak用户的属性,代码如下

@Override
    protected BrokeredIdentityContext extractIdentityFromProfile(EventBuilder event, JsonNode profile) {
        String uuionid = getJsonProperty(profile, "unionid");
        BrokeredIdentityContext user = new BrokeredIdentityContext(
                (uuionid != null && uuionid.length() > 0 ? uuionid : getJsonProperty(profile, "openid")));

        String nickname = getJsonProperty(profile, "nickname");
        user.setUsername(getJsonProperty(profile, "openid"));
        user.setBrokerUserId(getJsonProperty(profile, "openid"));
        user.setModelUsername(nickname);
        user.setFirstName(nickname);
        user.setLastName(nickname);
        user.setEmail(nickname + "@qq.com");
        user.setUserAttribute("avatar_url", getJsonProperty(profile, "headimgurl"));
        user.setName(getJsonProperty(profile, "nickname"));
        user.setIdpConfig(getConfig());
        user.setIdp(this);
        AbstractJsonUserAttributeMapper.storeUserProfileForMapper(user, profile, getConfig().getAlias());
        return user;
    }

打包插件代码,重启Keylcoak容器,在浏览器使用微信扫码登录后,NickName、FirstName、LastName以及Email均按代码规则设置,但头图属性并未添加到Keycloak的用户的Attribute中,如下
image
image

@Jeff-Tian Jeff-Tian self-assigned this Aug 3, 2023
@Jeff-Tian Jeff-Tian added the help wanted Extra attention is needed label Aug 3, 2023
@Jeff-Tian Jeff-Tian pinned this issue Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants