jwt_credentials.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_LIB_SECURITY_CREDENTIALS_JWT_JWT_CREDENTIALS_H
20 #define GRPC_CORE_LIB_SECURITY_CREDENTIALS_JWT_JWT_CREDENTIALS_H
21 
23 
24 #include <stdint.h>
25 
26 #include <string>
27 
28 #include "absl/status/statusor.h"
29 #include "absl/strings/str_format.h"
30 #include "absl/strings/string_view.h"
31 #include "absl/time/time.h"
32 #include "absl/types/optional.h"
33 
34 #include <grpc/grpc_security.h>
36 #include <grpc/support/sync.h>
37 #include <grpc/support/time.h>
38 
47 
49  : public grpc_call_credentials {
50  public:
52  gpr_timespec token_lifetime);
54 
57  const GetRequestMetadataArgs* args) override;
58 
59  const gpr_timespec& jwt_lifetime() const { return jwt_lifetime_; }
60  const grpc_auth_json_key& key() const { return key_; }
61 
63  return absl::StrFormat(
64  "JWTAccessCredentials{ExpirationTime:%s}",
67  };
68 
70 
71  grpc_core::UniqueTypeName type() const override { return Type(); }
72 
73  private:
74  int cmp_impl(const grpc_call_credentials* other) const override {
75  // TODO(yashykt): Check if we can do something better here
77  static_cast<const grpc_call_credentials*>(this), other);
78  }
79 
80  // Have a simple cache for now with just 1 entry. We could have a map based on
81  // the service_url for a more sophisticated one.
83  struct Cache {
87  };
89 
92 };
93 
94 // Private constructor for jwt credentials from an already parsed json key.
95 // Takes ownership of the key.
98  grpc_auth_json_key key, gpr_timespec token_lifetime);
99 
100 namespace grpc_core {
101 
102 // Exposed for testing purposes only.
104 
105 } // namespace grpc_core
106 
107 #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_JWT_JWT_CREDENTIALS_H */
gpr_timespec_to_micros
GPRAPI double gpr_timespec_to_micros(gpr_timespec t)
Definition: src/core/lib/gpr/time.cc:237
slice.h
grpc_call_credentials::GetRequestMetadataArgs
Definition: src/core/lib/security/credentials/credentials.h:196
grpc_service_account_jwt_access_credentials::type
grpc_core::UniqueTypeName type() const override
Definition: jwt_credentials.h:71
absl::StrFormat
ABSL_MUST_USE_RESULT std::string StrFormat(const FormatSpec< Args... > &format, const Args &... args)
Definition: abseil-cpp/absl/strings/str_format.h:338
grpc_service_account_jwt_access_credentials::Type
static grpc_core::UniqueTypeName Type()
Definition: jwt_credentials.cc:127
grpc_service_account_jwt_access_credentials::grpc_service_account_jwt_access_credentials
grpc_service_account_jwt_access_credentials(grpc_auth_json_key key, gpr_timespec token_lifetime)
Definition: jwt_credentials.cc:113
grpc_core
Definition: call_metric_recorder.h:31
grpc_service_account_jwt_access_credentials
Definition: jwt_credentials.h:48
grpc_core::Slice
Definition: src/core/lib/slice/slice.h:282
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
grpc_service_account_jwt_access_credentials::Cache
Definition: jwt_credentials.h:83
useful.h
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc_service_account_jwt_access_credentials::Cache::jwt_value
grpc_core::Slice jwt_value
Definition: jwt_credentials.h:84
grpc_call_credentials
Definition: src/core/lib/security/credentials/credentials.h:189
grpc_service_account_jwt_access_credentials::debug_string
std::string debug_string() override
Definition: jwt_credentials.h:62
json_token.h
time.h
grpc_security.h
credentials.h
grpc_service_account_jwt_access_credentials::jwt_lifetime
const gpr_timespec & jwt_lifetime() const
Definition: jwt_credentials.h:59
absl::FormatTime
std::string FormatTime(absl::string_view format, absl::Time t, absl::TimeZone tz)
Definition: abseil-cpp/absl/time/format.cc:74
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
grpc_service_account_jwt_access_credentials::Cache::jwt_expiration
gpr_timespec jwt_expiration
Definition: jwt_credentials.h:86
grpc_core::RefCountedPtr< grpc_call_credentials >
int64_t
signed __int64 int64_t
Definition: stdint-msvc2008.h:89
grpc_service_account_jwt_access_credentials::key_
grpc_auth_json_key key_
Definition: jwt_credentials.h:90
grpc_service_account_jwt_access_credentials::GetRequestMetadata
grpc_core::ArenaPromise< absl::StatusOr< grpc_core::ClientMetadataHandle > > GetRequestMetadata(grpc_core::ClientMetadataHandle initial_metadata, const GetRequestMetadataArgs *args) override
Definition: jwt_credentials.cc:59
grpc_core::RemoveServiceNameFromJwtUri
absl::StatusOr< std::string > RemoveServiceNameFromJwtUri(absl::string_view uri)
Definition: jwt_credentials.cc:179
grpc_service_account_jwt_access_credentials::~grpc_service_account_jwt_access_credentials
~grpc_service_account_jwt_access_credentials() override
Definition: jwt_credentials.cc:53
absl::optional
Definition: abseil-cpp/absl/types/internal/optional.h:61
grpc_service_account_jwt_access_credentials::cache_mu_
gpr_mu cache_mu_
Definition: jwt_credentials.h:82
arena_promise.h
absl::FromUnixMicros
constexpr Time FromUnixMicros(int64_t us)
Definition: third_party/abseil-cpp/absl/time/time.h:1601
stdint.h
grpc_core::MetadataHandle< ClientMetadata >
grpc_service_account_jwt_access_credentials::cached_
absl::optional< Cache > cached_
Definition: jwt_credentials.h:88
gpr_types.h
grpc_service_account_jwt_access_credentials::jwt_lifetime_
gpr_timespec jwt_lifetime_
Definition: jwt_credentials.h:91
key
const char * key
Definition: hpack_parser_table.cc:164
grpc_core::UniqueTypeName
Definition: unique_type_name.h:56
grpc_core::ArenaPromise
Definition: arena_promise.h:152
grpc_core::QsortCompare
int QsortCompare(const T &a, const T &b)
Definition: useful.h:95
gpr_mu
pthread_mutex_t gpr_mu
Definition: impl/codegen/sync_posix.h:47
grpc_service_account_jwt_access_credentials::key
const grpc_auth_json_key & key() const
Definition: jwt_credentials.h:60
grpc_service_account_jwt_access_credentials_create_from_auth_json_key
grpc_core::RefCountedPtr< grpc_call_credentials > grpc_service_account_jwt_access_credentials_create_from_auth_json_key(grpc_auth_json_key key, gpr_timespec token_lifetime)
Definition: jwt_credentials.cc:133
unique_type_name.h
ref_counted_ptr.h
transport.h
absl::StatusOr< std::string >
gpr_timespec
Definition: gpr_types.h:50
sync.h
grpc_service_account_jwt_access_credentials::Cache::service_url
std::string service_url
Definition: jwt_credentials.h:85
grpc_service_account_jwt_access_credentials::cmp_impl
int cmp_impl(const grpc_call_credentials *other) const override
Definition: jwt_credentials.h:74
port_platform.h
grpc_auth_json_key
Definition: json_token.h:36


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:27