# Adding google api config file to environment

**URL:** https://discourse.roots.io/t/adding-google-api-config-file-to-environment/14826
**Category:** trellis
**Created:** 2019-02-13T19:53:22Z
**Posts:** 9

## Post 1 by @morcth — 2019-02-13T19:53:22Z

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

---

## Post 2 by @codepuncher — 2019-02-13T21:34:46Z

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.

---

## Post 3 by @austin — 2019-02-15T17:42:13Z

> 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.

---

## Post 4 by @austin — 2019-02-15T17:45:41Z

1. put the file somewhere. Maybe in the config directory.
2. in your application.php define a config constant named “GOOGLE\_APPLICATION\_CREDENTIALS” and make the value as `realpath('./service-account.json')`
3. Feel free to add conditional logic like “service-account-staging.json” and stuff

---

## Post 5 by @codepuncher — 2019-02-15T18:36:31Z

Fair enough! How comes?

---

## Post 6 by @austin — 2019-02-15T18:54:38Z

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](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

---

## Post 7 by @morcth — 2019-02-15T19:08:15Z

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

---

## Post 8 by @austin — 2019-02-15T21:13:57Z

Seems fine! I have the same thing in my codebase

 ![image](https://discourse.roots.io/uploads/default/original/2X/b/b00d289fe4446da6a7af32f03dfad163bc703625.png)

---

## Post 9 by @system — 2019-03-27T20:02:08Z

This topic was automatically closed after 42 days. New replies are no longer allowed.
