簡體   English   中英

取代Google Apps 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM