首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >替换Google Apps Provisioning API

替换Google Apps Provisioning API
EN

Stack Overflow用户
提问于 2014-06-03 23:43:55
回答 1查看 237关注 0票数 2

在我的组织中,我们有一个内部开发的web应用程序,它依赖于Google apps provisioning API来允许我们的一级IT部门管理电子邮件帐户和电子邮件组。然而,由于谷歌放弃了API而支持Admin's SDK Directory API,我们的web应用程序的一些功能已经停止工作,所以是时候开始重新编写web应用程序的后端了。

然而,我们面临的问题是,新的应用程序接口使用oAuth 2.0身份验证,与旧的应用程序接口一样,我可以硬编码管理员用户并获得授权令牌,整个想法是将具有域管理员权限的用户和凭据的数量降至最少。

所以问题是,有没有办法让这个“虚拟”用户授权应用程序一次,再也不会有一个类似的架构,我们以前有过吗?尽管我承认更好的问题是:在这种情况下遵循的最佳实践是什么?

EN

回答 1

Stack Overflow用户

发布于 2014-10-24 18:18:11

最适合您的情况的身份验证流是两条腿的oauth。使用OAuth2.0,您需要设置Service Account Credentials

要使用服务帐户凭据构建管理服务,请执行以下操作:

代码语言:javascript
复制
import httplib2
import sys

from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials

def main(argv):
  # Load the key in PKCS 12 format that you downloaded from the Google API
  # Console when you created your Service account.
  f = file('key.p12', 'rb')
  key = f.read()
  f.close()

  # Create an httplib2.Http object to handle the HTTP requests and authorize it
  # with the Credentials. Note that the first parameter, service_account_name,
  # is the Email address created for the Service account. It must be the email
  # address associated with the key that was created.

  credentials = SignedJwtAssertionCredentials(
      'XXXXX@developer.gserviceaccount.com',
      key,
      scope='https://www.googleapis.com/auth/admin.directory.user')
  http = httplib2.Http()
  http = credentials.authorize(http)

  service = build('admin', 'directory_v1', http=http)

  # Then you can use the service
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24019416

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档