Google Oauth2 身份验证返回"Required parameter is missing: grant_type"



我正在尝试从Google获取刷新令牌以访问Google驱动器。到目前为止,我已经设法在谷歌应用程序引擎中创建了一个页面,它将我重定向到身份验证页面,并且我能够获取代码。到达那里的网址是

Window.Location.assign("https://accounts.google.com/o/oauth2/auth?scope=profile&redirect_uri=http://127.0.0.1:8888/oauth2manager/redirect&response_type=code&client_id=1058171155388-hg2akr2idan7c2kvdam9b89vptcjai8i.apps.googleusercontent.com");

然后我被重定向到/oauth2manager/redirect servlet 并获取 doPost 方法中的代码

String code = request.getParameter("code");

我的问题是我无法继续,因为我经常收到上述错误"缺少必需参数:grant_type"我已经尝试了restclient wiztools,RestEasy firefox扩展甚至卷曲。这是我的卷曲脚本

 #!/bin/bash
$code= "4/E7i1aKu4C-Pf23-8hY4Y8OBe9IBZ.wtKglnd8-CMdOl05ti8ZT3aNPWw7igI";
curl -v --data "code="+$code+"&client_id=1058171155388-hg2akr2idan7c2kvdam9b89vptcjai8i@developer.gserviceaccount.com&client_secret=JHXTAT4UWwsNaMgm******&redirect_uri= http://127.0.0.1:8888/oauth2manager/redirect&grant_type=authorization_code" https://accounts.google.com/o/oauth2/token

如何解决这个问题?我完全是这方面的新手。

我认为你的混合Oauth类型。 您使用的代码适用于普通 Oauth2。 但您的客户 ID 适用于服务帐号。

普通的Oauth2会询问用户是否允许你访问他们的数据。 服务帐户用于允许其他人访问应用程序的数据,服务帐户没有权限请求。

链接到服务帐户的文档。服务帐户

最新更新