2.12.0-rc 2.11.0 (latest)

# 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::debugger_v2::Controller2Client(
        google::cloud::debugger_v2::MakeController2Connection(options));
  }
```

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

- [`debugger_v2::Controller2Client`](https://docs.cloud.google.com/cpp/docs/reference/debugger/latest/debugger_v2_1_1Controller2Client-service-account-snippet.md.txt)
- [`debugger_v2::Debugger2Client`](https://docs.cloud.google.com/cpp/docs/reference/debugger/latest/debugger_v2_1_1Debugger2Client-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.