11
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

LaravelでFirebase Admin SDK for PHPを利用する

11
Last updated at Posted at 2020-06-02

インストール

composer require kreait/firebase-php
composer require kreait/laravel-firebase

Laravelに設定追加

config/app.php
        /*
         * Package Service Providers...
         */
        Kreait\Laravel\Firebase\ServiceProvider::class,
.env
APP_NAME=Laravel
APP_ENV=local
# ... 省略 ...
FIREBASE_CREDENTIALS=../firebase_credentials.json

config配下に設定ファイルを作る

php artisan vendor:publish --provider="Kreait\Laravel\Firebase\ServiceProvider" --tag=config

config/firebase.phpが作成される。

試してみる

app/Http/Controllers/FireTestController.php
<?php

namespace App\Http\Controllers;
use Kreait\Firebase\Auth;

class FireTestController extends Controller
{
    private $auth;

    public function __construct(Auth $auth)
    {
        $this->auth = $auth;
    }

    public function show()
    {
        $anonymous = $this->auth->signInAnonymously();
        print_r([$anonymous->idToken(), $anonymous->firebaseUserId()]);

        return view('welcome');
    }
}

これで、idTokenとfirebaseUserIdが取得できました。
あとはトークン使って好きなように。

idTokenは有効期限が1時間のアレ。
firebaseUserIdは、FirebaseConsoleのAuthenticationページでユーザーUIDと表示されているヤツ。

idTokenの再取得をする処理は以下にまとめた

LaravelでFirebase Admin SDK for PHPを利用する(トークン再取得編)

11
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?