对于 JWT,iat 和 exp 的值应该是多少?
What should the values of iat and exp be for JWTs?
我正在使用一个 API,声明在每个请求的授权 header 中使用 JWT,并表示 exp 和 iat 不是可选的。如何确定应该为 iat 和 exp 使用什么值?有关系吗?是什么阻止我将 iat 时间设置为过去很长时间并将 exp 时间设置为我想要的任何时间?
RFC7519 关于 iat
The "iat" (issued at) claim identifies the time at which the JWT was
issued. This claim can be used to determine the age of the JWT. Its
value MUST be a number containing a NumericDate value. Use of this
claim is OPTIONAL.
和exp
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.
我想我会回答这个问题,以防其他人遇到一些明确说明这一点的模糊文档。
就我而言,实际上我需要在为服务器提供 public 密钥后创建 JWT。在我的每个请求中,我都会创建 header、有效负载和签名,并将其作为授权发送。
简短的回答是,我可以将 iss 和 exp 设置为我想要的任何值:没有任何方法可以在该服务器端验证这一点。不通过使用可笑的 exp 值设置令牌永不过期的唯一原因是出于安全原因。
我正在使用一个 API,声明在每个请求的授权 header 中使用 JWT,并表示 exp 和 iat 不是可选的。如何确定应该为 iat 和 exp 使用什么值?有关系吗?是什么阻止我将 iat 时间设置为过去很长时间并将 exp 时间设置为我想要的任何时间?
RFC7519 关于 iat
The "iat" (issued at) claim identifies the time at which the JWT was issued. This claim can be used to determine the age of the JWT. Its value MUST be a number containing a NumericDate value. Use of this claim is OPTIONAL.
和exp
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.
我想我会回答这个问题,以防其他人遇到一些明确说明这一点的模糊文档。
就我而言,实际上我需要在为服务器提供 public 密钥后创建 JWT。在我的每个请求中,我都会创建 header、有效负载和签名,并将其作为授权发送。
简短的回答是,我可以将 iss 和 exp 设置为我想要的任何值:没有任何方法可以在该服务器端验证这一点。不通过使用可笑的 exp 值设置令牌永不过期的唯一原因是出于安全原因。