googleapis / googleapis/google-api-nodejs-client
Use code to obtain token. During the process of auth2, the request https://oauth2.googleapis.com/token failed.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 12.2k
- Forks
- 2k
- Ø Merge
- 1 T. 9 Std.
- Gemergte PRs (30 T.)
- 24
Beschreibung
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 googleapi@133.0.0 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!
Beitragsleitfaden
Rechercherichtung
Beginnen Sie mit dem Aufruf von OAuth2Client.getToken und dem gemeldeten POST an https://oauth2.googleapis.com/token. Überprüfen Sie anschließend die Details von ECONNRESET und das verknüpfte Google-OAuth-Webserver-Beispiel. Als abgeschlossen gilt die Aufgabe, wenn festgestellt wurde, ob die Clientbibliothek oder die Anfrageumgebung den Fehler beim Token-Austausch verursacht, und eine reproduzierbare Lösung dokumentiert ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, nodejs
- Bereich
- api, authentication
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100