我正在关注本教程
https://developers.google.com/accounts/docs/OAuth2ServiceAccount
授权我的申请。我已经按照教程创建了一个JWT。

但是,当我提出访问令牌请求时,我会不断获得
“无效的grant_type:urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer”异常。

这是我发出请求的代码

HttpClient httpClient = new HttpClient();
        PostMethod post = new PostMethod("https://accounts.google.com/o/oauth2/token");
        post.addRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        post.addParameter("grant_type", URLEncoder.encode("urn:ietf:params:oauth:grant-type:jwt-bearer", "UTF-8"));
        post.addParameter("assertion", "JWT including signature.");
        httpClient.executeMethod(post);


我查看了很多资源,但显而易见的错误似乎是将客户端ID误认为电子邮件ID。但是,我已经检查并重新检查过该内容,以确保我使用的是正确的。

请任何人告诉我我在做什么错。

非常感谢

最佳答案

我通过参考这篇文章解决了这个问题:
Invalid grant error is being thrown while retrieving accessToken for Google Service account request

事实证明NTP(网络时间协议)存在问题。到期时间和发行时间必须更改。完成之后,它开始正常工作。

关于java - 400错误“error_description”:“无效的grant_type:urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer” Google服务帐户,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24016564/

10-12 01:26