![](/img/trans.png)
[英]how to sign in to google apps and my own site without provisioning api
[英]Replacing Google Apps Provisioning API
在我的组织中,我们有一个内部开发的Web应用程序,该应用程序依靠Google Apps Provisioning API来允许我们的1级IT部门管理电子邮件帐户和电子邮件组。 但是,由于google不推荐使用该API,而推荐使用Admin的SDK Directory API ,因此我们的Web应用程序的某些功能已停止工作,因此现在该开始重新编写Web应用程序的后端了。
但是,我们面临的问题是,新API使用oAuth 2.0身份验证,就像旧API一样,我仅可以对管理员用户进行硬编码并获得授权令牌,所以整个想法是使用域的管理员权限。
所以问题是,有什么方法可以让这个“虚拟”用户一次授权该应用程序,而永远不会再拥有与以前相似的体系结构? 尽管我承认更好的问题是:在这种情况下应遵循的最佳实践是什么?
最适合您的情况的身份验证流程是two-leged-oauth。 使用oauth 2.0时,您需要设置服务帐户凭据 。
要使用“服务帐户凭据”构建管理服务,请执行以下操作:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.