google-auth-library
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
base64-js | 1.5.1 | 4.01 kB | MIT | prod | |
ecdsa-sig-formatter | 1.0.11 | 6.94 kB | Apache-2.0 | prod | |
gaxios | 6.5.0 | 103.48 kB | Apache-2.0 | prod | |
gcp-metadata | 6.1.0 | 22.61 kB | Apache-2.0 | prod | |
gtoken | 7.1.0 | 11.57 kB | MIT | prod | |
jws | 4.0.0 | 5.75 kB | MIT | prod |
The Google Auth Library for Node.js is Google's officially supported client library for using OAuth 2.0 authorization and authentication with Google APIs. The purpose of this library is to aid developers in building server-side software that uses Google APIs. It simplifies the authentication process, manages tokens, and handles various types of authentication including Application Default Credentials, OAuth 2, JSON Web Tokens, and Google Compute among others.
To use the google-auth-library, you first need to install the client library using npm via the command npm install google-auth-library
. After this, you can authenticate using the desired method. For instance, with Application Default Credentials (ADC), the library auto-detects the environment and retrieves appropriate credentials. Here's an example of choosing the correct credential type automatically:
const {GoogleAuth} = require('google-auth-library');
async function main() {
const auth = new GoogleAuth({
scopes: 'https://www.googleapis.com/auth/cloud-platform'
});
const client = await auth.getClient();
const projectId = await auth.getProjectId();
const url = `https://dns.googleapis.com/dns/v1/projects/${projectId}`;
const res = await client.request({ url });
console.log(res.data);
}
main().catch(console.error);
The library also supports other authentication methodologies like OAuth2, JWT, Workload Identity Federation, Impersonated Credentials Client, and more.
The documentation for the Google Auth Library for Node.js can be found at various places. The Node.js Client API Reference can be found here. More information about the library and its usage with tutorials and sample code can be found on the Google Auth Library Github repository. You can also explore the client libraries explained page on Google Cloud for further understanding.