googleapis / googleapis/google-api-nodejs-client

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

Aperta
#3,450 2 commenti 1 reazione 0 assegnatari Vedi su GitHub
priority: p2 size: m type: bug
Lingua principale
TypeScript
Stelle
12.2k
Fork
2k
Merge medio
1g 9h
PR unite (30g)
24

Descrizione

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!

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con la chiamata a OAuth2Client.getToken e il POST segnalato a https://oauth2.googleapis.com/token, quindi esamina i dettagli di ECONNRESET e l'esempio collegato di server web Google OAuth. Il lavoro è completo quando è stato identificato se la libreria client o l'ambiente della richiesta causa il fallimento dello scambio del token e quando è stata documentata una risoluzione riproducibile.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, nodejs
Ambito
api, authentication
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.