简体   繁体   English

使用Gmail API和Google App-Engine时的身份验证

[英]Authentication when using Gmail API and Google App-Engine

This might (once again) be a silly/basic question. 这可能(再次)是一个愚蠢/基本的问题。 But here it goes. 但是在这里。

I am trying to build a web-app that queries and displays some information from the user's Gmail. 我正在尝试构建一个网络应用程序,以查询并显示来自用户Gmail的一些信息。 My current idea is as follows: 我目前的想法如下:

  • Have the backend run on Google AppEngine (coded in Python) where it has endpoints that take in queries like "How many such emails in the past one month" and returns the correct answer. 使后端在Google AppEngine(使用Python编码)上运行,该后端具有接受诸如“过去一个月中有多少此类电子邮件”之类的查询的终结点,并返回正确的答案。

  • The frontend can be a website or an android app that can query the endpoints using REST. 前端可以是可以使用REST查询端点的网站或android应用。

The issue currently is with Authentication. 当前的问题是身份验证。 I would like to know the right flow of authentication for my app. 我想知道我的应用程序正确的身份验证流程。 As far I see, there are two potential options: 据我所知,有两个潜在的选择:

1) Use the front-end to check if the user is logged in. If not, authenticate and send the user credentials to the backend (using the javascript version of GMAIL API perhaps?). 1)使用前端检查用户是否已登录。如果未登录,请进行身份验证并将用户凭据发送到后端(也许使用GMAIL API的javascript版本?)。 2) Let the backend handle the authentication. 2)让后端处理身份验证。 Once it gets the query on the endpoints, if the user is not authenticated, it redirects the user to a login page. 一旦在端点上获得查询,如果用户未通过身份验证,它将把用户重定向到登录页面。 One of the issues I have with this is that I am using the Python on my AppEngine and all the GMAIL API tutorial for Python requires reading the credentials/clientID from a JSON file on the hard disk. 我遇到的问题之一是,我在AppEngine上使用Python,并且所有适用于Python的GMAIL API教程都需要从硬盘上的JSON文件中读取凭据/ clientID。 This is not possible on AppEngine since we cannot store any file on local disk. 由于我们无法在本地磁盘上存储任何文件,因此在AppEngine上这是不可能的。

Can someone point me in the right direction? 有人可以指出我正确的方向吗?

Thanks. 谢谢。

You don't need Google cloud storage to store the JSON file you can store it in the App Engine it self, and also without storing inside the JSON file you can directly use it as clientID in the code itself. 您不需要Google云存储来存储JSON文件,您可以将其存储在自己的App Engine中,而且无需存储在JSON文件中,您就可以直接将其用作代码本身中的clientID。

client_id and client_secret within the JSON file 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')

Without storing inside the JSON file 无需存储在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 请参阅此文档以获取更多详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 应用引擎同时验证Google帐户和Google Plus - App-engine authenticating google account and google plus at the same time 通过应用引擎端点api服务Blobstore图像 - serving blobstore image through app-engine endpoints api Google Cloud SQL App Engine API认证 - Google Cloud SQL App Engine API authentication Android客户端-使用Google Cloud Endpoints的Google App引擎身份验证 - Android Client - Google App engine authentication using Google Cloud Endpoints gitignore用于App引擎连接的android项目 - gitignore for App-engine connected android project 如何连接谷歌应用程序引擎应用程序与我的Android? - How can i connect a google app-engine application with my android? google-cloud端点应用程序引擎连接的android项目的登台服务器 - staging server for google-cloud endpoint app-engine connected android project 更改的App-Engine Connected Android项目的App-Engine端的包名称未反映在Android Side - Changing package name of App-Engine side of App-Engine Connected Android Project not reflected on Android Side 如何使用Phonegap在Android中加载app-engine托管的HTML文件 - How to load app-engine hosted HTML file in Android using Phonegap 如何将Android App与App Engine上的数据存储连接 - How to connect android app with data store on app-engine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM