firebase / firebase/firebase-admin-node
Setting $GOOGLE_APPLICATION_CREDENTIALS is causing authentication issue
- 主要语言
- TypeScript
- 星标
- 1.7k
- 派生
- 419
- 平均合并
- 3 天 10 小时
- 30 天内合并 PR
- 16
描述
* Operating System version: `macOS 12.4`
* Firebase SDK version: `firebase cli 12.5.2`
* Firebase Product: `admin 11.10.1`
* Node.js version: `v18.16.0`
* NPM version: 9.5.1
#### Steps to reproduce:
When pointing $GOOGLE_APPLICATION_CREDENTIALS to a JSON key and running `firebase emulators:start --only functions`, the console will confirm the key is recognized
```
functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to
.json. Non-emulated services will access production using these credentials. Be careful!
```
but the `firebase-admin` module will throw error
```
FirebaseAppError: 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: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND".
...
errorInfo: {
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: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND".'
},
```
When passing in the same key file directly when initializing `firebase-admin`, no such error is produced.
### Relevant Code:
initialization that **WILL** cause the error (with `$GOOGLE_APPLICATION_CREDENTIALS` set to the path to the key JSON file)
``` javascript
admin.initializeApp();
// or
admin.initializeApp({
credential: admin.credential.applicationDefault(),
});
```
initialization that will **NOT** cause the error:
```javascript
const serviceKey = require("path-to-the-key.json");
admin.initializeApp({
credential: admin.credential.cert(payload)
});
```
code snipet to trigger the error
```javascript
async function test() {
const EMAIL = ;
const user = await admin.auth().getUserByEmail(EMAIL);
}
```
贡献指南
调研方向
从 admin.initializeApp() 和 admin.credential.applicationDefault() 开始,然后将 GOOGLE_APPLICATION_CREDENTIALS 设置为密钥路径来重现,并与 credential.cert(payload) 进行比较。当基于环境的初始化获得有效的 OAuth 令牌,且 admin.auth().getUserByEmail(EMAIL) 不再引发报告中的 metadata.google.internal 错误时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, node.js
- 领域
- authentication
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100