15#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OAUTH2_REFRESHING_CREDENTIALS_WRAPPER_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OAUTH2_REFRESHING_CREDENTIALS_WRAPPER_H
18#include "google/cloud/storage/version.h"
19#include "google/cloud/internal/oauth2_refreshing_credentials_wrapper.h"
20#include "google/cloud/status.h"
21#include "google/cloud/status_or.h"
29GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
33
34
35
36
46 template <
typename RefreshFunctor>
48 std::chrono::system_clock::time_point, RefreshFunctor refresh_fn)
const {
49 auto refresh_fn_wrapper =
50 [refresh_fn]() -> StatusOr<
google::
cloud::internal::AccessToken> {
51 auto temp_token = refresh_fn();
52 if (!temp_token.ok())
return temp_token.status();
53 auto token = SplitToken(temp_token->token);
54 return google::
cloud::internal::AccessToken{std::move(token.second),
55 temp_token->expiration_time};
57 auto header = impl_->AuthorizationHeader(refresh_fn_wrapper);
58 if (!header.ok())
return std::move(header).status();
59 return header->first +
": " + header->second;
63
64
65
66
67
68
69
70
71
72
73
74
75 bool IsExpired(std::chrono::system_clock::time_point now)
const;
78
79
80
81
82
83
84
85 bool IsValid(std::chrono::system_clock::time_point now)
const;
88 static std::pair<std::string, std::string> SplitToken(
89 std::string
const& token);
91 std::unique_ptr<oauth2_internal::RefreshingCredentialsWrapper> impl_;
95GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
Wrapper for refreshable parts of a Credentials object.
Definition: refreshing_credentials_wrapper.h:37
bool IsValid(std::chrono::system_clock::time_point now) const
Returns whether the current access token should be considered valid.
bool IsExpired(std::chrono::system_clock::time_point now) const
Returns whether the current access token should be considered expired.
RefreshingCredentialsWrapper()
StatusOr< std::string > AuthorizationHeader(std::chrono::system_clock::time_point, RefreshFunctor refresh_fn) const
Definition: refreshing_credentials_wrapper.h:47
Authentication components for Google Cloud Storage.
Definition: anonymous_credentials.h:26
Contains all the Google Cloud Storage C++ client APIs.
Definition: auto_finalize.h:24
Definition: refreshing_credentials_wrapper.h:41
std::string token
Definition: refreshing_credentials_wrapper.h:42
std::chrono::system_clock::time_point expiration_time
Definition: refreshing_credentials_wrapper.h:43