Skip to content

Releases: googleapis/google-auth-library-nodejs

1.4.0

06 Apr 19:55
11a0896
Compare
Choose a tag to compare

It's that special time again! Bug fixes, new features, updated packages, this release has it all.

New features

2570751 feat: emit an event when new tokens are obtained (#341)
3b057e7 feat: add auth.request method (#346)
200de99 feat: export additional types (#345)
e835c05 feat: allow passing options to auth.getClient (#344)
f1ad9da feat: add getTokenInfo method (#337)
df75b73 feat: add JWT.getCredentials method (#323)

Bug fixes

f75f2a2 fix: pin axios to nodejs (#342)
4807764 fix: cache refreshToken promises (#339)
c30f822 fix: use id_token for IAP requests (#328)
5d5a1e7 fix: don't duplicate user-agent (#322)

Keepin' the lights on

375faea test: add missing scope checks (#343)
93ad6d5 chore(package): update @types/mocha to version 5.0.0 (#333)
a39267e chore(package): update sinon to version 5.0.0 (#332)
6589956 chore: setup nightly builds workflow (#329)

Enjoy that fresh hot auth y'all 🚀🐢

1.3.2

14 Mar 04:23
9fc4c80
Compare
Choose a tag to compare

This release contains minor test improvements and bug fixes. Enjoy!

b41381d fix: ensure GCF can read metadata requests (#324)
48f962c chore: update deps (#317)
879864a chore(package): update js-green-licenses to version 0.5.0 (#314)
13a6761 fix: increase test timeout (#316)
e43c73e chore: improve tests (#308)
7f7666f chore: fix typo in comment (#304)
1848552 chore: use sinon to mock in some cases (#303)
faf494a test: flatten tests (#301)
34bb07f docs: add newline in readme
a0169e7 docs: add instructions for oauth2 and installed apps (#300)

1.3.1

20 Feb 19:52
0ea5ee0
Compare
Choose a tag to compare

This releases fixes #295.

1.3.0

20 Feb 18:30
7b85668
Compare
Choose a tag to compare

This release has it all. Bug fixes, new features, and improved test coverage! Here are some highlights.

Easy mode

This release includes a bunch of the features available in google-auto-auth. This makes it really easy to get started with service credentials. You can easily grab and use application default credentials:

const { auth } = require('google-auth-library');
async function main() {
  const client = await auth.getClient();
  const projectId = await auth.getDefaultProjectId();
  const url = `https://www.googleapis.com/dns/v1/projects/${projectId}`;
  const res = await client.request({ url });
  console.log(res.data);
}
main().catch(console.error);

Or easily use the client to authorize a request:

const { auth } = require('google-auth-library');
const axios = require('axios');
async function main() {
  const client = await auth.getClient();
  const projectId = await auth.getDefaultProjectId();
  const url = `https://www.googleapis.com/dns/v1/projects/${projectId}`;
  const opts = await auth.authorizeRequest();
  const res = await axios.get(url, opts);
  console.log(res.data);
}
main().catch(console.error);

Commits in this release

64a1bd0 feat: add auto auth features (#281)
4d0c49d chore(package): update gcp-metadata to version 0.6.0 (#288)
60c5a1e chore: upgrade to TypeScript 2.7 (#289)
80c439a chore: upgrade all the things (#292)
5699b90 fix: cache GCE credentials (#286)
12feb2c test: improve coverage (#287)
7a951e0 fix: retry connections to gce metadata server (#284)
78d6813 fix: do not retry if a post with readable stream (#279)
3c9efe5 chore: use gcp-metadata (#278)

1.2.1

02 Feb 06:21
a21d244
Compare
Choose a tag to compare

This reverts #269, which broke the auth client for Google Cloud Function users.

1.2.0

30 Jan 22:51
5ab6be3
Compare
Choose a tag to compare

New Features

0803242 feat: add IAP and additional claims support (#268)
7d89b2c feat: add example of puppeteer (#265)
a570126 feat: Add given_name and family_name to TokenPayload interface (#260)

Bug Fixes

730d4b7 fix: Update GCE metadata token endpoint (#269)
17a56a6 fix: update links in readme (#262)

1.1.0

20 Jan 06:12
3d9e26a
Compare
Choose a tag to compare

This release includes a few new features, and a few bug fixes.

New Features

f9950b0 feat: cache JWT tokens in JWTAccess (#254)
7e9a390 feat: Add ability to refresh token automatically before expiration. (#242)
014ce0b feat: export static GoogleAuth (#249)

Fixes

c3ce4f1 fix: Fix samples/jwt.js link in README (#253)
64fb34d fix: update usage of OAuth2Client.verifyIdToken in example (#243)
771bc6c fix: use npm link to run samples (#245)

1.0.0

09 Jan 19:12
Compare
Choose a tag to compare

TL;DR - This release includes a variety of bug fixes, new features, and breaking changes. Please take care.

New Features

TypeScript support

This library now includes a d.ts file by default - no @types package needed.

Promise & Async/Await style APIs

Previous versions of the API were callback only. For every API that was callback based, there is also a Promise or Async/Await style variant. For example:

/**
 * You can use an errback style API
 **/
auth.getApplicationDefault(function(err, client) {
  if (err) {
    console.log('Authentication failed because of ', err);
    return;
  }
  // make request...
});

/**
 * Or if you're using Babel, TypeScript, or Node.js 8+ you can use async/await
 **/
try {
  const client = await auth.getApplicationDefault();
  // make request...
} catch (err) {
  console.log('Authentication failed because of ', err);
}

/**
 * Or, you can just use promises
 **/
auth.getApplicationDefault()
  .then(client => {
    // make request
  })
  .catch(err => {
    console.log('Authentication failed because of ', err);
  });

Ability to set maxExpiry when verifying tokens

The OAuth2Client.verifyIdToken method now accepts an optional maxExpiry field:

const result = await client.verifyIdToken({
  idToken: <id Token>, 
  audience: <audience>, 
  maxExpiry: <max expiry>
});

Support for code_verifier and code_challenge with OAuth2

The OAuth2Client.generateAuthUrl method has been extended to support the code_challenge_method and code_challenge fields. There is also a convenience method to generate a verifier:

// Generate a code_verifier and code_challenge
const codes = oAuth2Client.generateCodeVerifier();

// Generate the url that will be used for the consent dialog.
const authorizeUrl = oAuth2Client.generateAuthUrl({
  access_type: 'offline',
  scope: 'https://www.googleapis.com/auth/plus.me',
  code_challenge_method: 'S256',
  code_challenge: codes.codeChallenge
});

Breaking changes

There have been multiple API breaking changes with this release. Please test your code accordingly after upgrading.

Default exports

The exports on the google-auth-library have changed. The default export of the library was previously a reference to the GoogleAuth type, which was instantiated as a starting point for all consumers. Now, the module has no default export, but exports several other types common used.

// OLD CODE
var GoogleAuth = require('google-auth-library');
var auth = new GoogleAuth();
var jwtClient = new auth.JWT();
var oAuth2Client = new auth.OAuth2();
...

// NEW CODE
const gal = require('google-auth-library');
const auth = new gal.GoogleAuth();
const jwtClient = new gal.JWT();
const oAuth2Client = new gal.OAuth2Client();
...
// if you're using Node 6+, you might find this convenient:
const {GoogleAuth, JWT, OAuth2Client} = require('google-auth-library');

If you're using es6 imports via TypeScript or Babel, you can use es6 style as well:

import {GoogleAuth, OAuth2Client} from 'google-auth-library';
const auth = new GoogleAuth();
...

Synchronous methods

Several public methods were switched from asynchronous to synchronous APIs. In all cases, the APIs were not doing anything asynchronous - they were just providing errors in callback form. This has been changed.

// OLD CODE
var auth = new GoogleAuth();
auth.fromJSON(input, function (err, client) {
  if (err) {
    console.error('Error acquiring client: ' + err);
  }
  // make request with client ...
});

// NEW CODE
const auth = new GoogleAuth();
const client = auth.fromJSON(input);
// make request with client ...

This change was made with the following methods:

  • GoogleAuth.fromJSON
  • GoogleAuth.fromAPIKey
  • JWTAccess. getRequestMetadata
  • JWTAccess.fromJSON
  • JWTClient.fromJSON
  • JWTClient.fromAPIKey
  • UserRefreshClient.fromJSON

Request -> Axios

The underlying transport used for HTTP requests was changed from request to axios. This will result in a number of breaking changes.

Any calls to the client.request(opts) method will both accept different parameters, and have different return types. For the options passed to these methods, they are changing from a request options object to an axios request options object.

In addition to the properties on the opts object changing, the signature of the callback is changing as well. The previous version of the library would return objects with a callback that reversed request's default order: function (err, body, response). The signature of that callback has simply been changed to function (err, response), where the body of the response is available by looking at response.data.

// OLD CODE
oAuth2Client.request({
  uri: 'https://www.googleapis.com/plus/v1/people?query=pizza'
}, function (err, body, res) {
  console.log('The body of the response was ' + body);
});

// NEW CODE (using callbacks)
oAuth2Client.request({
  // note that we're using `url` instead of `uri` here, per the Axios request config. 
  url: 'https://www.googleapis.com/plus/v1/people?query=pizza'
}, function (err, res) {
  // The body isn't returned as part of the callback, and is available from `res.data`
  console.log(`The body of the response was ${res.data}`);
});

// NEW CODE (using async/await)
const res = await oAuth2Client.request({
  url:  'https://www.googleapis.com/plus/v1/people?query=pizza'
});
console.log(`The body of the response was ${res.data}`);

In addition to these changes - the request and axios libraries handle errors differently. request treats any completed request, even if it returns a non 2xx response code, as a success. The err parameter will be null or undefined. axios treats any non 2xx response as an error. Code which may have previous not worked, but also not thrown errors - may now start throwing errors.

Parameter change for verifyIdToken

The parameters to the verifyIdToken method of OAuth2Client have been changed. The function now accepts a single options object, and an optional callback. A function that used to look like this:

oAuth2Client.verifyIdToken(idToken, audience, callback);

Would now be rewritten as this:

oAuth2Client.verifyIdToken({
  idToken: idToken,
  audience: audience
}, callback);

1.0.0-alpha.1

06 Dec 18:08
a5b107d
Compare
Choose a tag to compare
1.0.0-alpha.1 Pre-release
Pre-release

TL;DR - This release includes a variety of bug fixes, new features, and breaking changes. Please take care.

New Features

TypeScript support

This library now includes a d.ts file by default - no @types package needed.

Promise & Async/Await style APIs

Previous versions of the API were callback only. For every API that was callback based, there is also a Promise or Async/Await style variant. For example:

/**
 * You can use an errback style API
 **/
auth.getApplicationDefault(function(err, client) {
  if (err) {
    console.log('Authentication failed because of ', err);
    return;
  }
  // make request...
});

/**
 * Or if you're using Babel, TypeScript, or Node.js 8+ you can use async/await
 **/
try {
  const client = await auth.getApplicationDefault();
  // make request...
} catch (err) {
  console.log('Authentication failed because of ', err);
}

/**
 * Or, you can just use promises
 **/
auth.getApplicationDefault()
  .then(client => {
    // make request
  })
  .catch(err => {
    console.log('Authentication failed because of ', err);
  });

Breaking changes

There have been multiple API breaking changes with this release. Please test your code accordingly after upgrading.

Default exports

The exports on the google-auth-library have changed. The default export of the library was previously a reference to the GoogleAuth type, which was instantiated as a starting point for all consumers. Now, the module has no default export, but exports several other types common used.

// OLD CODE
var GoogleAuth = require('google-auth-library');
var auth = new GoogleAuth();
var jwtClient = new auth.JWT();
var oAuth2Client = new auth.OAuth2();
...

// NEW CODE
const gal = require('google-auth-library');
const auth = new gal.GoogleAuth();
const jwtClient = new gal.JWT();
const oAuth2Client = new gal.OAuth2Client();
...

If you're using es6 imports via TypeScript or Babel, you can use es6 style as well:

import {GoogleAuth, OAuth2Client} from 'google-auth-library';
const auth = new GoogleAuth();
...

Synchronous methods

Several public methods were switched from asynchronous to synchronous APIs. In all cases, the APIs were not doing anything asynchronous - they were just providing errors in callback form. This has been changed.

// OLD CODE
var auth = new GoogleAuth();
auth.fromJSON(input, function (err, client) {
  if (err) {
    console.error('Error acquiring client: ' + err);
  }
  // make request with client ...
});

// NEW CODE
const auth = new GoogleAuth();
const client = auth.fromJSON(input);
// make request with client ...

This change was made with the following methods:

  • GoogleAuth.fromJSON
  • GoogleAuth.fromAPIKey
  • JWTAccess. getRequestMetadata
  • JWTAccess.fromJSON
  • JWTClient.fromJSON
  • JWTClient.fromAPIKey
  • UserRefreshClient.fromJSON

Request -> Axios

The underlying transport used for HTTP requests was changed from request to axios. This will result in a number of breaking changes.

Any calls to the client.request(opts) method will both accept different parameters, and have different return types. For the options passed to these methods, they are changing from a request options object to an axios request options object.

In addition to the properties on the opts object changing, the signature of the callback is changing as well. The previous version of the library would return objects with a callback that reversed request's default order: function (err, body, response). The signature of that callback has simply been changed to function (err, response), where the body of the response is available by looking at response.data.

// OLD CODE
oAuth2Client.request({
  uri: 'https://www.googleapis.com/plus/v1/people?query=pizza'
}, function (err, body, res) {
  console.log('The body of the response was ' + body);
});

// NEW CODE (using callbacks)
oAuth2Client.request({
  // note that we're using `url` instead of `uri` here, per the Axios request config. 
  url: 'https://www.googleapis.com/plus/v1/people?query=pizza'
}, function (err, res) {
  // The body isn't returned as part of the callback, and is available from `res.data`
  console.log(`The body of the response was ${res.data}`);
});

// NEW CODE (using async/await)
const res = await oAuth2Client.request({
  url:  'https://www.googleapis.com/plus/v1/people?query=pizza'
});
console.log(`The body of the response was ${res.data}`);

In addition to these changes - the request and axios libraries handle errors differently. request treats any completed request, even if it returns a non 2xx response code, as a success. The err parameter will be null or undefined. axios treats any non 2xx response as an error. Code which may have previous not worked, but also not thrown errors - may now start throwing errors.

v0.12.0 getCredentials

20 Nov 21:26
Compare
Choose a tag to compare

Adds a new getCredentials method that can be used to retrieve credentials, either from the previously user provided key, or from the metadata service.

Changes