
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
google-auto-auth
Advanced tools
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_CREDENTIALS
If you do not meet those, you must provide a keyFile 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) {});
Object
See the above section on Authentication. This object is necessary if automatic authentication is not available in your environment.
Everything from the gcloud-node Authentication Guide applies here.
At a glance, the supported properties for this method are:
keyFilename
- Path to a .json, .pem, or .p12 key filecredentials
- Object containing client_email
and private_key
propertiesscopes
- Required scopes for the desired API requestFor more details, see the Authentication Guide linked above, under "The config object".
Extend an HTTP request object with an authorized header.
Error
An 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.
Object
The 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.
Error
An error that occurred while trying to get an authorization client.
google-auth-library
The 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.
Error
An error that occurred while trying to get an authorization client.
Object
An object containing client_email
and private_key
.
Get the project ID if it was auto-detected or parsed from the provided keyfile.
Error
An error that occurred while trying to get an authorization client.
string
The project ID that was parsed from the provided keyfile or auto-detected from the environment.
Get an access token. The token will always be current. If necessary, background refreshes are handled automatically.
Error
An 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.
String
A current access token to be used during an API request.
FAQs
Making it as easy as possible to authenticate a Google API request
The npm package google-auto-auth receives a total of 128,066 weekly downloads. As such, google-auto-auth popularity was classified as popular.
We found that google-auto-auth demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 12 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.