• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 GRPCPP_SECURITY_CREDENTIALS_H
20 #define GRPCPP_SECURITY_CREDENTIALS_H
21 
22 #include <grpcpp/security/credentials_impl.h>
23 
24 namespace grpc {
25 
26 typedef ::grpc_impl::ChannelCredentials ChannelCredentials;
27 typedef ::grpc_impl::CallCredentials CallCredentials;
28 typedef ::grpc_impl::SslCredentialsOptions SslCredentialsOptions;
29 typedef ::grpc_impl::SecureCallCredentials SecureCallCredentials;
30 typedef ::grpc_impl::SecureChannelCredentials SecureChannelCredentials;
31 typedef ::grpc_impl::MetadataCredentialsPlugin MetadataCredentialsPlugin;
32 
33 static inline std::shared_ptr<grpc_impl::ChannelCredentials>
GoogleDefaultCredentials()34 GoogleDefaultCredentials() {
35   return ::grpc_impl::GoogleDefaultCredentials();
36 }
37 
SslCredentials(const SslCredentialsOptions & options)38 static inline std::shared_ptr<ChannelCredentials> SslCredentials(
39     const SslCredentialsOptions& options) {
40   return ::grpc_impl::SslCredentials(options);
41 }
42 
43 static inline std::shared_ptr<grpc_impl::CallCredentials>
GoogleComputeEngineCredentials()44 GoogleComputeEngineCredentials() {
45   return ::grpc_impl::GoogleComputeEngineCredentials();
46 }
47 
48 /// Constant for maximum auth token lifetime.
49 constexpr long kMaxAuthTokenLifetimeSecs =
50     ::grpc_impl::kMaxAuthTokenLifetimeSecs;
51 
52 static inline std::shared_ptr<grpc_impl::CallCredentials>
53 ServiceAccountJWTAccessCredentials(
54     const std::string& json_key,
55     long token_lifetime_seconds = grpc::kMaxAuthTokenLifetimeSecs) {
56   return ::grpc_impl::ServiceAccountJWTAccessCredentials(
57       json_key, token_lifetime_seconds);
58 }
59 
60 static inline std::shared_ptr<grpc_impl::CallCredentials>
GoogleRefreshTokenCredentials(const std::string & json_refresh_token)61 GoogleRefreshTokenCredentials(const std::string& json_refresh_token) {
62   return ::grpc_impl::GoogleRefreshTokenCredentials(json_refresh_token);
63 }
64 
65 static inline std::shared_ptr<grpc_impl::CallCredentials>
AccessTokenCredentials(const std::string & access_token)66 AccessTokenCredentials(const std::string& access_token) {
67   return ::grpc_impl::AccessTokenCredentials(access_token);
68 }
69 
GoogleIAMCredentials(const std::string & authorization_token,const std::string & authority_selector)70 static inline std::shared_ptr<grpc_impl::CallCredentials> GoogleIAMCredentials(
71     const std::string& authorization_token,
72     const std::string& authority_selector) {
73   return ::grpc_impl::GoogleIAMCredentials(authorization_token,
74                                            authority_selector);
75 }
76 
CompositeChannelCredentials(const std::shared_ptr<ChannelCredentials> & channel_creds,const std::shared_ptr<CallCredentials> & call_creds)77 static inline std::shared_ptr<ChannelCredentials> CompositeChannelCredentials(
78     const std::shared_ptr<ChannelCredentials>& channel_creds,
79     const std::shared_ptr<CallCredentials>& call_creds) {
80   return ::grpc_impl::CompositeChannelCredentials(channel_creds, call_creds);
81 }
82 
83 static inline std::shared_ptr<grpc_impl::CallCredentials>
CompositeCallCredentials(const std::shared_ptr<CallCredentials> & creds1,const std::shared_ptr<CallCredentials> & creds2)84 CompositeCallCredentials(const std::shared_ptr<CallCredentials>& creds1,
85                          const std::shared_ptr<CallCredentials>& creds2) {
86   return ::grpc_impl::CompositeCallCredentials(creds1, creds2);
87 }
88 
89 static inline std::shared_ptr<grpc_impl::ChannelCredentials>
InsecureChannelCredentials()90 InsecureChannelCredentials() {
91   return ::grpc_impl::InsecureChannelCredentials();
92 }
93 
94 typedef ::grpc_impl::MetadataCredentialsPlugin MetadataCredentialsPlugin;
95 
96 static inline std::shared_ptr<grpc_impl::CallCredentials>
MetadataCredentialsFromPlugin(std::unique_ptr<MetadataCredentialsPlugin> plugin)97 MetadataCredentialsFromPlugin(
98     std::unique_ptr<MetadataCredentialsPlugin> plugin) {
99   return ::grpc_impl::MetadataCredentialsFromPlugin(std::move(plugin));
100 }
101 
102 namespace experimental {
103 
104 typedef ::grpc_impl::experimental::StsCredentialsOptions StsCredentialsOptions;
105 
StsCredentialsOptionsFromJson(const std::string & json_string,StsCredentialsOptions * options)106 static inline grpc::Status StsCredentialsOptionsFromJson(
107     const std::string& json_string, StsCredentialsOptions* options) {
108   return ::grpc_impl::experimental::StsCredentialsOptionsFromJson(json_string,
109                                                                   options);
110 }
111 
StsCredentialsOptionsFromEnv(StsCredentialsOptions * options)112 static inline grpc::Status StsCredentialsOptionsFromEnv(
113     StsCredentialsOptions* options) {
114   return grpc_impl::experimental::StsCredentialsOptionsFromEnv(options);
115 }
116 
StsCredentials(const StsCredentialsOptions & options)117 static inline std::shared_ptr<grpc_impl::CallCredentials> StsCredentials(
118     const StsCredentialsOptions& options) {
119   return grpc_impl::experimental::StsCredentials(options);
120 }
121 
122 typedef ::grpc_impl::experimental::AltsCredentialsOptions
123     AltsCredentialsOptions;
124 
AltsCredentials(const AltsCredentialsOptions & options)125 static inline std::shared_ptr<grpc_impl::ChannelCredentials> AltsCredentials(
126     const AltsCredentialsOptions& options) {
127   return ::grpc_impl::experimental::AltsCredentials(options);
128 }
129 
LocalCredentials(grpc_local_connect_type type)130 static inline std::shared_ptr<grpc_impl::ChannelCredentials> LocalCredentials(
131     grpc_local_connect_type type) {
132   return ::grpc_impl::experimental::LocalCredentials(type);
133 }
134 
TlsCredentials(const::grpc_impl::experimental::TlsCredentialsOptions & options)135 static inline std::shared_ptr<grpc_impl::ChannelCredentials> TlsCredentials(
136     const ::grpc_impl::experimental::TlsCredentialsOptions& options) {
137   return ::grpc_impl::experimental::TlsCredentials(options);
138 }
139 
140 }  // namespace experimental
141 }  // namespace grpc
142 
143 #endif  // GRPCPP_SECURITY_CREDENTIALS_H
144