【问题标题】:Authentication when using Gmail API and Google App-Engine使用 Gmail API 和 Google App-Engine 时的身份验证
【发布时间】:2017-12-04 08:34:25
【问题描述】:

这可能(再一次)是一个愚蠢/基本的问题。但它就在这里。

我正在尝试构建一个网络应用程序来查询和显示来自用户 Gmail 的一些信息。我目前的想法如下:

  • 让后端在 Google AppEngine(用 Python 编码)上运行,它的端点接收诸如“过去一个月内有多少此类电子邮件”之类的查询并返回正确答案。

  • 前端可以是可以使用 REST 查询端点的网站或 Android 应用程序。

目前的问题是身份验证。我想知道我的应用程序的正确身份验证流程。据我所知,有两种可能的选择:

1) 使用前端检查用户是否登录。如果没有,验证并将用户凭据发送到后端(也许使用 javascript 版本的 GMAIL API?)。 2)让后端处理身份验证。一旦它在端点上获得查询,如果用户未通过身份验证,它会将用户重定向到登录页面。我遇到的问题之一是我在我的 AppEngine 上使用 Python,所有 Python 的 GMAIL API 教程都需要从硬盘上的 JSON 文件中读取凭据/clientID。这在 AppEngine 上是不可能的,因为我们无法在本地磁盘上存储任何文件。

有人能指出正确的方向吗?

谢谢。

【问题讨论】:

  • 不能在 App Engine 中存储 JSON 文件是什么意思?您可以在 App Engine 中保存 JSON 文件,然后您只需在身份验证代码中指向 JSON 文件的路径。
  • @BravinBalasubramaniam cloud.google.com/appengine/docs/standard/php/googlestorage。这是否意味着我需要使用 Google Cloud Storage 来读取 JSON 文件?我只想像 GMAIL API Javascript 教程一样直接使用 ClientID。

标签: android python google-app-engine authentication gmail


【解决方案1】:

您不需要谷歌云存储来存储 JSON 文件,您可以将其存储在 App Engine 中,也无需存储在 JSON 文件中,您可以直接将其用作代码本身中的 clientID。

JSON 文件中的 client_id 和 client_secret

from oauth2client.client import flow_from_clientsecrets
...
flow = flow_from_clientsecrets('path_to_directory/client_secrets.json',
                               scope='https://www.googleapis.com/auth/calendar',
                               redirect_uri='http://example.com/auth_return')

不存储在 JSON 文件中

from oauth2client.client import OAuth2WebServerFlow
...
flow = OAuth2WebServerFlow(client_id='your_client_id',
                           client_secret='your_client_secret',
                           scope='https://www.googleapis.com/auth/calendar',
                           redirect_uri='http://example.com/auth_return')

Please refer this documentation for further details

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-30
    • 1970-01-01
    • 2011-03-05
    • 1970-01-01
    • 1970-01-01
    • 2011-12-25
    • 1970-01-01
    相关资源
    最近更新 更多