Google oauth的作用域在身份验证过程中发生了更改,但作用域是相同的



我创建了一个需要谷歌范围的应用程序,它一直工作到现在。我得到这个错误:

Error
ERROR:Scope has changed from "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://mail.google.com" to "https://mail.google.com/ https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile".

之前:

"https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/userinfo.profile 
https://mail.google.com"

之后:

"https://mail.google.com/ 
https://www.googleapis.com/auth/userinfo.email 
https://www.googleapis.com/auth/userinfo.profile"

据我所见,范围没有改变。前后有3个作用域,但只有顺序发生了变化。

这方面的python代码在这里:

try:
credentials = oauth.fetch_token('https://accounts.google.com/o/oauth2/token',
authorization_response = full_authorization_response_url,
client_secret=client_secret)
except Exception as e:
import traceback
print(traceback.format_exc())
credentials = 'ERROR:'+str(e)
if type(credentials) in (str,unicode):
return "Error<br>"+credentials

最后一句话似乎是相关的。所以谷歌说范围改变了,但我不知道为什么,也不知道如何修复,因为它没有改变。

我发现放宽服务器上的令牌作用域解决了这个问题。它显然期望相同的范围以相同的顺序,除非您添加以下行:

os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE'] = '1'

相关内容

最新更新