Skip to content

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

Open
@specious

Description

@specious

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:

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 and extracted from my project as a standalone test case):

#!/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 seems to work perfectly for batching the operations and not hitting the rate limit albeit without using HTTP/2, as per #2375 (comment).

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions