2.13.0-rc 2.12.0 (latest) 2.11.0

# How to Override the Authentication Credentials

Unless otherwise configured, the client libraries use [Application Default Credentials](https://cloud.google.com/docs/authentication#adc) to authenticate with Google Cloud Services. While this works for most applications, in some cases you may need to override this default. You can do so by providing the [UnifiedCredentialsOption](https://cloud.google.com/cpp/docs/reference/common/latest/structgoogle_1_1cloud_1_1UnifiedCredentialsOption.html) The following example shows how to explicitly load a service account key file:

```cpp
  [](std::string const& keyfile) {
    auto is = std::ifstream(keyfile);
    is.exceptions(std::ios::badbit);  // Minimal error handling in examples
    auto contents = std::string(std::istreambuf_iterator<char>(is.rdbuf()), {});
    auto options =
        google::cloud::Options{}.set<google::cloud::UnifiedCredentialsOption>(
            google::cloud::MakeServiceAccountCredentials(contents));
    return google::cloud::gameservices_v1::GameServerClustersServiceClient(
        google::cloud::gameservices_v1::MakeGameServerClustersServiceConnection(
            options));
  }
```

Follow these links to find examples for other `*Client` classes:

- [`gameservices_v1::GameServerClustersServiceClient`](https://docs.cloud.google.com/cpp/docs/reference/gameservices/latest/gameservices_v1_1_1GameServerClustersServiceClient-service-account-snippet.md.txt)
- [`gameservices_v1::GameServerConfigsServiceClient`](https://docs.cloud.google.com/cpp/docs/reference/gameservices/latest/gameservices_v1_1_1GameServerConfigsServiceClient-service-account-snippet.md.txt)
- [`gameservices_v1::GameServerDeploymentsServiceClient`](https://docs.cloud.google.com/cpp/docs/reference/gameservices/latest/gameservices_v1_1_1GameServerDeploymentsServiceClient-service-account-snippet.md.txt)
- [`gameservices_v1::RealmsServiceClient`](https://docs.cloud.google.com/cpp/docs/reference/gameservices/latest/gameservices_v1_1_1RealmsServiceClient-service-account-snippet.md.txt)

Keep in mind that we chose this as an example because it is relatively easy to understand. Consult the [Best practices for managing service account keys](https://cloud.google.com/iam/docs/best-practices-for-managing-service-account-keys) guide for more details.

###### See Also

[Authentication Components](https://cloud.google.com/cpp/docs/reference/common/latest/group__guac.html) - for more information on the factory functions to create [`google::cloud::Credentials`](https://cloud.google.com/cpp/docs/reference/common/latest/classgoogle_1_1cloud_1_1Credentials.html) objects.