keycloak-angular :与身份验证相关的事件



我想监视与身份验证相关的事件,如下所示

开始、初始化、LOGGED_IN、LOGGED_OUT、TOKEN_REFRESHED、TOKEN_VALIDITY_CHECKED、TOKEN_EXPIRED NOT_AUTHENTICATED
我该怎么做?

我正在使用密钥斗篷的显式服务,当我开始使用"钥匙斗篷角度"时,我不知道如何监视事件

版本: "keycloak-angular": "^1.3.0" , Angular: "^5.2.9" 和 , keycloak 服务器 ;3.4.2.决赛

在旧服务中

声明

private eventStream: BehaviorSubject<string> = new BehaviorSubject('START');
private keycloakAuth: any;

初始化

this.keycloakAuth = new Keycloak({
    "realm": this.configService.config.security.keycloak.realm,
    "auth-server-url": this.configService.config.security.keycloak.authserver,
    "ssl-required": this.configService.config.security.keycloak.sslRequired,
    "clientId": this.configService.config.security.keycloak.clientId,
    "public-client": this.configService.config.security.keycloak.publicClient
});

this.keycloakAuth.init({ onLoad: 'check-sso' })
    .success(() => {
        // Pour initialiser les champs nom d'utilisateur
        this.getInfosUser().then();
        // notify ...
        this.eventStream.next('INITIALIZED');
        if (this.keycloakAuth.authenticated) {
            this.logger.info('[KeyCloak] Init end, Already logged in !');
            // notify ...
            this.eventStream.next('LOGGED_IN');
        }
        else {
            this.logger.info('[KeyCloak] Init ended, not logged in !');
            // notify ...
            this.eventStream.next('LOGGED_OUT');
        }
        resolve();
        // if some call are waiting for end of initialization,
        // notify them that it has ended with success !
        this.notifyEndOfInit(true);
    })
    .error(() => {
        reject();
        // if some call are waiting for end of initialization,
        // notify them that it has ended with failure !
        this.notifyEndOfInit(false);
    });

对于Keycloak OpenId Connect基于身份验证,您可以使用基于REST的界面登录,注销和检查用户会话,您可以在Angular中使用此库,该库在此答案中共享:https://stackoverflow.com/a/59122397/10294152

您需要在密钥斗篷配置中启用OpenId-Connect才能使用它。

相关内容

  • 没有找到相关文章

最新更新