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

Use code to obtain token. During the process of auth2, the request https://oauth2.googleapis.com/token failed.

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

从 OAuth2Client.getToken 调用以及报告的、发送到 https://oauth2.googleapis.com/token 的 POST 开始,然后查看 ECONNRESET 的详细信息和链接的 Google OAuth Web 服务器示例。完成的标准是确定导致令牌交换失败的是客户端库还是请求环境,并记录一种可复现的解决方案。

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

描述

priority: p2 size: m type: bug

I couldn't find the corresponding entry in [support console] and couldn't start, so I'm still here to ask for help.
I use [email protected] in my node project, the code is as follows:

const { google } = require('googleapis');

async getToken() {
const { ctx } = this;
const { code } = ctx.request.body;
const { client_id, client_secret, redirect_uri, } = ctx.app.config.oauth2Google;
const oauth2Client = new google.auth.OAuth2(client_id, client_secret, redirect_uri);
const data = await oauth2Client.getToken(code);
}

Wrong question:

config: {"method":"POST","url":"https://oauth2.googleapis.com/token","data":"< - See errorRedactor option in gaxios for configuration >.","headers":{"Content-Type":"application/x-www-form-urlencoded","User-Agent":"google-api-nodejs-client/9.6.3","x- goog-api-client":"gl-node/20.11.0"},"body":"< - See errorRedactor option in gaxios for configuration>.","responseType":"unknown" }
response: undefined
error: {"message":"request to https://oauth2.googleapis.com/token failed, reason: read ECONNRESET","type":"system","errno":"ECONNRESET","code":" ECONNRESET"}

Here is the official documentation: https://developers.google.com/identity/protocols/oauth2/web-server?hl=zh-cn#exchange-authorization-code

and code:
`const url = require('url');
// Receive the callback from Google's OAuth 2.0 server.
if (req.url.startsWith('/oauth2callback')) {
// Handle the OAuth 2.0 server response
let q = url.parse(req.url, true).query;

// Get access and refresh tokens (if access_type is offline)
let { tokens } = await oauth2Client.getToken(q.code);
oauth2Client.setCredentials(tokens);
}`

Thanks!

主要语言
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 摘要。