googleapis / googleapis/google-api-nodejs-client

Clarify intended procedure for detecting when a new access token has been generated and how/whether to store it

Aperta
#3,568 1 commento 4 reazioni 0 assegnatari Vedi su GitHub
size: m type: docs
Lingua principale
TypeScript
Stelle
12.2k
Fork
2k
Merge medio
1g 9h
PR unite (30g)
24

Descrizione

### Please make sure you have searched for information in the following guides.

- [X] Search the issues already opened: https://github.com/GoogleCloudPlatform/google-cloud-node/issues
- [X] Check our Troubleshooting guide: https://googlecloudplatform.github.io/google-cloud-node/#/docs/guides/troubleshooting
- [X] Check our FAQ: https://googlecloudplatform.github.io/google-cloud-node/#/docs/guides/faq
- [X] Check our libraries HOW-TO: https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md
- [X] Check out our authentication guide: https://github.com/googleapis/google-auth-library-nodejs
- [X] Check out handwritten samples for many of our APIs: https://github.com/GoogleCloudPlatform/nodejs-docs-samples

### Documentation Request

When an access token is expired, performing an API request will automatically use the refresh token to fetch a new access token. However, this does *not* trigger the `on('tokens)` event; this only fires on the first authentication.

What is not explained clearly in the docs then, is how the new access token is meant to be detected so that it can be stored and reused for its validity period. Otherwise the new access token may be lost and users hit 401 Invalid Credentials errors in subsequent requests.

Is the intent that after each API call, we manually check the oAuth2Client for a new access token via `oAuth2Client.credentials.access_token`? I.e., add manual token checking logic after each API call? If this is the case, can explicit instructions be added that something like this is the intended approach?

Or is there some other event similar to `tokens` we can listen for on the `oAuth2Client` that will automatically trigger upon receiving an updated access token? (If not, can that feature be added?)

Perhaps the access token is not meant to be stored at all? Discarded after each request? But then we are fetching new access tokens for every request after the first hour.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con la guida all’autenticazione collegata e con le guide HOW-TO del repository relative alla risoluzione dei problemi, alle FAQ e alle librerie. Verifica come vengono esposti i token di accesso OAuth2 aggiornati, se devono essere memorizzati e se è disponibile un evento. Il lavoro è completato quando la documentazione descrive chiaramente la procedura prevista per l’aggiornamento, il rilevamento e la memorizzazione.

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

Valutazione

Stack tecnologico
node.js, typescript
Ambito
authentication, documentation
Tipo di issue
Documentazione
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.