I have an application in GAE and I use a service account to call some google services. When I created the service account in the control panel, I was given the JSON key. The json content looks something like this:
{ "private_key_id": "bar-foo", "private_key": "-----BEGIN PRIVATE KEY-----foo-bar\n-----END PRIVATE KEY-----\n", "client_email": " foo-bar@developer.gserviceaccount.com ", "client_id": "bar-foo.apps.googleusercontent.com", "type": "service_account" }
How can I use this private_key in my java code to create a GoogleCredential object?
I was able to do this using the setServiceAccountPrivateKeyFromP12File method, but for this I would need to create a p12 file and store it somewhere. With json private key, I could configure it in the properties file.
I found the setServiceAccountPrivate method in GoogleCredential.Builder that takes a PrivateKey object as a parameter, but I don't know how to generate this object from a value inside json. All the examples I found used the p12 file.
source share