我们提供安全,免费的手游软件下载!
keycloak对第三方登录(社区登录)进行了封装,主要经历以下三个过程:
private Response finishBrokerAuthentication(BrokeredIdentityContext context, UserModel federatedUser,
AuthenticationSessionModel authSession, String providerId) {
authSession.setAuthNote(AuthenticationProcessor.BROKER_SESSION_ID, context.getBrokerSessionId());
authSession.setAuthNote(AuthenticationProcessor.BROKER_USER_ID, context.getBrokerUserId());
this.event.user(federatedUser);
context.getIdp().authenticationFinished(authSession, context);
authSession.setUserSessionNote("loginType", providerId);
...
}
code = OAuth2CodeParser.persistCode(session, clientSession, codeData);
redirectUri.addParam(OAuth2Constants.CODE, code);
// TODO: 登录成功后,将用户登录方式追加到回调页面上
if (authSession.getUserSessionNotes().containsKey("loginType")) {
String loginType = authSession.getUserSessionNotes().get("loginType");
redirectUri.addParam("loginType", loginType);
}
{
"time": 1723099954167,
"type": "FEDERATED_IDENTITY_LINK",
"realmId": "fabao",
"clientId": "pkulaw",
"userId": "e62a4ea6-c1c3-4f10-9136-8ceebba45339",
"sessionId": null,
"ipAddress": "111.198.143.194",
"error": null,
"details": {
"identity_provider": "carsi",
"identity_provider_identity": "student@pku.edu.cn",
"code_id": "6668189e-4cd6-488e-8582-d28b87636b41",
"username": "phone202408081431274571"
}
}
// 社区绑定现在有用户后,发的事件FEDERATED_IDENTITY_LINK,我们需要添加一些扩展信息
event.detail(Details.IDENTITY_PROVIDER, providerId);
event.detail(Details.IDENTITY_PROVIDER_USERNAME, context.getBrokerUserId()); //event.detail(Details.IDENTITY_PROVIDER_USERNAME, context.getUsername());
event.detail("identity_provider_username", context.getUsername());
{
"time": 1723101725866,
"type": "FEDERATED_IDENTITY_LINK",
"realmId": "fabao",
"clientId": "pkulaw",
"userId": "347c9e9e-076c-45e3-be74-c482fffcc6e5",
"sessionId": null,
"ipAddress": "10.10.80.81",
"error": null,
"details": {
"identity_provider": "carsi",
"identity_provider_username": "student@pku.edu.cn",
"identity_provider_identity": "6zETJRPrWiBi7B85cCHPoVD7dyI\u003d",
"code_id": "c344f279-9786-468b-a67e-fecf39c531b0",
"username": "test"
}
}
热门资讯