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

时间:2020-01-13 13:34:43

标签: identityserver4 oidc-client-js oidc-client

我正在将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
};

1 个答案:

答案 0 :(得分:0)

时间必须正确。在服务器或客户端上,这没有关系,但必须是实际时间。如果您随时间变化,令牌的声明(iat,nbf等)可能代表过去或将来的一刻,因此它将失效。

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

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

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

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

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

为什么信任服务器上的时钟而不是客户机上的时钟,台式机应用程序如何,离线应用程序如何?