python - 使用 OAuth2WebServerFlow 的多个范围

标签 python google-app-engine

我想使用 OAuth2WebServerFlow() 授权多个范围。这是我当前的代码:

flow = OAuth2WebServerFlow(
    client_id=id,
    client_secret=secret,
    scope= ['scope1','scope2','scope3'],
    approval_prompt='force',
    access_type='offline')

当我被重定向到 Google 授权屏幕时,应用程序要求的唯一权限是“具有离线访问权限”。此外,我在 API 控制台中打开了这些范围。

最佳答案

来自documentation :

In addition to these OpenID-specific scopes, your scope argument can also include other scope strings. All scope strings must be space-separated. For example, if you wanted per-file access to a user’s Google Drive, your scope might be openid profile email https://www.googleapis.com/auth/drive.file.

所以在你的情况下:

scope= 'scope1 ' + 'scope2 ' + 'scope3'

示例:

scope = ('https://www.googleapis.com/auth/devstorage.read_write ' +
         'https://www.googleapis.com/auth/prediction')

编辑

正如@Greg 提到的:

OAuth2WebServerFlow takes either a string or an iterable of strings, which it turns into the space-separated parameter before constructing the auth-URL.

我倾向于将 oAuth 用于 api(应用程序授权),而不是将 oAuth 用于用户 oauth,所以我忘记了我在自己的应用程序中也观察到了这一点。

如果您的范围有无效 授权,那么您将收到有关错误授权的错误消息。

不过,如果您要求正确 资助,大多数时候它们是结合在一起的。

在下面的示例中,我询问的是 'https://www.googleapis.com/auth/devstorage.read_write ' + 'https://www.googleapis.com/auth/prediction'

但尽管我只收到离线访问提示。 我的应用程序运行良好,权限正确。 该应用程序没有更多权限(其他 api)。

关于python - 使用 OAuth2WebServerFlow 的多个范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21463869/

相关文章:

python - 获取 Blobstore key

java - 如何获取 Google App Engine 管理员邮件地址?

python - 如何对 numpy 矩阵中的每个元素执行操作?

python 或数据库?

php - 编码 php 和 python?

python - 使用带有 IF 语句的 Schedule 库的 Python

security - 谷歌应用引擎的 ssl 是免费的吗?

java - 为什么我不能在我的 java 应用程序的 GAE 中换行?

java - 插件使用 GAE 不支持的类是否会导致运行时错误或在部署时启动

python - 如何在Python类中模拟.users.get?