googleapis / googleapis/google-api-nodejs-client
Switching to HTTP/2 makes calendarList.list() complain about invalid authentication
- Dominant language
- TypeScript
- Stars
- 12.2k
- Forks
- 2k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 24
Description
I have an application that uses an access token to request a list of calendars and then deletes and creates batches of events in a specific calendar.
Everything works, but when I switch on HTTP/2 support:
```js
google.options({
http2: true
})
```
I get this exception when making the `await calendarApi.calendarList.list()` call:
```
Request failed with status code 401.
'{
error: {
code: 401,
message: 'Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.',
errors: [
{
message: 'Invalid Credentials',
domain: 'global',
reason: 'authError',
location: 'Authorization',
locationType: 'header'
}
],
status: 'UNAUTHENTICATED'
}
}
```
Here's my code (using [dotenv](https://github.com/motdotla/dotenv) and extracted from my project as a standalone test case):
```js
#!/usr/bin/env node
import 'dotenv/config'
import { google } from 'googleapis'
// When this is turned on, requesting the calendar list fails
google.options({ http2: true })
const authClient = new google.auth.OAuth2(
process.env.GOOGLE_CLIENT_ID,
process.env.GOOGLE_CLIENT_SECRET,
'http://localhost:2024',
)
authClient.setCredentials({
access_token: process.env.GOOGLE_ACCESS_TOKEN,
refresh_token: process.env.GOOGLE_REFRESH_TOKEN,
})
const calendarApi = google.calendar({
version: 'v3',
auth: authClient,
})
let response
try {
console.log('Requesting list of calendars...')
response = await calendarApi.calendarList.list()
} catch(e) {
console.error(e.message)
process.exit(1)
}
console.log(response.data.items)
```
I'm using googleapis 144.0.0 and I tried multiple older versions and the result is the same.
My motivation for switching to HTTP/2 was hitting the "rate limit exceeded" error while performing too many simultaneous operations.
@jrmdayn's drop-in [batch request add-on](https://github.com/jrmdayn/googleapis-batcher) seems to work perfectly for batching the operations and not hitting the rate limit albeit without using HTTP/2, as per https://github.com/googleapis/google-api-nodejs-client/issues/2375#issuecomment-1377330182.
However, I'm still interested in switching to HTTP/2 for its performance benefits and due to it being the new standard.
@JustinBeckwith, I see that you've done a lot of work on the HTTP/2 implementation (#1130). I don't know if you can tell right away what is going on here.
Contributor guide
Assessment
This issue has not been assessed yet.