3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #ifndef GRPC_NODE_CALL_CREDENTIALS_H_
20 #define GRPC_NODE_CALL_CREDENTIALS_H_
27 #include "grpc/grpc_security.h"
32 class CallCredentials : public Nan::ObjectWrap {
34 static void Init(v8::Local<v8::Object> exports);
35 static bool HasInstance(v8::Local<v8::Value> val);
36 /* Wrap a grpc_call_credentials struct in a javascript object */
37 static v8::Local<v8::Value> WrapStruct(grpc_call_credentials *credentials);
39 /* Returns the grpc_call_credentials struct that this object wraps */
40 grpc_call_credentials *GetWrappedCredentials();
43 explicit CallCredentials(grpc_call_credentials *credentials);
47 CallCredentials(const CallCredentials &);
48 CallCredentials &operator=(const CallCredentials &);
50 static NAN_METHOD(New);
51 static NAN_METHOD(CreateSsl);
52 static NAN_METHOD(CreateFromPlugin);
54 static NAN_METHOD(Compose);
55 static Nan::Callback *constructor;
56 // Used for typechecking instances of this javascript class
57 static Nan::Persistent<v8::FunctionTemplate> fun_tpl;
59 grpc_call_credentials *wrapped_credentials;
62 /* Auth metadata plugin functionality */
64 typedef struct plugin_callback_data {
65 plugin_callback_data(const char *service_url_,
66 grpc_credentials_plugin_metadata_cb cb_,
68 : service_url(service_url_),
70 user_data(user_data_),
71 async_resource(NULL) {
72 Nan::HandleScope scope;
73 async_resource = new Nan::AsyncResource("grpc:plugin_callback_data");
75 ~plugin_callback_data() {
76 delete async_resource;
79 const char *service_url;
80 grpc_credentials_plugin_metadata_cb cb;
82 Nan::AsyncResource *async_resource;
83 } plugin_callback_data;
85 typedef struct plugin_state {
86 Nan::Callback *callback;
87 std::queue<plugin_callback_data *> *pending_callbacks;
88 uv_mutex_t plugin_mutex;
90 uv_async_t plugin_async;
93 int plugin_get_metadata(
94 void *state, grpc_auth_metadata_context context,
95 grpc_credentials_plugin_metadata_cb cb,
97 grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX],
98 size_t *num_creds_md, grpc_status_code *status,
99 const char **error_details);
101 void plugin_destroy_state(void *state);
103 NAN_METHOD(PluginCallback);
105 NAUV_WORK_CB(SendPluginCallback);
110 #endif // GRPC_NODE_CALL_CREDENTIALS_H_