You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auth.prototype.getAuthClient=function(callback){varself=this;varconfig=self.config;if(this.authClient){setImmediate(function(){callback(null,self.authClient);});return;}vargoogleAuth=newGoogleAuth();varkeyFile=config.keyFilename||config.keyFile;if(config.credentials||path.extname(keyFile)==='.json'){googleAuth.fromJSON(config.credentials||require(keyFile),addScope);}elseif(keyFile){varauthClient=newgoogleAuth.JWT();authClient.keyFile=keyFile;authClient.email=config.email;addScope(null,authClient);}else{googleAuth.getApplicationDefault(addScope);}functionaddScope(err,authClient,projectId){if(err){callback(err);return;}if(authClient.createScopedRequired()){if(!config.scopes){varscopeError=newError('Scopes are required for this request.');scopeError.code='MISSING_SCOPE';callback(scopeError);return;}authClient.scopes=config.scopes;}self.authClient=authClient;self.projectId=projectId||authClient.projectId;callback(null,authClient);}};
var assign = require('object-assign');
var GoogleAuth = require('google-auth-library');
+var path = require('path');
function Auth(config) {
if (!(this instanceof Auth)) {
@@ -40,15 +41,15 @@ Auth.prototype.getAuthClient = function (callback) {
}
var googleAuth = new GoogleAuth();
+ var keyFile = config.keyFilename || config.keyFile;- if (config.keyFilename || config.keyFile) {+ if (config.credentials || path.extname(keyFile) === '.json') {+ googleAuth.fromJSON(config.credentials || require(keyFile), addScope);+ } else if (keyFile) {
var authClient = new googleAuth.JWT();
- authClient.keyFile = config.keyFilename || config.keyFile;+ authClient.keyFile = keyFile;
authClient.email = config.email;
- authClient.scopes = config.scopes;
addScope(null, authClient);
- } else if (config.credentials) {- googleAuth.fromJSON(config.credentials, addScope);
} else {
googleAuth.getApplicationDefault(addScope);
}
@@ -59,7 +60,7 @@ Auth.prototype.getAuthClient = function (callback) {
return;
}
- if (authClient.createScopedRequired && authClient.createScopedRequired()) {+ if (authClient.createScopedRequired()) {
if (!config.scopes) {
var scopeError = new Error('Scopes are required for this request.');
scopeError.code = 'MISSING_SCOPE';
@@ -67,11 +68,11 @@ Auth.prototype.getAuthClient = function (callback) {
return;
}
- authClient = authClient.createScoped(config.scopes);
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: