kreait / laravel-firebase

A Laravel package for the Firebase PHP Admin SDK
https://github.com/kreait/firebase-php
MIT License
994 stars 163 forks source link

invalid_grant issues on Lumen #102

Closed wienzzz closed 2 years ago

wienzzz commented 2 years ago

Can anyone give me pointer about this?

I am trying to incorporate firebase on my Lumen REST API and I have followed the documentation to send FCM using this library, but upon calling the function to send message from code block below :

$topic = "a-topic";
$notification = Notification::create("New ORDER from SALES", "NEW ORDER FROM ".$uid."!");

$message = CloudMessage::withTarget('topic', $topic)
                    ->withNotification($notification) // optional
                    ->withData(array("invoice" => $inv)) // optional
;

$messaging->send($message);

Summary of what I did :

  1. composer require kreait/laravel-firebase
  2. Generate private key from firebase console and put it on accessible folder
  3. create [lumen_project]/config/firebase.php file
  4. add FIREBASE_CREDENTIAL to .env file

From here I stuck and don't really know what to do :( Am I missing any step to use laravel-firebase library?

jeromegamez commented 2 years ago

Have you added the ServiceProvider to `config/app.php? (https://github.com/kreait/laravel-firebase#laravel)

It could be that you have local google application default credentials in your $HOME/.config/gcloud directory, e.g. from a previous gcloud auth application-default login operation (or in $APPDATA, if you're on windows). If that's the case, the reason could be that the package is falling back to these credentials when the path specified in FIREBASE_CREDENTIAL cannot be found.

Now that I've written out the FIREBASE_CREDENTIAL myself... the environment variable needs to be FIREBASE_CREDENTIALS (with an S at the end). When the correct env variable is not set, the package will fall back to the auto-discovered application default credentials, so now I believe that this should be in fact the reason 🤞

wienzzz commented 2 years ago

@jeromegamez thanks for your reply,

Your library indeed work out of the box perfectly. Apparently I have several issues that doesn't concern this library at all. But I will share this in case other face similar problem like me :

jeromegamez commented 2 years ago

Thanks for sharing @wienzzz! 🌺

FYI: You can configure the SDK to use a proxy: https://firebase-php.readthedocs.io/en/5.x/setup.html?highlight=Proxy#http-client-options