使用 oAuth 和 youtube 进行身份验证时,在第二次身份验证尝试时总是出现错误:invalid_grant,为什么? [英] When authenticating with oAuth and youtube, always get error : invalid_grant on 2nd auth attempt, why?

查看:37
本文介绍了使用 oAuth 和 youtube 进行身份验证时,在第二次身份验证尝试时总是出现错误:invalid_grant,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

截至昨天,当我将 requestToken 交换为 accessToken 时,我的应用程序第一次可以通过 oAuth 2.0 向 google (youtube) 进行身份验证,但第二次没有问题(重新身份验证,相同的应用程序 + 相同的用户)我收到一个错误:

As of yesterday, my application is able to authenticate with google (youtube) via oAuth 2.0 the first time no problem but the 2nd time (re-authentication, same app + same user), when I exchange the requestToken for an accessToken I get an error:

error : invalid_grant

我正在使用:

grant_type = authorization_code

就像他们建议的那样.过去 2 天前发生的情况是,在重新进行身份验证时,网页会说您之前已经通过此应用程序进行了身份验证,是否要再次授予它访问权限?".发生了什么变化或者我可能做错了什么?

like they suggest. What used to happen, before 2 days ago, was on re-authentication the web page would say 'you've already authenticated with this application before, would you like to grant it access again?'. What has changed or what could I be doing wrong?

推荐答案

我找到了解决这个问题的方法(至少对我们来说是这样).当重定向到accounts.google.com/o/oauth2/auth url 时,我们必须同时添加approval_prompt=force 和access_type=offline.如果缺少一个,我们就没有刷新令牌.

I found a way to fix this (at least for us). When redirecting to the accounts.google.com/o/oauth2/auth url, we had to add both approval_prompt=force and access_type=offline. If one was missing, we got no refresh token.

这个 url 记录了所有参数,但没有说明刷新令牌:http://code.google.com/apis/accounts/docs/OAuth2WebServer.html

This url documents all of the parameters, but says nothing about the refresh token: http://code.google.com/apis/accounts/docs/OAuth2WebServer.html

这篇关于使用 oAuth 和 youtube 进行身份验证时,在第二次身份验证尝试时总是出现错误:invalid_grant,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆