2

我在我的客户端中使用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
};
4

1 回答 1

0

时间必须正确。在服务器或客户端上,没关系,但它必须是实际时间。如果您对时间进行调整,令牌上的声明(iat、nbf 等)可能代表过去或未来的某个时刻,因此它不会起作用。

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

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

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

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

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

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

于 2020-01-15T10:19:08.013 回答