angular - oidcSecurityService - 使用隐式流和静默更新的用户定时注销
问题描述
我有一个 Angular 应用程序 - 我正在使用 OidcSecurityService v11 并且有一个使用 silentRenew=true 的隐式流实现,如下所示
oidcConfigService.withConfig({
stsServer: "https://localhost:44371",
redirectUrl: `${window.location.origin}/callback`,
clientId: 'spaCodeClient',
scope: 'openid profile MyWebProject',
responseType: 'code',
triggerAuthorizationResultEvent: true,
postLogoutRedirectUri: `${window.location.origin}`,
startCheckSession: false,
silentRenew: true,
silentRenewUrl: `${window.location.origin}/silent-renew.html`,
postLoginRoute: '/disclaimer',
forbiddenRoute: '/unauthorized',
unauthorizedRoute: '/unauthorized',
logLevel: LogLevel.Debug,
historyCleanupOff: true,
// iss_validation_off: false
// disable_iat_offset_validation: true
maxIdTokenIatOffsetAllowedInSeconds: 10,
disableIatOffsetValidation: true
});
My Identity Server 4 服务器端客户端超时设置(开发用)如下
"IdentityTokenLifetime": 30, // one time only token --> Lifetime to identity token in seconds (defaults to 300 seconds / 5 minutes)
"AccessTokenLifetime": 120, // passed around the application --> Lifetime of access token in seconds (defaults to 3600 seconds / 1 hour)
"AuthorizationCodeLifetime": 30 // Lifetime of authorization code in seconds (defaults to 300 seconds / 5 minutes)
"AbsoluteRefreshTokenLifetime": 180, // Maximum lifetime of a refresh token in seconds. Defaults to 2592000 seconds / 30 days
"SlidingRefreshTokenLifetime": 150, // Sliding lifetime of a refresh token in seconds. Defaults to 1296000 seconds / 15 days
我想检查令牌、会话等是否过期以注销用户(最好提前警告)。到目前为止,刷新令牌看起来只是在过期后刷新(通过静默更新处理)(最终我得到了 http.get 调用的 401,但远远超过了上面的超时)
我已经看到了一些解决方案(它们利用了令牌、id_token、超时),但是当我使用带有静默更新的隐式流时,据我所知,这些令牌/超时并不相关。推荐的解决方案是将 startCheckSession 设置为 true,然后订阅相应的事件,然后将用户发送到未经授权的屏幕,如https://github.com/damienbod/angular-auth-oidc-client/issues/568(用户: rekosko:24-Jan-2020 - 请注意这是对 v10 问题的回答)?
我已将以下内容添加到我的 AuthService
checkSessionExpired(): Observable<boolean> {
console.log("checkSessionExpired");
return this.oidcSecurityService.checkSessionChanged$.pipe(
map((isSessionChanged: boolean) => {
console.log("checkSessionExpired-checkSessionChanged$:" + isSessionChanged);
if (isSessionChanged) {
return true;
}
return false;
})
);
}
...但是我不确定如何/在哪里调用它(拦截器,也许是一个计时器 - 从哪里开始?)或者这是否是正确的方法
有谁知道在上述情况下这是否是首选解决方案(对于 v11) - 如果是这样,您是否能够提供比上述链接的解决方案更多的细节(这在 v11 中的样子,它是从哪里调用的, ETC)
解决方案
推荐阅读
- sql - 根据给定条件 PostgreSQL 选择随机行
- angular - 在不相关的函数之间检测到循环依赖
- bash - 如何编写一个unix shell脚本
- java - 自 2.2.0 spring-boot-maven-plugin 创建 2 个 java 进程(可能导致 CreateProcess 错误=206)。需要解决方法来修复它
- python - 在 ORTools 中为每辆卡车设置不同的约束
- angular - NativeScript:如何从主页显示侧抽屉?
- python - 如何绘制(散点图)具有多列的数据框
- sql - 从 SQL 中单列中的过滤值创建多列
- python - 通读python中的连接文件
- snowflake-cloud-data-platform - 如何使用来自 Oracle 的数据更新雪花中的表?