Updated the getGoogleAuthDelegate function to use credential.getRequestMetadata

pull/1515/head
murgatroid99 10 years ago
parent e82f8266cf
commit 00943fcd32
  1. 7
      src/node/index.js
  2. 19
      src/node/src/client.js

@ -100,22 +100,23 @@ function load(filename, format) {
function getGoogleAuthDelegate(credential) { function getGoogleAuthDelegate(credential) {
/** /**
* Update a metadata object with authentication information. * Update a metadata object with authentication information.
* @param {string} authURI The uri to authenticate to
* @param {Object} metadata Metadata object * @param {Object} metadata Metadata object
* @param {function(Error, Object)} callback * @param {function(Error, Object)} callback
*/ */
return function updateMetadata(metadata, callback) { return function updateMetadata(authURI, metadata, callback) {
metadata = _.clone(metadata); metadata = _.clone(metadata);
if (metadata.Authorization) { if (metadata.Authorization) {
metadata.Authorization = _.clone(metadata.Authorization); metadata.Authorization = _.clone(metadata.Authorization);
} else { } else {
metadata.Authorization = []; metadata.Authorization = [];
} }
credential.getAccessToken(function(err, token) { credential.getRequestMetadata(authURI, function(err, header) {
if (err) { if (err) {
callback(err); callback(err);
return; return;
} }
metadata.Authorization.push('Bearer ' + token); metadata.Authorization.push(header.Authorization);
callback(null, metadata); callback(null, metadata);
}); });
}; };

@ -469,27 +469,28 @@ var requester_makers = {
* requestSerialize: function to serialize request objects * requestSerialize: function to serialize request objects
* responseDeserialize: function to deserialize response objects * responseDeserialize: function to deserialize response objects
* @param {Object} methods An object mapping method names to method attributes * @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 * @return {function(string, Object)} New client constructor
*/ */
function makeClientConstructor(methods) { function makeClientConstructor(methods, serviceName) {
/** /**
* Create a client with the given methods * Create a client with the given methods
* @constructor * @constructor
* @param {string} address The address of the server to connect to * @param {string} address The address of the server to connect to
* @param {Object} options Options to pass to the underlying channel * @param {Object} options Options to pass to the underlying channel
* @param {function(Object, function)=} updateMetadata function to update the * @param {function(string, Object, function)=} updateMetadata function to
* metadata for each request * update the metadata for each request
*/ */
function Client(address, options, updateMetadata) { function Client(address, options, updateMetadata) {
if (updateMetadata) { if (!updateMetadata) {
this.updateMetadata = updateMetadata; updateMetadata = function(uri, metadata, callback) {
} else {
this.updateMetadata = function(metadata, callback) {
callback(null, metadata); callback(null, metadata);
}; };
} }
this.server_address = address; this.server_address = address.replace(/\/$/, '');
this.channel = new grpc.Channel(address, options); this.channel = new grpc.Channel(address, options);
this.updateMetadata = _.partial(updateMetadata,
this.server_address + '/' + serviceName);
} }
_.each(methods, function(attrs, name) { _.each(methods, function(attrs, name) {
@ -525,7 +526,7 @@ function makeClientConstructor(methods) {
* @return {function(string, Object)} New client constructor * @return {function(string, Object)} New client constructor
*/ */
function makeProtobufClientConstructor(service) { function makeProtobufClientConstructor(service) {
var method_attrs = common.getProtobufServiceAttrs(service); var method_attrs = common.getProtobufServiceAttrs(service, service.name);
var Client = makeClientConstructor(method_attrs); var Client = makeClientConstructor(method_attrs);
Client.service = service; Client.service = service;

Loading…
Cancel
Save