简体   繁体   English

在 nodejs 中调用 getToken 时 Google OAuth2 客户端超时

[英]Google OAuth2 client timeout when calling getToken in nodejs

I was using Google API to do oauth2.我正在使用 Google API 来做 oauth2。 The app key Id and secret have been set up, and the URL was created successfully using oauth2Client.generateAuthUrl .已设置应用密钥 ID 和密钥,并且使用oauth2Client.generateAuthUrl成功创建了 URL。

    let {google} = require('googleapis'),
    contacts = google.people('v1'),
    oauth2Client = new google.auth.OAuth2(
      "MY_KEY",
      "MY_SECRET",
      "http://localhost:8886/mbl/User/ImportContact"
    ),
    scopes = [
        'https://www.googleapis.com/auth/contacts.readonly',
      'https://www.googleapis.com/auth/plus.me',
      'https://www.googleapis.com/auth/calendar'
    ],
    url = oauth2Client.generateAuthUrl({
      access_type: 'online',
      scope: scopes
    });

In the URL, I authorized the access, and then was redirected to the designated oauthcallback method.在 URL 中,我授权了访问,然后被重定向到指定的 oauthcallback 方法。 The code was in format of代码格式为

4/AADYYeZzY38aKLr1g11IBN2d_9keAdtN2JhDU1WH5pHAPi_0ECfRVS4a-oDiCE5IHPiB3SnyJ4p59ZEFOOSEDFQ# 4/AADYYeZzY38aKLr1g11IBN2d_9keAdtN2JhDU1WH5pHAPi_0ECfRVS4a-oDiCE5IHPiB3SnyJ4p59ZEFOOSEDFQ#

which looks right.看起来不错。

However, the code execution got stuck at the oauth2Client.getToken .但是,代码执行卡在oauth2Client.getToken It never gets past the following line它永远不会超过以下行

const {tokens} = await oauth2Client.getToken(code)

After a while, it gives me timeout error:过了一会儿,它给了我超时错误:

Error: connect ETIMEDOUT 216.58.199.10:443错误:连接 ETIMEDOUT 216.58.199.10:443

Could someone kindly help me with it?有人可以帮助我吗? I have been struggling with it all day.我一整天都在为此苦苦挣扎。

oAuth2Client.getToken probably returns the desired token in a callback from where you can capture it. oAuth2Client.getToken 可能会在回调中返回所需的令牌,您可以从中捕获它。 You may wish to promisify it before you use async - await with it.您可能希望在使用 async 之前承诺它 - 等待它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 google-api-nodejs-client /如何解码从oauth2Client.getToken收到的id_token - google-api-nodejs-client / How to decode the id_token received from oauth2Client.getToken 用Q.ninvoke()调用时,Google的oauth2client.getToken()错误返回 - Google's oauth2client.getToken() incorrectly returns when called with Q.ninvoke() Google API NodeJS库OAuth2请求 - Google APIs NodeJS Library OAuth2 Request Node.js Google OAuth2无效凭据 - Nodejs google oAuth2 invalid credentials AWS Lambda 超时(NodeJS - 调用 Google Calendar API 时) - AWS Lambda Timeout (NodeJS - when calling Google Calendar API) NodeJS google Oauth2 完美运行,但部署到 Heroku 会阻止 google Oauth2 运行 [已解决] - NodeJS google Oauth2 works perfectly, but deployment to Heroku stops google Oauth2 from working [SOLVED] 带有Node.js的邮递员OAuth2 - Postman oauth2 with nodejs 登录/退出 10 次后,Google oauth2Client getToken 返回 invalid_grant, Bad Request - After login/out 10 times, Google oauth2Client getToken returns invalid_grant, Bad Request OAuth2与Node.js - Oauth2 with nodejs Firebase-NodeJS:带有OAuth2的Google API的域范围委派 - Firebase - NodeJS: Domain-Wide Delegation with OAuth2 for Google API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM