SpringBoot 应用程序读取 KeyCloak 令牌中 iat 的两小时时间偏移量

问题描述 投票:0回答:1

我有一个 SpringBoot 应用程序,使用 KeyCloak OAuth2/OIDC 进行身份验证。当使用在我的本地计算机上运行的 KeyCloak 实例时,这可以正常工作。现在我已经在本地网络中的服务器上使用相同的配置设置了 KeyCloak 并收到以下错误:

[invalid_id_token] An error occurred while attempting to decode the Jwt: The ID Token contains invalid claims: {iat=2024-04-23T13:26:41Z}

通话期间当地时间为 15:26,因此存在两个小时的偏差。我的时区是 CET (GMT+2),这似乎表明存在时区问题。但到目前为止我还无法确定它。

我检查了以下内容:

  • 服务器上的时间和时区正确(由

    timedatectl
    检查)

  • SpringBoot应用程序中的时间和时区是否正确(通过

    LocalDateTime.now()
    检查)

  • JWT 中的时间戳(如下所列)似乎是正确的(通过使用 Postman 调用 KeyCloak 的

    /protocol/openid-connect/token
    端点并使用 https://jwt.io/ 读取 access_token 进行检查)。

{
  "exp": 1713879118,
  "iat": 1713878818,
  "jti": "d89131ca-e904-40cc-806f-50496d2abdf0",
  "iss": "http://192.168.252.141:8080/realms/myRealm",
  "aud": "account",
  "sub": "6ba5043e-9faf-4cbc-914f-bb5623e04bfe",
  "typ": "Bearer",
  "azp": "myrealm-login",
  "session_state": "a8406003-b6d7-4bd2-8dec-e728c48600b1",
  "acr": "1",
  "allowed-origins": [
    "*",
    "http://localhost:8080/"
  ],
  ...
}

版本:

  • 钥匙斗篷24.0.3

  • SpringBoot 3.2.4

spring-boot spring-security jwt keycloak
1个回答
-1
投票

你的问题解决了吗?我使用 Google Oauth2 服务遇到了完全相同的问题。 我所在的时区是 UTC+2。我没有在我的应用程序中更改任何内容,突然我收到此无效令牌错误:

[invalid_id_token] An error occurred while attempting to decode the Jwt: The ID Token contains invalid claims: {iat=2024-08-22T08:18:2      
8Z}

版本:

  • 春季启动3.2.4
© www.soinside.com 2019 - 2024. All rights reserved.