はじめに
Raspberry pi3(CLI only)にFirebaseの環境を構築しようとした際、Firebaseのログイン処理に苦戦したため、備忘録として残しておきます。
どこで詰まったか
$ firebase login
i Firebase optionally collects CLI usage and error reporting information to help improve our products. Data is collected in accordance with Google's privacy policy (https://policies.google.com/privacy) and is not used to identify you.
? Allow Firebase to collect CLI usage and error reporting information? Yes
i To change your data collection preference at any time, run `firebase logout` and log in again.
Visit this URL on this device to log in:
https://accounts.google.com/o/oauth2/・・・・・・
Waiting for authentication...
ここでfirebase-cliを利用する装置上で、Webブラウザ(GUI)でURL(Visit this URL on this device to log in:
の下に記載されている)へアクセスし、Googleアカウントの認証を行う必要がある。
しかし、うちのRaspberry piにGUIは入っていない。
解決策
--no-localhost
オプションを追加し、URLの発行だけRaspberry pi上で行い、他のGUIが入ってる装置でGoogle認証を行う。
$ sudo firebase login --no-localhost
[sudo] password for hub:
Visit this URL on any device to log in:
https://accounts.google.com/o/oauth2/auth?・・・・
? Paste authorization code here:
Visit this URL on this device to log in:
の下に記載されているURLに、他の装置上のブラウザでアクセスする。
GoogleアカウントへのログインとCLI利用の許可処理を行うと、パスコードが発行されるのでそれをコピーする。
コピーしたパスコードをRaspberry piに入力すると、「Success! Logged in as username」が表示され、無事Firebaseのログイン処理が完了する。
補足
Error: Authentication Error: Your credentials are no longer valid. Please run firebase login --reauth
上記のエラーメッセージが出た場合はsudo firebase login --no-localhost --reauth
で改めて試すとログインできる。