| 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> |
| 34 | GoogleDefaultCredentials() { |
| 35 | return ::grpc_impl::GoogleDefaultCredentials(); |
| 36 | } |
| 37 | |
| 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> |
| 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 grpc::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> |
| 61 | GoogleRefreshTokenCredentials(const grpc::string& json_refresh_token) { |
| 62 | return ::grpc_impl::GoogleRefreshTokenCredentials(json_refresh_token); |
| 63 | } |
| 64 | |
| 65 | static inline std::shared_ptr<grpc_impl::CallCredentials> |
| 66 | AccessTokenCredentials(const grpc::string& access_token) { |
| 67 | return ::grpc_impl::AccessTokenCredentials(access_token); |
| 68 | } |
| 69 | |
| 70 | static inline std::shared_ptr<grpc_impl::CallCredentials> GoogleIAMCredentials( |
| 71 | const grpc::string& authorization_token, |
| 72 | const grpc::string& authority_selector) { |
| 73 | return ::grpc_impl::GoogleIAMCredentials(authorization_token, |
| 74 | authority_selector); |
| 75 | } |
| 76 | |
| 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> |
| 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> |
| 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> |
| 97 | MetadataCredentialsFromPlugin( |
| 98 | std::unique_ptr<MetadataCredentialsPlugin> plugin) { |
| 99 | return ::grpc_impl::MetadataCredentialsFromPlugin(plugin: std::move(plugin)); |
| 100 | } |
| 101 | |
| 102 | namespace experimental { |
| 103 | |
| 104 | typedef ::grpc_impl::experimental::StsCredentialsOptions StsCredentialsOptions; |
| 105 | |
| 106 | static inline grpc::Status StsCredentialsOptionsFromJson( |
| 107 | const grpc::string& json_string, StsCredentialsOptions* options) { |
| 108 | return ::grpc_impl::experimental::StsCredentialsOptionsFromJson(json_string, |
| 109 | options); |
| 110 | } |
| 111 | |
| 112 | static inline grpc::Status StsCredentialsOptionsFromEnv( |
| 113 | StsCredentialsOptions* options) { |
| 114 | return grpc_impl::experimental::StsCredentialsOptionsFromEnv(options); |
| 115 | } |
| 116 | |
| 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 | |
| 125 | static inline std::shared_ptr<grpc_impl::ChannelCredentials> AltsCredentials( |
| 126 | const AltsCredentialsOptions& options) { |
| 127 | return ::grpc_impl::experimental::AltsCredentials(options); |
| 128 | } |
| 129 | |
| 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 | |
| 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 | |