firebaseをSymfonyに導入ハウツー

 

Firebaseすごいな。ログイン機能を全部やってくれるって滅茶ありがたい。しかも認証部分は無料みたい。

ユーザーの情報をFirebase側に保存するときにStorageのお金とかかからないのかな?もし知っていたら教えてください。

 

導入方法

1.Composerでバンドルを入れる

code

composer require kreait/firebase-bundle

2.Symfonyプロジェクト内のconfig/bundle.phpを変更する

code

return [
// …
Kreait\Firebase\Symfony\Bundle\FirebaseBundle::class => [‘all’ => true],
];

3.config/packages/firebase.yamlを新しく追加する

GithubのFullってやつをfirebase.yamlに保存する

code

kreait_firebase:
projects:
my_project:
# Optional: Path to the project’s Service Account credentials file
# If omitted, the credentials will be auto-dicovered as described
# in https://firebase-php.readthedocs.io/en/stable/setup.html#with-autodiscovery
credentials: ‘%kernel.project_dir%/config/my_project_credentials.json
# Optional: If set to true, this project will be used when
# type hinting the component classes of the Firebase SDK,
# e.g. Kreait\Firebase\Auth, Kreait\Firebase\Database,
# Kreait\Firebase\Messaging, etc.
default: false
# Optional: If set to false, the service and its alias can only be
# used via dependency injection, and not be retrieved from the
# container directly.
public: true
# Optional: Should only be used if the URL of your Realtime
# Database can not be generated with the project id of the
# given Service Account
database_uri: ‘https://my_project.firebaseio.com’
# Optional: Default domain for Dynamic Links
default_dynamic_links_domain: ‘https://my_project.page.link’
# Optional: Used to cache Google‘s public keys. Must implement
# \Psr\SimpleCache\CacheInterface (PSR-16)
verifier_cache: null # Example: cache.app
# If set, logs simple HTTP request and response statuses
http_request_logger: null # Example: monolog.logger.firebase
# If set, logs detailed HTTP request and response statuses
http_request_debug_logger: null # Example: monolog.logger.firebase_debug

4.FirebaseConsoleを登録する
ログイン - Google アカウント
5.サービスアカウントの秘密鍵を生成する

FirebaseConsoleで自動生成してくれる

Sign in - Google Accounts
6.firebase.yamlのcredentialにあるファイルパスを、先程取得したJSONの場所に合わせる。

 

以上、覚書

コメント

タイトルとURLをコピーしました