GRPC C++ 0.10.0.0

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

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
39 #include <grpc++/config.h>
40 #include <grpc++/impl/grpc_library.h>
41
42 namespace grpc {
43 class ChannelArguments;
44 class ChannelInterface;
45 class SecureCredentials;
46
47 class Credentials : public GrpcLibrary {
48 public:
49 ~Credentials() GRPC_OVERRIDE;
50 virtual bool ApplyToCall(grpc_call* call) = 0;
51
52 protected:
53 friend std::shared_ptr<Credentials> CompositeCredentials(
54 const std::shared_ptr<Credentials>& creds1,
55 const std::shared_ptr<Credentials>& creds2);
56
57 virtual SecureCredentials* AsSecureCredentials() = 0;
58
59 private:
60 friend std::shared_ptr<ChannelInterface> CreateChannel(
61 const grpc::string& target, const std::shared_ptr<Credentials>& creds,
62 const ChannelArguments& args);
63
64 virtual std::shared_ptr<ChannelInterface> CreateChannel(
65 const grpc::string& target, const ChannelArguments& args) = 0;
66 };
67
68 // Options used to build SslCredentials
69 // pem_roots_cert is the buffer containing the PEM encoding of the server root
70 // certificates. If this parameter is empty, the default roots will be used.
71 // pem_private_key is the buffer containing the PEM encoding of the client's
72 // private key. This parameter can be empty if the client does not have a
73 // private key.
74 // pem_cert_chain is the buffer containing the PEM encoding of the client's
75 // certificate chain. This parameter can be empty if the client does not have
76 // a certificate chain.
77 struct SslCredentialsOptions {
78 grpc::string pem_root_certs;
79 grpc::string pem_private_key;
80 grpc::string pem_cert_chain;
81 };
82
83 // Factories for building different types of Credentials
84 // The functions may return empty shared_ptr when credentials cannot be created.
85 // If a Credentials pointer is returned, it can still be invalid when used to
86 // create a channel. A lame channel will be created then and all rpcs will
87 // fail on it.
88
89 // Builds credentials with reasonable defaults.
90 std::shared_ptr<Credentials> GoogleDefaultCredentials();
91
92 // Builds SSL Credentials given SSL specific options
93 std::shared_ptr<Credentials> SslCredentials(
94 const SslCredentialsOptions& options);
95
96 // Builds credentials for use when running in GCE
97 std::shared_ptr<Credentials> ComputeEngineCredentials();
98
99 // Builds service account credentials.
100 // json_key is the JSON key string containing the client's private key.
101 // scope is a space-delimited list of the requested permissions.
102 // token_lifetime_seconds is the lifetime in seconds of each token acquired
103 // through this service account credentials. It should be positive and should
104 // not exceed grpc_max_auth_token_lifetime or will be cropped to this value.
105 std::shared_ptr<Credentials> ServiceAccountCredentials(
106 const grpc::string& json_key, const grpc::string& scope,
107 long token_lifetime_seconds);
108
109 // Builds Service Account JWT Access credentials.
110 // json_key is the JSON key string containing the client's private key.
111 // token_lifetime_seconds is the lifetime in seconds of each Json Web Token
112 // (JWT) created with this credentials. It should not exceed
113 // grpc_max_auth_token_lifetime or will be cropped to this value.
114 std::shared_ptr<Credentials> ServiceAccountJWTAccessCredentials(
115 const grpc::string& json_key, long token_lifetime_seconds);
116
117 // Builds refresh token credentials.
118 // json_refresh_token is the JSON string containing the refresh token along
119 // with a client_id and client_secret.
120 std::shared_ptr<Credentials> RefreshTokenCredentials(
121 const grpc::string& json_refresh_token);
122
123 // Builds access token credentials.
124 // access_token is an oauth2 access token that was fetched using an out of band
125 // mechanism.
126 std::shared_ptr<Credentials> AccessTokenCredentials(
127 const grpc::string& access_token);
128
129 // Builds IAM credentials.
130 std::shared_ptr<Credentials> IAMCredentials(
131 const grpc::string& authorization_token,
132 const grpc::string& authority_selector);
133
134 // Combines two credentials objects into a composite credentials
135 std::shared_ptr<Credentials> CompositeCredentials(
136 const std::shared_ptr<Credentials>& creds1,
137 const std::shared_ptr<Credentials>& creds2);
138
139 // Credentials for an unencrypted, unauthenticated channel
140 std::shared_ptr<Credentials> InsecureCredentials();
141
142 } // namespace grpc
143
144 #endif // GRPCXX_CREDENTIALS_H
grpc::CompositeCredentials
std::shared_ptr< Credentials > CompositeCredentials(const std::shared_ptr< Credentials > &creds1, const std::shared_ptr< Credentials > &creds2)
Definition: secure_credentials.cc:137
grpc::string
std::string string
Definition: config.h:112
grpc::AccessTokenCredentials
std::shared_ptr< Credentials > AccessTokenCredentials(const grpc::string &access_token)
Definition: secure_credentials.cc:122
grpc::ChannelArguments
Definition: channel_arguments.h:52
grpc_library.h
config.h
grpc::Credentials::~Credentials
~Credentials() GRPC_OVERRIDE
Definition: credentials.cc:38
grpc::Credentials::ApplyToCall
virtual bool ApplyToCall(grpc_call *call)=0
grpc::InsecureCredentials
std::shared_ptr< Credentials > InsecureCredentials()
Definition: insecure_credentials.cc:62
grpc::ServiceAccountJWTAccessCredentials
std::shared_ptr< Credentials > ServiceAccountJWTAccessCredentials(const grpc::string &json_key, long token_lifetime_seconds)
Definition: secure_credentials.cc:101
grpc::SslCredentialsOptions::pem_root_certs
grpc::string pem_root_certs
Definition: credentials.h:78
grpc::SslCredentialsOptions
Definition: credentials.h:77
grpc::GrpcLibrary
Definition: grpc_library.h:41
grpc::Credentials::AsSecureCredentials
virtual SecureCredentials * AsSecureCredentials()=0
grpc::SslCredentialsOptions::pem_cert_chain
grpc::string pem_cert_chain
Definition: credentials.h:80
grpc::Credentials
Definition: credentials.h:47
grpc::SslCredentialsOptions::pem_private_key
grpc::string pem_private_key
Definition: credentials.h:79
grpc::Credentials::CreateChannel
friend std::shared_ptr< ChannelInterface > CreateChannel(const grpc::string &target, const std::shared_ptr< Credentials > &creds, const ChannelArguments &args)
Definition: create_channel.cc:45
grpc::ComputeEngineCredentials
std::shared_ptr< Credentials > ComputeEngineCredentials()
Definition: secure_credentials.cc:80
grpc::ServiceAccountCredentials
std::shared_ptr< Credentials > ServiceAccountCredentials(const grpc::string &json_key, const grpc::string &scope, long token_lifetime_seconds)
Definition: secure_credentials.cc:85
grpc::RefreshTokenCredentials
std::shared_ptr< Credentials > RefreshTokenCredentials(const grpc::string &json_refresh_token)
Definition: secure_credentials.cc:115
grpc::Credentials::CompositeCredentials
friend std::shared_ptr< Credentials > CompositeCredentials(const std::shared_ptr< Credentials > &creds1, const std::shared_ptr< Credentials > &creds2)
Definition: secure_credentials.cc:137
grpc::SslCredentials
std::shared_ptr< Credentials > SslCredentials(const SslCredentialsOptions &options)
Definition: secure_credentials.cc:68
grpc::GoogleDefaultCredentials
std::shared_ptr< Credentials > GoogleDefaultCredentials()
Definition: secure_credentials.cc:63
GRPC_OVERRIDE
#define GRPC_OVERRIDE
Definition: config.h:77
grpc::SecureCredentials
Definition: secure_credentials.h:44
grpc::IAMCredentials
std::shared_ptr< Credentials > IAMCredentials(const grpc::string &authorization_token, const grpc::string &authority_selector)
Definition: secure_credentials.cc:129