在我的组织中,我们有一个内部开发的web应用程序,它依赖于Google apps provisioning API来允许我们的一级IT部门管理电子邮件帐户和电子邮件组。然而,由于谷歌放弃了API而支持Admin's SDK Directory API,我们的web应用程序的一些功能已经停止工作,所以是时候开始重新编写web应用程序的后端了。
然而,我们面临的问题是,新的应用程序接口使用oAuth 2.0身份验证,与旧的应用程序接口一样,我可以硬编码管理员用户并获得授权令牌,整个想法是将具有域管理员权限的用户和凭据的数量降至最少。
所以问题是,有没有办法让这个“虚拟”用户授权应用程序一次,再也不会有一个类似的架构,我们以前有过吗?尽管我承认更好的问题是:在这种情况下遵循的最佳实践是什么?
发布于 2014-10-24 18:18:11
最适合您的情况的身份验证流是两条腿的oauth。使用OAuth2.0,您需要设置Service Account Credentials。
要使用服务帐户凭据构建管理服务,请执行以下操作:
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 servicehttps://stackoverflow.com/questions/24019416
复制相似问题