GRPC Core  9.0.0
json_token.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 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_JSON_TOKEN_H
20 #define GRPC_CORE_LIB_SECURITY_CREDENTIALS_JWT_JSON_TOKEN_H
21 
23 
25 
26 #include <grpc/slice.h>
27 #include <openssl/rsa.h>
28 
29 #include "src/core/lib/json/json.h"
30 
31 /* --- Constants. --- */
32 
33 #define GRPC_JWT_OAUTH2_AUDIENCE "https://oauth2.googleapis.com/token"
34 
35 /* --- auth_json_key parsing. --- */
36 
37 typedef struct {
38  const char* type;
40  char* client_id;
41  char* client_email;
44 
45 /* Returns 1 if the object is valid, 0 otherwise. */
47 
48 /* Creates a json_key object from string. Returns an invalid object if a parsing
49  error has been encountered. */
51  const char* json_string);
52 
53 /* Creates a json_key object from parsed json. Returns an invalid object if a
54  parsing error has been encountered. */
56 
57 /* Destructs the object. */
59 
60 /* --- json token encoding and signing. --- */
61 
62 /* Caller is responsible for calling gpr_free on the returned value. May return
63  NULL on invalid input. The scope parameter may be NULL. */
64 char* grpc_jwt_encode_and_sign(const grpc_auth_json_key* json_key,
65  const char* audience,
66  gpr_timespec token_lifetime, const char* scope);
67 
68 /* Override encode_and_sign function for testing. */
69 typedef char* (*grpc_jwt_encode_and_sign_override)(
70  const grpc_auth_json_key* json_key, const char* audience,
71  gpr_timespec token_lifetime, const char* scope);
72 
73 /* Set a custom encode_and_sign override for testing. */
76 
77 #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_JWT_JSON_TOKEN_H */
void grpc_auth_json_key_destruct(grpc_auth_json_key *json_key)
Definition: json_token.cc:133
char *(* grpc_jwt_encode_and_sign_override)(const grpc_auth_json_key *json_key, const char *audience, gpr_timespec token_lifetime, const char *scope)
Definition: json_token.h:69
void grpc_jwt_encode_and_sign_set_override(grpc_jwt_encode_and_sign_override func)
Definition: json_token.cc:315
grpc_auth_json_key grpc_auth_json_key_create_from_json(const grpc_json *json)
Definition: json_token.cc:68
int grpc_auth_json_key_is_valid(const grpc_auth_json_key *json_key)
Definition: json_token.cc:63
grpc_auth_json_key grpc_auth_json_key_create_from_string(const char *json_string)
Definition: json_token.cc:123
char * grpc_jwt_encode_and_sign(const grpc_auth_json_key *json_key, const char *audience, gpr_timespec token_lifetime, const char *scope)
Definition: json_token.cc:295
Analogous to struct timespec.
Definition: gpr_types.h:47
Definition: json_token.h:37
const char * type
Definition: json_token.h:38
RSA * private_key
Definition: json_token.h:42
char * private_key_id
Definition: json_token.h:39
char * client_id
Definition: json_token.h:40
char * client_email
Definition: json_token.h:41
Definition: json.h:32