cod*_*yer 6 javascript authentication registration node.js keycloak
我正在使用 Keycloak 来保护我的 Javascript 应用程序。当单击按钮时,我希望打开一个注册页面,其中包含我现有的电子邮件。我的意思是,keycloak 注册页面将打开,其中电子邮件字段已预先填写。
我发现我们可以在登录页面中使用login_hint. 通过将其添加到链接末尾。例子:
http://localhost:8080/auth/realms/realm_name/protocol/openid-connect/auth?client_id=client_id&redirect_uri={url}&response_mode=fragment&response_type=code&scope=openid&nonce={...}&login_hint=exmaple@gmail.com
Run Code Online (Sandbox Code Playgroud)
但我不知道我是否可以对注册页面做同样的事情。有办法吗?
谢谢
我知道这个问题已经有 10 个月了,但我回答它是因为我将来无疑会再次遇到这个问题,并希望我能偶然发现这个答案。
为此,我在 KeyCloak 主题中添加了一段 Javascript 代码。
大致如下:
document.addEventListener("DOMContentLoaded", (event) => {
let email = getUrlParameter('email');
if (email) {
let field = document.getElementById('email');
field.value = email;
}
});
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};
Run Code Online (Sandbox Code Playgroud)
然后,我将用户发送到 keycloak 注册屏幕,并在 URL 参数中包含他们的电子邮件。
| 归档时间: |
|
| 查看次数: |
2829 次 |
| 最近记录: |