15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OAUTH2_AUTHORIZED_USER_CREDENTIALS_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OAUTH2_AUTHORIZED_USER_CREDENTIALS_H
18 #include "google/cloud/storage/internal/curl_request_builder.h"
19 #include "google/cloud/storage/internal/http_response.h"
20 #include "google/cloud/storage/oauth2/credential_constants.h"
21 #include "google/cloud/storage/oauth2/credentials.h"
22 #include "google/cloud/storage/oauth2/refreshing_credentials_wrapper.h"
23 #include "google/cloud/storage/version.h"
24 #include "google/cloud/status.h"
45 std::string
const& content, std::string
const& source,
52 storage::internal::HttpResponse
const& response,
53 std::chrono::system_clock::time_point now);
77 template <
typename HttpRequestBuilderType =
78 storage::internal::CurlRequestBuilder,
79 typename ClockType = std::chrono::system_clock>
84 : info_(std::move(info)),
90 std::unique_lock<std::mutex> lock(mu_);
91 return refreshing_creds_.AuthorizationHeader(clock_.now(),
92 [
this] {
return Refresh(); });
97 HttpRequestBuilderType builder(
99 storage::internal::GetDefaultCurlHandleFactory(options_));
100 std::string payload(
"grant_type=refresh_token");
101 payload +=
"&client_id=";
102 payload += builder.MakeEscapedString(info_
.client_id).get();
103 payload +=
"&client_secret=";
105 payload +=
"&refresh_token=";
107 auto response = std::move(builder).BuildRequest().MakeRequest(payload);
108 if (!response)
return std::move(response).status();
109 if (response->status_code >= 300)
return AsStatus(*response);
110 return ParseAuthorizedUserRefreshResponse(*response, clock_.now());
116 mutable std::mutex mu_;