当刷新令牌过期时,Keycloft角度重定向到登录页面



我使用的是anuglar密钥斗篷库,当访问令牌和刷新令牌都过期时会出现问题。当用户单击某个操作来调用BE API时,将调用令牌openid-connect/token的密钥斗篷服务器,并返回:

error: "invalid_grant"
error_description: "Token is not active"

这很好,但问题是之后什么都不会发生,我们希望用户在发生这种情况时被重定向到登录页面。有什么办法可以改变这种行为吗?

我找到了解决方案,有一个名为OnAuthRefreshError的密钥斗篷事件,我们可以监听它,然后将用户重定向到登录页面。示例:

this.keycloakService.keycloakEvents$
.pipe(takeUntil(this.cancelSubscription$))
.subscribe((event) => {
if (event.type === KeycloakEventType.OnAuthRefreshError) {
this.keycloakService.login({
prompt: 'login',
});
}
});

最新更新