如何获取服务帐户的承载访问令牌

时间:2014-10-16 13:26:14

标签: oauth-2.0 access-token service-accounts bearer-token

我已为此服务帐户生成凭据:

f = file(settings.SERVICE_ACCOUNT_PKCS12_FILE_PATH, 'rb')
key = f.read()
f.close()
credentials = client.SignedJwtAssertionCredentials(settings.SERVICE_ACCOUNT_EMAIL, key, scope=settings.GROUPS_SCOPE, sub=settings.ADMIN_DOMAIN_EMAIL)
print 'credentials : '+str(credentials.to_json())

打印以json格式显示凭据:

{"private_key": "MIIGwAIBAzCCBnoGLUn09Ywa1l7G8XC2SgA9eDhXAdKw4DAh...83J+6iAgIEAA==", "id_token": null, "token_uri": "https://accounts.google.com/o/oauth2/token", "token_response": null, "client_id": null, "scope": "https://www.googleapis.com/auth/admin.directory.group", "token_expiry": null, "_class": "SignedJwtAssertionCredentials", "refresh_token": null, "_module": "oauth2client.client", "private_key_password": "notasecret", "access_token": null, "service_account_name": "xxx@developer.gserviceaccount.com", "invalid": false, "assertion_type": null, "kwargs": {"sub": "username@domain.com"}, "client_secret": null, "revoke_uri": "https://accounts.google.com/o/oauth2/revoke", "user_agent": null}

这会生成一个null的私钥和访问令牌。

是否有一个类可以指定here指定{{3}}的REST请求来获取访问令牌?

1 个答案:

答案 0 :(得分:2)