1
#include "source/extensions/http/injected_credentials/oauth2/client_credentials_impl.h"
2

            
3
namespace Envoy {
4
namespace Extensions {
5
namespace Http {
6
namespace InjectedCredentials {
7
namespace OAuth2 {
8

            
9
absl::Status OAuth2ClientCredentialTokenInjector::inject(Envoy::Http::RequestHeaderMap& headers,
10
23
                                                         bool overwrite) {
11
23
  if (!overwrite && !headers.get(Envoy::Http::CustomHeaders::get().Authorization).empty()) {
12
3
    return absl::AlreadyExistsError("Credential already exists in the header");
13
3
  }
14

            
15
20
  auto token = token_reader_->credential();
16

            
17
20
  if (token.empty()) {
18
2
    ENVOY_LOG(error, "Failed to get oauth2 token from token provider");
19
2
    return absl::NotFoundError("Failed to get oauth2 token from token provider");
20
2
  }
21

            
22
18
  headers.setReferenceKey(Envoy::Http::CustomHeaders::get().Authorization, token);
23
18
  return absl::OkStatus();
24
20
}
25

            
26
} // namespace OAuth2
27
} // namespace InjectedCredentials
28
} // namespace Http
29
} // namespace Extensions
30
} // namespace Envoy