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"

オープン
#2,291 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
TypeScript
スター
1.7k
フォーク
419
平均マージ
3日 10時間
マージ済み PR(30日)
16

説明

* 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.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

src/app/credential-internal.ts の 523 行目付近から始め、Firebase の service-account JSON ファイルによる application default credentials で再現してください。access_token を含むものの expires_in を含まない OAuth レスポンスがどのように検証されるかを確認してください。報告された credential flow がそのレスポンスを拒否しなくなり、issue に記載された Admin Auth の使用方法に対して動作を確認できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
node.js, typescript
領域
authentication, backend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。