gpt4 book ai didi

oauth - 谷歌 oauth2.0 405 错误

转载 作者:行者123 更新时间:2023-12-04 15:22:31 41 4
gpt4 key购买 nike

我尝试使用以下链接使用 google oauth,但出现 405 错误,

你能告诉我参数是否正确吗?

client_id = changed to a diff value
response_type = code
scope= openid%20email
redirecturl = given the value based on what I registered in console.developers.com
login_hint = my gmail id..

https://accounts.google.com/o/oauth2/token?
client_id=690178314820-85fvo4eq56se4mppdaf0pt6tnnjo552&
response_type=code&
scope=openid%20email&
redirect_uri=http://test.webfactional.com&
state=security_token%3D138r5719ru3e1%26url%3Dhttps://oa2cb.example.com/myHome&
login_hint=myemail@gmail.com

我在浏览器中提出了上述获取请求..

最佳答案

有几个步骤可以让我更轻松地访问 Google,以便向您展示完整的流程。我的猜测是你被困在第二步,因为你没有将它作为帖子发送。

第一步:请求访问

https://accounts.google.com/o/oauth2/auth?client_id={clientid}.apps.googleusercontent.com&redirect_uri={From console}&scope=openid%20email&response_type=code

这只会显示要求他们批准您的窗口。一旦用户批准访问,您将获得一个一次性验证码。

第 2 步:交流 Authentication CodeAccessTokenRefreshToken .请注意,这需要作为 HTTP 发送发布 不是 HTTP Get。
https://accounts.google.com/o/oauth2/token
code={Authentication Code from step 1}&client_id={ClientId}.apps.googleusercontent.com&client_secret={ClientSecret}&redirect_uri=={From console}&grant_type=authorization_code

你应该得到一个 JSon 字符串,看起来像这样。
{
"access_token" : "ya29.1.AADtN_VSBMC2Ga2lhxsTKjVQ_ROco8VbD6h01aj4PcKHLm6qvHbNtn-_BIzXMw",
"token_type" : "Bearer",
"expires_in" : 3600,
"refresh_token" : "1/J-3zPA8XR1o_cXebV9sDKn_f5MTqaFhKFxH-3PUPiJ4"
}

现在你可以拿那个 Access_token并用它来提出您的要求。但是访问 token 的有效期只有 1 小时,然后它们会在那之前过期,您需要使用 Refresh_token获取新的访问 token 。此外,如果您想再次访问您的用户数据,您应该保存 refresh_token某个地方可以让您始终访问那里的数据。

第 3 步:使用刷新 token
https://accounts.google.com/o/oauth2/token
client_id={ClientId}.apps.googleusercontent.com&client_secret={ClientSecret}&refresh_token={RefreshToken from step 2}&grant_type=refresh_token

这次你只会取回访问 token ,因为你的刷新 token 是好的,直到用户删除身份验证或者你有 6 个月没有使用它。
{
"access_token" : "ya29.1.AADtN_XK16As2ZHlScqOxGtntIlevNcasMSPwGiE3pe5ANZfrmJTcsI3ZtAjv4sDrPDRnQ",
"token_type" : "Bearer",
"expires_in" : 3600
}

您可以在此处找到更多详细信息 Google 3 Legged oauth2 flow

关于oauth - 谷歌 oauth2.0 405 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24026431/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com