[英]Upgrading lcobucci/jwt from 3.x to 4.x: migrating ValidationData with $currentTime
I'm migrating lcobucci/jwt code written by another developer, and I can see several validation calls, which look like this:我正在迁移另一位开发人员编写的lcobucci/jwt代码,我可以看到几个验证调用,如下所示:
$validationData = new ValidationData($this->getNowTime() + self::TTL_TIME_LIMIT);
if (!$token->validate($validationData)) {
// ...
}
$validationData = new ValidationData($this->getNowTime());
if (!$token->validate($validationData)) {
// ...
}
From the upgrading steps I can see that validation is now done like this:从升级步骤我可以看到验证现在是这样完成的:
!$this->configuration->validator()->validate($token, ...$this->configuration->validationConstraints())
But I can not see how can I pass the $currentTime argument with new API.但是我看不到如何使用新的 API 传递 $currentTime 参数。 And as you can see, in the old code it's not always an actual current time as in the first call (as I understand it's done to see if token will be expired during the next hour).
正如你所看到的,在旧代码中,它并不总是像第一次调用那样的实际当前时间(据我所知,它已经完成以查看令牌是否会在下一小时内过期)。
Any solution for smooth migration in this case?在这种情况下有什么平滑迁移的解决方案吗?
After some research I was able to upgrade it to the new API:经过一番研究,我能够将其升级到新的 API:
$validAtConstraint = new LooseValidAt(
new FrozenClock($this->getNowTime()->modify(\sprintf('+%s seconds', self::TTL_TIME_LIMIT)))
);
if ($this->configuration->validator()->validate(
$token,
$validAtConstraint,
...$this->configuration->validationConstraints()
)
) {
// ...
}
Also, check out more detailed answer on the library github's discussion: https://github.com/lcobucci/jwt/discussions/813此外,请查看有关库 github 讨论的更详细答案: https://github.com/lcobucci/jwt/discussions/813
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.