我正在使用Jhipster 4.13.3和Oauth2 / OIDC选项来生成网关连接的keycloak。
当服务发送401状态时,不会执行重定向到/ login。
拦截器(auth-expired.interceptor.ts)被定义为处理错误,但它无法正常工作。
第一个问题
在if条件中,error.json()不包含path,因此条件为false并且永远不会执行重定向。
if (error.status === 401 && error.text() !== ''
&& error.json().path && !error.json().path.includes('/api/account')) {
const destination = this.stateStorageService.getDestinationState();
if (destination !== null) {
const to = destination.destination;
const toParams = destination.params;
if (to.name === 'accessdenied') {
this.stateStorageService.storePreviousState(to.name, toParams);
}
} else {
this.stateStorageService.storeUrl('/');
}
const loginService: LoginService = this.injector.get(LoginService);
loginService.login();
}
有人知道正确的情况吗?
第二个问题
我禁用了对“error.json()。path ...”的检查,重定向被调用但是“经常”失败,它有时会起作用,我没有找到解释。即使我杀死了keycloak管理控制台中的所有会话,浏览器也会重定向到主页,而不是keycloak登录表单。
有人对此有解释吗?
谢谢,菲利普
当在承载者/用户的访问令牌的iss字段上标记的主机名具有不同的情况,即用于向密钥泄露的令牌端点发布HTTP请求的URL中的主机名小写与大写时,我们继续获得HTTP 401状态代码响应。
任何类型的主机名不匹配都可能导致401错误:
这发生在Microsoft Windows 10版本1809环境中。