diff options
author | Tim Emiola <tbetbetbe@users.noreply.github.com> | 2015-05-08 10:49:24 -0700 |
---|---|---|
committer | Tim Emiola <tbetbetbe@users.noreply.github.com> | 2015-05-08 10:49:24 -0700 |
commit | f0b4c58778941a7273ef7aa134ca65957e1b9248 (patch) | |
tree | 28e711e5871b7353c561c56d4248eab767c4f85e /src/node | |
parent | 0db579d183f6820f5b5198ec06d6aec7d219497e (diff) | |
parent | 00943fcd32c4d4ea1e0b036ea3f30d1a1749d988 (diff) |
Merge pull request #1515 from murgatroid99/node_auth_uri_parameter
Updated the getGoogleAuthDelegate function to use credential.getRequestMetadata
Diffstat (limited to 'src/node')
-rw-r--r-- | src/node/index.js | 7 | ||||
-rw-r--r-- | src/node/src/client.js | 19 |
2 files changed, 14 insertions, 12 deletions
diff --git a/src/node/index.js b/src/node/index.js index 875756328d..c09e416c6e 100644 --- a/src/node/index.js +++ b/src/node/index.js @@ -100,22 +100,23 @@ function load(filename, format) { function getGoogleAuthDelegate(credential) { /** * Update a metadata object with authentication information. + * @param {string} authURI The uri to authenticate to * @param {Object} metadata Metadata object * @param {function(Error, Object)} callback */ - return function updateMetadata(metadata, callback) { + return function updateMetadata(authURI, metadata, callback) { metadata = _.clone(metadata); if (metadata.Authorization) { metadata.Authorization = _.clone(metadata.Authorization); } else { metadata.Authorization = []; } - credential.getAccessToken(function(err, token) { + credential.getRequestMetadata(authURI, function(err, header) { if (err) { callback(err); return; } - metadata.Authorization.push('Bearer ' + token); + metadata.Authorization.push(header.Authorization); callback(null, metadata); }); }; diff --git a/src/node/src/client.js b/src/node/src/client.js index 9f3ddf8ed0..707a2d99d8 100644 --- a/src/node/src/client.js +++ b/src/node/src/client.js @@ -485,27 +485,28 @@ var requester_makers = { * requestSerialize: function to serialize request objects * responseDeserialize: function to deserialize response objects * @param {Object} methods An object mapping method names to method attributes + * @param {string} serviceName The name of the service * @return {function(string, Object)} New client constructor */ -function makeClientConstructor(methods) { +function makeClientConstructor(methods, serviceName) { /** * Create a client with the given methods * @constructor * @param {string} address The address of the server to connect to * @param {Object} options Options to pass to the underlying channel - * @param {function(Object, function)=} updateMetadata function to update the - * metadata for each request + * @param {function(string, Object, function)=} updateMetadata function to + * update the metadata for each request */ function Client(address, options, updateMetadata) { - if (updateMetadata) { - this.updateMetadata = updateMetadata; - } else { - this.updateMetadata = function(metadata, callback) { + if (!updateMetadata) { + updateMetadata = function(uri, metadata, callback) { callback(null, metadata); }; } - this.server_address = address; + this.server_address = address.replace(/\/$/, ''); this.channel = new grpc.Channel(address, options); + this.updateMetadata = _.partial(updateMetadata, + this.server_address + '/' + serviceName); } _.each(methods, function(attrs, name) { @@ -541,7 +542,7 @@ function makeClientConstructor(methods) { * @return {function(string, Object)} New client constructor */ function makeProtobufClientConstructor(service) { - var method_attrs = common.getProtobufServiceAttrs(service); + var method_attrs = common.getProtobufServiceAttrs(service, service.name); var Client = makeClientConstructor(method_attrs); Client.service = service; |