Use code to obtain token. During the process of auth2, the request https://oauth2.googleapis.com/token failed.
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- javascript, nodejs
- 领域
- api, authentication
调研方向
从 OAuth2Client.getToken 调用以及报告的、发送到 https://oauth2.googleapis.com/token 的 POST 开始,然后查看 ECONNRESET 的详细信息和链接的 Google OAuth Web 服务器示例。完成的标准是确定导致令牌交换失败的是客户端库还是请求环境,并记录一种可复现的解决方案。
由索引模型根据 Issue 内容生成。
描述
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
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
googleapis/google-api-nodejs-client 的其他 Issue
-
难度 5/5 一周以上 新手友好度 32/100
googleapis/google-api-nodejs-client#3932 · 1 条评论 ·
维护者通常 1 天内回复
-
[Discovery Engine] streamAnswer is typed as one AnswerQueryResponse, but REST returns frame arrays未关闭
难度 3/5 1-2 天 新手友好度 64/100
googleapis/google-api-nodejs-client#3930 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 76/100
googleapis/google-api-nodejs-client#3927 · 1 个 reaction ·
维护者通常 1 天内回复
-
size: l type: feature request
难度 4/5 3-5 天 新手友好度 35/100
googleapis/google-api-nodejs-client#3926 ·
维护者通常 1 天内回复
-
type: feature request
难度 5/5 一周以上 新手友好度 15/100
googleapis/google-api-nodejs-client#3903 ·
维护者通常 1 天内回复
查看 googleapis/google-api-nodejs-client 的全部 Issue
相似的 Issue
-
难度 1/5 1-3 小时 新手友好度 88/100
supabase/agent-skills#611 ·
-
难度 1/5 1 小时以内 新手友好度 68/100
polka-codes/test#345 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 92/100
GoogleChromeLabs/project-sesame#217 ·
维护者通常 12 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
solana-foundation/solana-com#2202 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100