简体   繁体   English

通过 Spring 引导链接 Keycloak 帐户

[英]Linking Keycloak accounts through Spring Boot

I was wondering if there is a way to Link a Broker realm user to the provider through the keycloak library in spring boot.我想知道是否有办法通过 spring 引导中的 keycloak 库将代理 realm 用户链接到提供程序。

Situation: When we log in with a user through the realm provider, keycloak identifies their existence in the broker (or creates them) and then an email is sent to the accounts link.情况:当我们通过 realm 提供程序与用户登录时,keycloak 会识别它们在代理中的存在(或创建它们),然后将 email 发送到帐户链接。 But the way I use keycloak, I have a service responsible for creating these to customize them for the application.但是我使用 keycloak 的方式,我有一个服务负责创建这些来为应用程序定制它们。 In other words, when a user is created through this SpringBoot service, the idea is to check the existence of the realm provider and link the user created in the broker there.换句话说,当通过这个 SpringBoot 服务创建用户时,想法是检查 realm 提供程序的存在并链接在代理中创建的用户。

Question: Is it possible to link the broker's account with an existing one in the provider programmatically?问题:是否可以通过编程方式将经纪人的帐户与提供商中的现有帐户相关联?

Additional: it is possible to add the link directly through the admin console, so there must be a way to do it programmatically.附加:可以直接通过管理控制台添加链接,因此必须有一种方法可以以编程方式进行。

Image of manual creation of account link in admin console在管理控制台中手动创建帐户链接的图像

I tried using the setSocialLinks method or the setFederatedIdentities method but it doesn't seem to work.我尝试使用 setSocialLinks 方法或 setFederatedIdentities 方法,但它似乎不起作用。

FederatedIdentityRepresentation federatedIdentity = new FederatedIdentityRepresentation();

federatedIdentity.setIdentityProvider(super.getProviderRealmName());
federatedIdentity.setUserId(providerUserId);
federatedIdentity.setUserName(user.getUsername());

user.setFederatedIdentities(Collections.singletonList(federatedIdentity));
                
Response brokerResult = brokerUserResource.create(user);

Well, there's an option to do it automatically already on the Authentication flow configuration好吧,已经有一个选项可以在身份验证流配置中自动执行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM