feat(clients): google service-account OAuth and per-endpoint credential choice
ServiceAccountAuth signs an RS256 JWT with wolfCrypt from the key file in GOOGLE_APPLICATION_CREDENTIALS and exchanges it for a self-refreshing bearer token. GoogleClient holds a key and an OAuth credential and uses OAuth everywhere except express endpoints, which only accept the key. Signing is tested with generated RSA keys and public-key verification. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#include "google/credentials.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include "google/service_account.h"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
@@ -46,6 +48,18 @@ std::string Credentials::env(const char* name) {
|
||||
return from_json_file(".env.json", name);
|
||||
}
|
||||
|
||||
std::shared_ptr<clients::Auth> Credentials::api_key_from_env(const char* name) {
|
||||
std::string key = env(name);
|
||||
if (key.empty()) return nullptr;
|
||||
return api_key(std::move(key));
|
||||
}
|
||||
|
||||
std::shared_ptr<clients::Auth> Credentials::oauth_from_env() {
|
||||
std::string token = env("GOOGLE_ACCESS_TOKEN");
|
||||
if (!token.empty()) return bearer(std::move(token));
|
||||
return ServiceAccountAuth::from_env();
|
||||
}
|
||||
|
||||
std::shared_ptr<clients::Auth> Credentials::from_env(const char* name) {
|
||||
// An OAuth access token (GOOGLE_ACCESS_TOKEN, e.g. from
|
||||
// `gcloud auth print-access-token`) wins: Agent Platform APIs need it.
|
||||
|
||||
Reference in New Issue
Block a user