GRPC Core  9.0.0
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 
26 
28  : public grpc_call_credentials {
29  public:
31  gpr_timespec token_lifetime);
33 
37  grpc_closure* on_request_metadata,
38  grpc_error** error) override;
39 
41  grpc_error* error) override;
42 
43  const gpr_timespec& jwt_lifetime() const { return jwt_lifetime_; }
44  const grpc_auth_json_key& key() const { return key_; }
45 
46  private:
47  void reset_cache();
48 
49  // Have a simple cache for now with just 1 entry. We could have a map based on
50  // the service_url for a more sophisticated one.
51  gpr_mu cache_mu_;
52  struct {
54  char* service_url = nullptr;
56  } cached_;
57 
58  grpc_auth_json_key key_;
59  gpr_timespec jwt_lifetime_;
60 };
61 
62 // Private constructor for jwt credentials from an already parsed json key.
63 // Takes ownership of the key.
66  grpc_auth_json_key key, gpr_timespec token_lifetime);
67 
68 #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_JWT_JWT_CREDENTIALS_H */
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:112
grpc_service_account_jwt_access_credentials::cancel_get_request_metadata
void cancel_get_request_metadata(grpc_credentials_mdelem_array *md_array, grpc_error *error) override
Definition: jwt_credentials.cc:106
grpc_service_account_jwt_access_credentials
Definition: jwt_credentials.h:28
grpc_call_credentials
Definition: credentials.h:226
json_token.h
grpc_service_account_jwt_access_credentials::jwt_lifetime
const gpr_timespec & jwt_lifetime() const
Definition: jwt_credentials.h:43
grpc_core::RefCountedPtr< grpc_call_credentials >
grpc_service_account_jwt_access_credentials::~grpc_service_account_jwt_access_credentials
~grpc_service_account_jwt_access_credentials() override
Definition: jwt_credentials.cc:46
grpc_service_account_jwt_access_credentials::jwt_md
grpc_mdelem jwt_md
Definition: jwt_credentials.h:53
credentials.h
grpc_polling_entity
Definition: polling_entity.h:37
grpc_service_account_jwt_access_credentials::get_request_metadata
bool get_request_metadata(grpc_polling_entity *pollent, grpc_auth_metadata_context context, grpc_credentials_mdelem_array *md_array, grpc_closure *on_request_metadata, grpc_error **error) override
Definition: jwt_credentials.cc:52
grpc_mdelem
Definition: metadata.h:98
grpc_service_account_jwt_access_credentials::service_url
char * service_url
Definition: jwt_credentials.h:54
grpc_service_account_jwt_access_credentials::key
const grpc_auth_json_key & key() const
Definition: jwt_credentials.h:44
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:128
GRPC_MDNULL
#define GRPC_MDNULL
Definition: metadata.h:403
gpr_mu
Definition: sync_windows.h:26
gpr_timespec
Analogous to struct timespec.
Definition: gpr_types.h:47
grpc_error
Definition: error_internal.h:39
grpc_auth_metadata_context
Context that can be used by metadata credentials plugin in order to create auth related metadata.
Definition: grpc_security.h:373
grpc_closure
A closure over a grpc_iomgr_cb_func.
Definition: closure.h:56
grpc_credentials_mdelem_array
Definition: credentials.h:205
grpc_service_account_jwt_access_credentials::jwt_expiration
gpr_timespec jwt_expiration
Definition: jwt_credentials.h:55
port_platform.h
grpc_auth_json_key
Definition: json_token.h:37