morcth
February 13, 2019, 7:53pm
1
Hello,
I am trying to hook up google api access to my site. I have created a credentials file that I need to add to env.
I have added other config values in wordpress_sites.yml and vault just fine but this time it is a file with multiple values that needs to be added like this:
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json');
The file itself is something like this:
{
"type": "service_account",
"project_id": "xxx",
"private_key_id": "xxx",
"private_key": "-----BEGIN PRIVATE KEY-----xxx-----END PRIVATE KEY-----\n",
"client_email": "xxx",
"client_id": "xx",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "xxx"
}
I want the file outside of the root and have no idea how to do it.
Anybody know?
Thanks,
Josh
You could store everything inside of the JSON file as separate values in env
then make an endpoint that returns JSON using the values you need.
austin
February 15, 2019, 5:42pm
3
You could store everything inside of the JSON file as separate values in env
then make an endpoint that returns JSON using the values you need.
Sorry to be kurt but: don’t do this haha.
austin
February 15, 2019, 6:54pm
6
The api client expects a path to a file: https://github.com/googleapis/google-api-php-client/blob/master/README.md#authentication-with-service-accounts
You don’t want to care about what is in the JSON file, just feed it to the api client
1 Like
morcth
February 15, 2019, 7:08pm
7
Thanks so much guys.
I did something similar to Austin’s approach and it seems to be working.
Files in config seem to be added to the site directory just fine and in my test php I have:
require_once __DIR__.'/../../../../vendor/autoload.php';
$client->setAuthConfig(__DIR__ . '/../../../../config/client_secrets.json');
Those lines seem to be working fine.
@austin - your method might be a bit cleaner but is there any possible issues with my approach?
Thank you,
Josh
austin
February 15, 2019, 9:13pm
8
Seems fine! I have the same thing in my codebase
system
Closed
March 27, 2019, 8:02pm
9
This topic was automatically closed after 42 days. New replies are no longer allowed.