我的 ID 提供者 returns 一个值 Keycloak 不理解。我能做什么?

My id provider returns a value Keycloak doesn't understand. What can I do?

我将 Keycloak 与用作 ID 提供程序的外部 OAuth 服务器一起使用。

当我尝试登录时,Keycloak 发送身份验证反向通道请求,其中 OAuth 服务器使用 JWT 回复。

解码 JWT 时,Keycloak 失败并出现此异常

Caused by: com.fasterxml.jackson.core.JsonParseException: Numeric value (1539167070926) out of range of int
 at [Source: (byte[])"{"sub":"20008203","aud":"Test-Keycloak","amr":["pwd","mobile"],"iss":"oauth","exp":1539167070926,"iat":1539163470926,"jti":"d24e5a11-1931-45a7-b77a-0c935ea40df8"}"; line: 1, column: 97]
    at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1804)
    at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:663)
    at com.fasterxml.jackson.core.base.ParserBase.convertNumberToInt(ParserBase.java:869)
    at com.fasterxml.jackson.core.base.ParserBase._parseIntValue(ParserBase.java:801)
    at com.fasterxml.jackson.core.base.ParserBase.getIntValue(ParserBase.java:645)
    at com.fasterxml.jackson.databind.deser.std.NumberDeserializers$IntegerDeserializer.deserialize(NumberDeserializers.java:472)
    at com.fasterxml.jackson.databind.deser.std.NumberDeserializers$IntegerDeserializer.deserialize(NumberDeserializers.java:452)
    at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:136)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
    ... 80 more

似乎 exp 值太大了。 keycloak 是否无法解码?我的 OAuth 服务器发送了错误的值吗?我该怎么做才能正确解码该过期时间?

据我了解,我尝试使用的 ID 提供程序似乎不符合 JWT 规范。的确,JWT spec states下面

The "exp" (expiration time) claim identifies the expiration time on or after which the JWT MUST NOT be accepted for processing. The processing of the "exp" claim requires that the current date/time MUST be before the expiration date/time listed in the "exp" claim. Implementers MAY provide for some small leeway, usually no more than a few minutes, to account for clock skew. Its value MUST be a number containing an IntDate value. Use of this claim is OPTIONAL.

换句话说,当设置exp时,它必须是一个包含从EPOCH开始的秒数的int值。

事实是,自 JWT 草案发布(2014 年 2 月)以来,关于“exp”时间戳的规范发生了变化。最终规范于 2015 年 5 月发布,(https://www.rfc-editor.org/rfc/rfc7519#section-4.1.4) 只需要一个数字日期。

因此,RFC 没有规定数字表示的宽度,我假设这意味着(从作为 keycloak 的应用程序的一侧)我们应该使用 wide-enough 整数(64 位)这样我们就不会溢出。

由于 Y2038 问题(带符号的 32 位整数不能表示(大约)2038 年 1 月 19 日之后的日期),这种情况在不久的将来会变得更加烦人