
Security News
Software Engineering Daily Podcast: Feross on AI, Open Source, and Supply Chain Risk
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.
@codefresh-io/google-auto-auth
Advanced tools
Making it as easy as possible to authenticate a Google API request
Making it as easy as possible to authenticate a Google API request
$ npm install --save google-auto-auth
var googleAuth = require('google-auto-auth');
// Create a client
var auth = googleAuth();
auth.authorizeRequest({
method: 'get',
uri: 'https://www.googleapis.com/something'
}, function (err, authorizedReqOpts) {
/*
authorizedReqOpts = {
method: 'get',
uri: 'https://www.googleapis.com/something',
headers: {
Authorization: 'Bearer {{token}}'
}
}
*/
});
Or, just get an access token.
auth.getToken(function (err, token) {
/*
token = 'access token'
*/
});
gcloud sdkGOOGLE_APPLICATION_CREDENTIALSIf you do not meet those, you must provide a keyFilename or credentials object.
var googleAuth = require('google-auto-auth');
var authConfig = {};
// path to a key:
authConfig.keyFilename = '/path/to/keyfile.json';
// or a credentials object:
authConfig.credentials = {
client_email: '...',
private_key: '...'
};
// Create a client
var auth = googleAuth(authConfig);
auth.authorizeRequest({/*...*/}, function (err, authorizedReqOpts) {});
auth.getToken(function (err, token) {});
ObjectSee the above section on Authentication. This object is necessary if automatic authentication is not available in your environment.
At a glance, the supported properties for this method are:
credentials - Object containing client_email and private_key propertieskeyFilename - Path to a .json, .pem, or .p12 key fileprojectId - Your project IDscopes - Required scopes for the desired API requesttoken - An access token. If provided, we'll use this instead of fetching a new oneExtend an HTTP request object with an authorized header.
ErrorAn API error or an error if scopes are required for the request you're trying to make (check for err.code = MISSING_SCOPE). If you receive the missing scope error, provide the authConfig.scopes array with the necessary scope URLs for your request. There are examples of scopes that are required for some of the Google Cloud Platform services in the gcloud-node Authentication Guide.
ObjectThe reqOpts object provided has been extended with a valid access token attached to the headers.Authorization value. E.g.: headers.Authorization = 'Bearer y.2343...'.
Get the auth client instance from google-auth-library.
ErrorAn error that occurred while trying to get an authorization client.
google-auth-libraryThe client instance from google-auth-library. This is the underlying object this library uses.
Get the client_email and private_key properties from an authorized client.
ErrorAn error that occurred while trying to get an authorization client.
ObjectAn object containing client_email and private_key.
Determine if the environment the app is running in is a Google Compute Engine instance.
NullWe won't return an error, but it's here for convention-sake.
Object{
IS_APP_ENGINE: Boolean,
IS_CLOUD_FUNCTION: Boolean,
IS_COMPUTE_ENGINE: Boolean,
IS_CONTAINER_ENGINE: Boolean
}
If you've already run this function, the object will persist as auth.environment.
Get the project ID if it was auto-detected or parsed from the provided keyfile.
ErrorAn error that occurred while trying to get an authorization client.
stringThe project ID that was parsed from the provided key file or auto-detected from the environment.
Get an access token. The token will always be current. If necessary, background refreshes are handled automatically.
ErrorAn API error or an error if scopes are required for the request you're trying to make (check for err.code = MISSING_SCOPE). If you receive the missing scope error, provide the authConfig.scopes array with the necessary scope URLs for your request.
StringA current access token to be used during an API request. If you provided authConfig.token, this method simply returns the value you passed.
Determine if the environment the app is running in is a Google App Engine instance.
NullWe won't return an error, but it's here for convention-sake.
BooleanWhether the app is in App Engine or not.
Determine if the environment the app is running in is a Google Cloud Function.
NullWe won't return an error, but it's here for convention-sake.
BooleanWhether the app is in a Cloud Function or not.
Determine if the environment the app is running in is a Google Compute Engine instance.
NullWe won't return an error, but it's here for convention-sake.
BooleanWhether the app is in a Compute Engine instance or not.
Determine if the environment the app is running in is a Google Container Engine instance.
NullWe won't return an error, but it's here for convention-sake.
BooleanWhether the app is in a Container Engine instance or not.
FAQs
Making it as easy as possible to authenticate a Google API request
We found that @codefresh-io/google-auto-auth demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 32 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.

Security News
Rust’s crates.io team is advancing an RFC to add a Security tab that surfaces RustSec vulnerability and unsoundness advisories directly on crate pages.