I managed to create a service account and a key of itself via the Python API iamcredetials.googleapis.com but I can't log it in since the key is in P12 format and received as a dict
, and I can't find the way to log the key in. is there a way to create a p12 file or something so I can use the key?
I tried using the functions available in the oauth2clinet.service_account.ServiceAccountCredentials()
module but none of them loads it successfully, I understand there's some grade of deprecation in this library and maybe I'm using obsolete methods.
The closer I was to a successfully log-in was when using the _from_p12_keyfile_contents()
function which gave an "encoding routines" error, which is beyond my understanding.
from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient import discovery, errors, logging
default_creds = google_application_defaults()
service = discovery.build("iam", "v1", credentials=default_creds, cache_discovery = False)
key = service.projects().serviceAccounts().keys().create( name = serviceAccMail, body={}).execute()
creds = ServiceAccountCredentials._from_p12_keyfile_contents(accountEmail, newkey["privateKeyData"], "notasecret")
Error: [('asn1 encoding routines', 'asn1_check_tlen', 'wrong tag'), ('asn1 encoding routines', 'asn1_item_embed_d2i', 'nested asn1 error')]
What's the correct way to log this key in?