GRPC C++  0.11.0.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
credentials.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015, Google Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following disclaimer
14  * in the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of Google Inc. nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 
34 #ifndef GRPCXX_CREDENTIALS_H
35 #define GRPCXX_CREDENTIALS_H
36 
37 #include <memory>
38 
40 #include <grpc++/support/config.h>
41 
42 namespace grpc {
43 class ChannelArguments;
44 class Channel;
45 class SecureCredentials;
46 
53 class Credentials : public GrpcLibrary {
54  public:
56 
58  virtual bool ApplyToCall(grpc_call* call) = 0;
59 
60  protected:
61  friend std::shared_ptr<Credentials> CompositeCredentials(
62  const std::shared_ptr<Credentials>& creds1,
63  const std::shared_ptr<Credentials>& creds2);
64 
65  virtual SecureCredentials* AsSecureCredentials() = 0;
66 
67  private:
68  friend std::shared_ptr<Channel> CreateCustomChannel(
69  const grpc::string& target, const std::shared_ptr<Credentials>& creds,
70  const ChannelArguments& args);
71 
72  virtual std::shared_ptr<Channel> CreateChannel(
73  const grpc::string& target, const ChannelArguments& args) = 0;
74 };
75 
84 
88 
93 };
94 
95 // Factories for building different types of Credentials The functions may
96 // return empty shared_ptr when credentials cannot be created. If a
97 // Credentials pointer is returned, it can still be invalid when used to create
98 // a channel. A lame channel will be created then and all rpcs will fail on it.
99 
106 std::shared_ptr<Credentials> GoogleDefaultCredentials();
107 
109 std::shared_ptr<Credentials> SslCredentials(
110  const SslCredentialsOptions& options);
111 
118 std::shared_ptr<Credentials> GoogleComputeEngineCredentials();
119 
125 std::shared_ptr<Credentials> ServiceAccountJWTAccessCredentials(
126  const grpc::string& json_key, long token_lifetime_seconds);
127 
136 std::shared_ptr<Credentials> GoogleRefreshTokenCredentials(
137  const grpc::string& json_refresh_token);
138 
147 std::shared_ptr<Credentials> AccessTokenCredentials(
148  const grpc::string& access_token);
149 
156 std::shared_ptr<Credentials> GoogleIAMCredentials(
157  const grpc::string& authorization_token,
158  const grpc::string& authority_selector);
159 
161 std::shared_ptr<Credentials> CompositeCredentials(
162  const std::shared_ptr<Credentials>& creds1,
163  const std::shared_ptr<Credentials>& creds2);
164 
166 std::shared_ptr<Credentials> InsecureCredentials();
167 
168 } // namespace grpc
169 
170 #endif // GRPCXX_CREDENTIALS_H
std::shared_ptr< Credentials > SslCredentials(const SslCredentialsOptions &options)
Builds SSL Credentials given SSL specific options.
std::string string
Definition: config.h:112
std::shared_ptr< Credentials > GoogleRefreshTokenCredentials(const grpc::string &json_refresh_token)
Builds refresh token credentials.
Options for channel creation.
Definition: channel_arguments.h:52
std::shared_ptr< Credentials > ServiceAccountJWTAccessCredentials(const grpc::string &json_key, long token_lifetime_seconds)
Builds Service Account JWT Access credentials.
friend std::shared_ptr< Channel > CreateCustomChannel(const grpc::string &target, const std::shared_ptr< Credentials > &creds, const ChannelArguments &args)
Create a new custom Channel pointing to target.
~Credentials() GRPC_OVERRIDE
std::shared_ptr< Credentials > AccessTokenCredentials(const grpc::string &access_token)
Builds access token credentials.
virtual bool ApplyToCall(grpc_call *call)=0
Apply this instance's credentials to call.
grpc::string pem_root_certs
The buffer containing the PEM encoding of the server root certificates.
Definition: credentials.h:83
Options used to build SslCredentials.
Definition: credentials.h:77
Definition: grpc_library.h:41
virtual SecureCredentials * AsSecureCredentials()=0
grpc::string pem_cert_chain
The buffer containing the PEM encoding of the client's certificate chain.
Definition: credentials.h:92
std::shared_ptr< Credentials > GoogleIAMCredentials(const grpc::string &authorization_token, const grpc::string &authority_selector)
Builds IAM credentials.
A credentials object encapsulates all the state needed by a client to authenticate with a server and ...
Definition: credentials.h:53
grpc::string pem_private_key
The buffer containing the PEM encoding of the client's private key.
Definition: credentials.h:87
std::shared_ptr< Credentials > GoogleDefaultCredentials()
Builds credentials with reasonable defaults.
friend std::shared_ptr< Credentials > CompositeCredentials(const std::shared_ptr< Credentials > &creds1, const std::shared_ptr< Credentials > &creds2)
Combines two credentials objects into a composite credentials.
std::shared_ptr< Credentials > InsecureCredentials()
Credentials for an unencrypted, unauthenticated channel.
std::shared_ptr< Credentials > GoogleComputeEngineCredentials()
Builds credentials for use when running in GCE.
std::shared_ptr< Credentials > CompositeCredentials(const std::shared_ptr< Credentials > &creds1, const std::shared_ptr< Credentials > &creds2)
Combines two credentials objects into a composite credentials.
#define GRPC_OVERRIDE
Definition: config.h:77