Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#3,592 3 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
javascript, nodejs

调研方向

首先使用 google.options({ http2: true }) 和 calendarApi.calendarList.list() 运行独立的 OAuth2 复现,然后检查 Node.js 客户端用于处理 Authorization 的 HTTP/2 请求路径。将其与非 HTTP/2 路径进行比较;完成的标准是启用 HTTP/2 时,经过身份验证的 calendar-list 请求不再返回 401。

由索引模型根据 Issue 内容生成。

描述

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 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.

主要语言
TypeScript
星标
12.3k
派生
2k
平均合并
1 天 19 小时
30 天内合并 PR
21

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

googleapis/google-api-nodejs-client 的其他 Issue

查看 googleapis/google-api-nodejs-client 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。