php 令牌必须是短期令牌并且在合理的时间范围内
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36189612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Token must be a short-lived token and in a reasonable timeframe
提问by wataru
I am having the same error as this. In my case it is happening when the app is trying to upload a file via Google Cloud Client API.
我有相同的错误此。就我而言,当应用程序尝试通过 Google Cloud Client API 上传文件时,就会发生这种情况。
POST https://www.googleapis.com/oauth2/v4/token
400 Bad Request
Invalid JWT: Token must be a short-lived token and in a reasonable timeframe
How I load the token is reading a service-account json file, and attach it to CURLOPT_HTTPHEADER
in PHP. It did work properly for the past one month, so I am guessing that Google changed the way of authorization.
我加载令牌的方式是读取服务帐户 json 文件,并将其附加到CURLOPT_HTTPHEADER
PHP 中。过去一个月它确实正常工作,所以我猜测谷歌改变了授权方式。
Has anyone faced & solved this?
有没有人遇到并解决过这个问题?
回答by WNG
I stumbled upon the same issue at roughly the same time, so I expected a generic bug of Google but here is what had happened on my computer :
我几乎在同一时间偶然发现了同样的问题,所以我预计会出现 Google 的通用错误,但这是我计算机上发生的情况:
raise HttpAccessTokenRefreshError(error_msg, status=resp.status)
oauth2client.client.HttpAccessTokenRefreshError: invalid_grant: Invalid JWT: Token must be a short-lived token and in a reasonable timeframe
was caused in my case by a poor synchronisation of the computer's clock where the code was executed that had a lag of 5 minutes (due to a faulty battery for the internal clock). It started working again when I manually changed the internal time of my computer to the correct one.
在我的情况下,是由计算机时钟的同步不良引起的,其中执行的代码有 5 分钟的延迟(由于内部时钟的电池有故障)。当我手动将计算机的内部时间更改为正确的时间时,它又开始工作了。
This solution was mentionned here, but not with the full error message
回答by Eddy López
I had the same issue, I found that my server was delayed by 8 minutes. I configurated the NTP server and magically it was solved
我遇到了同样的问题,我发现我的服务器延迟了 8 分钟。我配置了NTP服务器,神奇地解决了
回答by Dave
For those getting that error for a containerized app and ending up here,
对于那些因容器化应用程序出现错误并在此处结束的人,
I had the same issue when using my token from a containerized app. Rebooting Docker Desktop (Windows) did it for me.
从容器化应用程序使用我的令牌时,我遇到了同样的问题。重新启动 Docker 桌面 (Windows) 为我做到了。
I had this setup for weeks before getting that issue for the first time.
在第一次遇到这个问题之前,我已经进行了数周的设置。
回答by Gurdeep Singh
Same problem encountered....manually reset my computer's clock to the current time....problem resolved.
遇到同样的问题....手动将我的计算机的时钟重置为当前时间....问题已解决。
回答by ajon
I was stumped on this for hours. I even posted this question. Turns out I had overlooked something that should have been somewhat obvious. My dev server is a Linux virtual machine. The clock on my VM was 8 days behind my local system clock. So while my local clock was correct, I overlooked the fact that my VM was several days delayed. Hopefully, this can save the absent-minded some time.
我被这个难住了好几个小时。我什至发布了这个问题。原来我忽略了一些本应该很明显的东西。我的开发服务器是 Linux 虚拟机。我的 VM 上的时钟比我的本地系统时钟晚 8 天。因此,虽然我的本地时钟是正确的,但我忽略了我的 VM 延迟了几天的事实。希望这可以为心不在焉的人节省一些时间。
回答by Don Ondeje
I had a similar problem when trying to reach the google cloud big query API. Adjusting my system clock and allowing windows 10 to automatically set the time and time zone solved the problem.
我在尝试访问谷歌云大查询 API 时遇到了类似的问题。调整我的系统时钟并允许 Windows 10 自动设置时间和时区解决了问题。
回答by Mark Tickner
It sounds obvious, but ensure the expiry exp
is after the issued at time iat
.
这听起来很明显,但请确保到期时间exp
是在 time 发布之后iat
。
回答by jagath
I had the similar problem and my job was keep failing with below error:
我遇到了类似的问题,我的工作一直失败并出现以下错误:
File "/usr/local/lib/python2.7/site-packages/google/oauth2/_client.py", line 59, in _handle_error_response
error_details, response_body)
google.auth.exceptions.RefreshError: ('invalid_grant: Invalid JWT: Token must be a short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp values and use a clock with skew to account for clock differences between systems.', u'{\n "error" : "invalid_grant",\n "error_description" : "Invalid JWT: Token must be a short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp values and use a clock with skew to account for clock differences between systems."\n}')
2018-05-1713:01:01: API CALL iOS intra day: module failed.
The actual root cause was the system time was out of sync with the server. I have refreshed the ntp server which synced the time and the problem was resolved.
真正的根本原因是系统时间与服务器不同步。我刷新了同步时间的 ntp 服务器,问题解决了。