firebase / firebase/firebase-admin-node
When using application default credentials, `access_token` is present but `expires_in` is missing from OAuth response, causing "Unexpected response while fetching access token"
- Lenguaje dominante
- TypeScript
- Estrellas
- 1.7k
- Forks
- 419
- Merge medio
- 3 d 10 h
- PR fusionados (30 d)
- 16
Descripción
* Operating System version: Mac
* Firebase SDK version: 11.5.0
* Firebase Product: Admin SDK (Auth)
* Node.js version: 18.17.1
* NPM version: 9.6.7
### [REQUIRED] Step 3: Describe the problem
I'm getting the following error from the Admin SDK when using application default credentials to authenticate:
```
{
code: 'app/invalid-credential',
message: 'Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error:
"Error fetching access token: Unexpected response while fetching access token:
{"access_token":"ya29.","token_type":"Bearer"}".'
}
```
_(line breaks added for legibility)_
Which seems to indicate a valid access token _is_ being provisioned (there's a token in there that starts with `ya29.`), but the library isn't reading it correctly.
It seems like the library is [expecting an `expires_in` key to appear as well](https://github.com/firebase/firebase-admin-node/blob/master/src/app/credential-internal.ts#L523) but that key is missing in the response it's getting from Google's auth APIs.
#### Steps to reproduce:
1. Use application default credentials (`GOOGLE_APPLICATION_CREDENTIALS=sa.json` and `credential: applicationDefault()`) with the Node Admin SDK
2. Grab `sa.json` from your project's Service Accounts tab in the Firebase console.
3. Try to use Admin SDK APIs such as `getAuth`, `auth.verifySessionCookie`, etc. (my code is [here](https://github.com/romannurik/express-firebase-auth-gate/blob/main/src/make-gated-app.ts) if needed).
4. Observe [in some cases?] you see the error cited above.
Guía de contribución
Línea de trabajo
Start in src/app/credential-internal.ts around line 523 and reproduce with application default credentials from a Firebase service-account JSON file. Inspect how the OAuth response containing access_token but no expires_in is validated. Done means the reported credential flow no longer rejects that response, with behavior checked against the Admin Auth usage described in the issue.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- node.js, typescript
- Área
- authentication, backend
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100