且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取Keycloak中已登录用户的角色

更新时间:2023-12-02 17:41:16

loadUserInfo不提供用户角色,您可以使用keycloak-js并通过tokenParsed

the loadUserInfo does not provide the roles of the user you may use the keycloak-js and get the roles by tokenParsed

var Keycloak = require('keycloak-js');
var kc = Keycloak('./keycloak.json');

kc.init().success(function(authenticated) {

   alert(JSON.stringify(kc.tokenParsed)); 

}).error(function() {
            alert('failed to initialize');
});

希望有帮助