解決Firebase部屬失敗HTTP Error: 401, Request had invalid authentication credentials.

這幾天寫了好幾個功能,今天想要部屬到Firebase時發生了401部屬錯誤,完整訊息如下:

Error: HTTP Error: 401, Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

該怎麼處理呢? 


問題細節

使用除錯模式debug(firebase deploy --debug)看到的是從很前面就開始錯誤了

[2024-07-12T05:49:05.391Z] <<< [apiv2][status] POST https://cloudresourcemanager.googleapis.com/v1/projects/tidy-access-240712:testIamPermissions 401

[2024-07-12T05:49:05.391Z] <<< [apiv2][body] POST https://cloudresourcemanager.googleapis.com/v1/projects/tidy-access-240712:testIamPermissions {"error":{"code":401,"message":"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","status":"UNAUTHENTICATED","details":[{"@type":"type.googleapis.com/google.rpc.ErrorInfo","reason":"ACCESS_TOKEN_TYPE_UNSUPPORTED","metadata":{"method":"google.cloudresourcemanager.v1.Projects.TestIamPermissions","service":"cloudresourcemanager.googleapis.com"}}]}}


Firebase登出再登入竟還是失敗

因為昨天有升級firebase-tools想說該不會因為改版,導致憑證不相容,就重新登入

firebase logout再firebase login

結果還是得到相同HTTP Error: 401。


Reauth就成功

google了一下其他人是否也有問題。看到除了重新登入的方法,還可以用

firebase login --reauth

這樣會一樣會進行oauth的憑證登入。

說也奇怪,這樣作之後再部屬就正常了,故以此文章作個紀錄。


參考資料




留言