将单点登录添加到 GMail API 授权

Adding Single-sign-on to GMail API authorization

我已经在 Google App Engine 上成功创建了一个 python 网络应用程序,可以与 Gmail API 进行交互。我现在想要得到的是,当授予权限时,我的应用程序还会创建一个用户帐户,用户可以使用他们的 Google 帐户登录该帐户。这将避免用户不得不为我的应用输入另一个密码。

总而言之,当前的工作流程是: 1.用户通过输入电子邮件和密码创建帐户 2.用户授权GMail访问

我想得到的是: 1. 用户连接 Google 帐户并由此获得一个帐户并验证 GMail 访问权限

执行此操作的最佳方法是什么?

我当前的 google API 代码如下所示。直接来自此处的 Google 示例:https://developers.google.com/api-client-library/python/guide/google_app_engine

from apiclient.discovery import build
from google.appengine.ext import webapp
from oauth2client.appengine import OAuth2Decorator

decorator = OAuth2Decorator(
  client_id='your_client_id',
  client_secret='your_client_secret',
  scope='https://www.googleapis.com/auth/calendar')

service = build('calendar', 'v3')

class MainHandler(webapp.RequestHandler):

  @decorator.oauth_required
  def get(self):
    # Get the authorized Http object created by the decorator.
    http = decorator.http()
    # Call the service using the authorized Http object.
    request = service.events().list(calendarId='primary')
    response = request.execute(http=http)
  1. 要访问 Google API,首先您必须在开发人员控制台中注册。检查这个 link

  2. 我了解您的流程是,用户使用 gmail id 和密码登录,并且用户必须授予对您的应用程序的访问权限。在使用 oauth 流程时,如果您在代码中 select 'access_type'='offline' ,即使用户处于离线状态,它也有助于访问信息。为此你需要 refresh token.

  3. 在您的开发人员控制台中,您必须激活您的应用程序将要使用的所有 API。

  4. 在上面提到的 Oauth link 你可以查看如何处理授权请求,如何验证用户。

  5. 如果你想service account, then don't forget to do domain wide delegation.

  6. 在决定 scopes 时,如果您的应用程序未向用户帐户写入任何信息,请使用只读范围。

检查此 link Gmail API python 中的示例客户端代码。

原来这正是我想要做的教程:https://developers.google.com/+/web/signin/server-side-flow