Oidc 客户端 js ,不要在客户端中使用 Date.now



我在我的客户端中使用oidc-client-js用于我的一个SPA项目。 我有一个用 IdentityServer4 编写的身份服务器。

如果我手动更改服务器的日期时间,oidc-client-js 无法在登录用户中验证服务器的响应,因为日期时间不同。

而且,如果我手动更改客户端的日期时间并使用自动日期时间选项保留服务器,则来自服务器的响应再次无效。

我认为任何用于处理日期时间的 JavaScript 解决方案都不可靠,所有日期时间都必须在服务器中进行验证。

如何在服务器而不是客户端中验证令牌?

我的假设是正确的吗? 如果它不正确,oidc-client-js 是否有任何解决方案使用服务器时间而不是浏览器时间?

这是我的客户端配置

const userManagerConfig = {
client_id: '58bdb6b3dd264200a1186573a8abf884',
redirect_uri: `${window.location.protocol}//${window.location.hostname}${window.location.port ? `:${window.location.port}` : ''}/authentication/callback`,
response_type: 'code',
post_logout_redirect_uri: `${window.location.protocol}//${window.location.hostname}${window.location.port ? `:${window.location.port}` : ''}`,
scope: 'openid profile phone tes.api',
authority: `http://localhost:5016`,
silent_redirect_uri: `${window.location.protocol}//${window.location.hostname}${window.location.port ? `:${window.location.port}` : ''}/authentication/silent_callback`,
automaticSilentRenew: true,
filterProtocolClaims: true,
loadUserInfo: true,
triggerAuthFlow : true
};

时间必须正确。在服务器或客户端上,这无关紧要,但它必须是实际时间。如果你对时间有所缓和,代币上的声明(iat,nbf等(可能代表过去或未来的时刻,所以它不起作用。

为什么要将服务器或客户端的日期/时间更改为无效日期/时间?

如何在服务器而不是客户端中验证令牌?

在 SPA 上,与 oidc 相关的所有内容都发生在客户端代码中,包括令牌验证。

这不是客户端对令牌进行的唯一验证,也不是最重要的验证,主要的验证是检查使用颁发机构公开的公钥对进行签名。

我认为任何用于处理日期时间的 JavaScript 解决方案都不可靠,所有日期时间都必须在服务器中进行验证。

为什么更信任服务器上的时钟而不是客户端计算机上的时钟,桌面应用程序呢,离线呢......

最新更新