I have an application in GAE and I'm using a service account to call some google services. When I created a service account in the dashboard, a JSON key was provided to me. The content of the json is 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 generate a GoogleCredential object?
I was able to do that using the setServiceAccountPrivateKeyFromP12File
method but for that I would need to create a p12 file and have it stored somewhere. With the json private key I could have it configured in my properties file.
I found a setServiceAccountPrivate
method in the GoogleCredential.Builder
that receives a PrivateKey object as parameter but I don't know how to generate this object from the value inside the json. All examples that I found were using the p12 file.