googleapis / googleapis/google-api-nodejs-client

Switching to HTTP/2 makes calendarList.list() complain about invalid authentication

Offen
#3,592 3 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
TypeScript
Sterne
12.2k
Forks
2k
Ø Merge
1 T. 9 Std.
Gemergte PRs (30 T.)
24

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Start by running the standalone OAuth2 reproduction with google.options({ http2: true }) and calendarApi.calendarList.list(), then inspect the HTTP/2 request path used by the Node.js client for Authorization handling. Compare it with the non-HTTP/2 path; done means authenticated calendar-list requests no longer return 401 when HTTP/2 is enabled.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, nodejs
Bereich
api, authentication, networking
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.