4

keycloak~避免出现"用户已登录"的界面

 2 years ago
source link: https://www.cnblogs.com/lori/p/15401196.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

keycloak出现"用户已登录"的界面的场景我们需要先搞清楚,主要是这样的操作:

  1. 用户打开一个浏览器,在上面同时打开多个登录窗口
  2. 用户先在一个窗口上进行登录
  3. 用户再第二个窗口上再进行登录
  4. 这时,出现用户已经登录,事实上,在kc上,如果你已经登录了,则不能再使用其它用户登录了
  1. 同一个浏览器在同一个kc realm下,它的sessionid是相同的,所以被认为一个用户,不支持多个用户的sessionid

多用户登录改进

如果希望kc支持在一个用户登录后,再刷新第二个界面的登录页,再使用第二个用户才能登录。

单用户不出现用户已登录

  1. 前端ftl模板添加session状态检查
  2. 如果cookie中存的sessionid已经登录,而进行redirect_uri
  3. 如果没有登录,再走正常的登录逻辑
  • 前端登录代码
  function confirmSession(callback) {
        $.get("/auth/realms/your-realms/session-exist", function (o) {
            console.log(o);
            if (o.exist) {
                location.href = getQueryVariable("redirect_uri");
            } else {
                callback();
            }
        });
    }

   function login_f() {
        confirmSession(function () {
            document.getElementById("kc-form-login").submit();
        })
    }

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK