RickBlog

恩返し

エンドユーザー認証[Firebase][Ruby]

FirestoreをRubyで扱っていたら認証のエラーが出てハマってしまったので、解決方法をメモしておく。

RubyでFirestoreを扱う方法。
https://cloud.google.com/firestore/docs/quickstart-servers?hl=ja

エラー内容

googleアカウントを切り替えて、新しいプロジェクトに対して処理を実行したら、以下のエラーが発生した。

GaxError Exception occurred in retry method that was not classified as transient, caused by 7:Missing or insufficient permissions. (Google::Gax::RetryError)
7:Missing or insufficient permissions. (Google::Cloud::PermissionDeniedError)

原因調査

アカウントを切り替える前のに戻して実行すると、以下の警告が出ていた。

Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/.

エンドユーザー認証を使っているので、アカウントを切り替えるとエラーが出るのでは?と考えた。

解決方法

以下のコマンドでアカウントを設定する。

$ gcloud init

以下のコマンドでアカウントを認証したら解決した。

$ gcloud auth application-default login