0
votes

I am trying to authenticate a Google Admin SDK using ServiceAccountCredentials.from_json(). I am using the Google Cloud Platform to run a Cloud Function. The Cloud Function gets a file from Cloud Storage, decrypts it, then uses that file to authenticate the service. According to this I can authenticate using from_json_keyfile_name. I wont have a direct path though so I attempted to authenticate with the contents of the file from Google Console -> API -> Download credentials. That json has the following keys:

  • type
  • project_id
  • private_key_id
  • private_key
  • client_email
  • client_id
  • auth_uri
  • token_uri
  • auth_provider_x509_cert_url
  • client_x509_cert_url

However, ServiceAccountCredentials.from_json() looks for _private_key_pkcs12. which is not in the downloaded json.

1
I'm having trouble understanding what is the issue and what are you trying to accomplish. Could you give some more details on what is the problem you're running into?Maxim
@Maxim Sure. Basically, I need to create a Service Account for Google Admin using json. Not a json file, but actual json. This is possible with ServiceAccountCredentials.from_json() but it excepts data like _private_key_pkcs12 which is not found in the json file downloaded from Google Console.user1222324562

1 Answers

1
votes

oauth2client is deprecated. Use google.oauth2.service_account.

Example

from google.oauth2 import service_account
credentials = service_account.Credentials.from_service_account_info(sa_json)
return build(service_name, service_version, credentials=credentials)