Problem/Motivation
From Google: Apps using the FCM legacy HTTP API should consider migrating to the HTTP v1 API.
For more information:
* https://firebase.googleblog.com/2017/11/whats-new-with-fcm-customizing-m...
* https://firebase.google.com/docs/cloud-messaging/migrate-v1
Steps to reproduce
N/A
Proposed resolution
Migrate to the new HTTP v1 API following the guide provided by Google:
https://firebase.google.com/docs/cloud-messaging/migrate-v1
Remaining tasks
# Update the server endpoint used for sending messages (group management likely still needs to use the legacy endpoint)
# Update the authorization strategy to use OAuth bearer tokens
# Update the payload of send requests
User interface changes
None.
API changes
There may be changes needed to the service API for sending messages.
Data model changes
Not sure.
| Comment | File | Size | Author |
|---|---|---|---|
| #51 | diff-merge-request-3163053-51.patch | 47.92 KB | lonalore |
| #51 | diff-dev-3163053-51.patch | 65.68 KB | lonalore |
| #50 | Migrate_from_legacy_HTTP_to_HTTP_v1-3163053-v50.patch | 63.97 KB | aalin |
| #49 | Migrate_from_legacy_HTTP_to_HTTP_v1-3163053-v48.patch | 61.83 KB | aalin |
| #48 | v34-v48.diff | 1.02 KB | aalin |
Issue fork firebase-3163053
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
samthemanAre there any other FCM modules which use v1 protocol?
Comment #3
mkrizaj commentedHi,
Are there any plans to migrate the module to use HTTP v1 API?
Thanks
Comment #4
siarheinik commenteddeprecated
Migrate from legacy HTTP to HTTP v1 patchComment #5
siarheinik commenteddeprecated
Comment #6
siarheinik commenteddeprecated
Migrate from legacy HTTP to HTTP v1 patchComment #7
siarheinik commentedUpdate PATCH file.
Migrate from legacy HTTP to HTTP v1 patch
Comment #8
mieg commentedhi SiarheiNik, thanks for your work! I tried to use your patch but i couldn't get it to work. It seems there is now a dependency on google-auth-library-php? I get this error:
Error Class "Google\Auth\ApplicationDefaultCredentials" not found.
[edit] solved this by adding google/auth to the project
Comment #9
gazsesz commentedHi,
Can we expect an update to version 3.0.1 ?
Comment #10
siarheinik commentedUpdate the configuration form. Added file selection for credentials. The file is saved to the private folder 'file_private_path'
Comment #11
siarheinik commentedFix error message.
Comment #12
drupalfan2 commentedI recently got this reminder from google:
Will this patch provide the needed actions?
Will this patch update the "Legacy HTTP protocol" and also the "Server Keys" topic?
Will this patch change over to the latest api versions?
Thank you.
Comment #13
deadbeef commentedHere's an update which fixes among other things:
Comment #14
ptmkenny commentedLet's use a merge request to handle this because the changes are complicated and extensive. This should probably be a new major version of the module since the API is changing.
Comment #15
ptmkenny commentedComment #17
ptmkenny commentedComment #18
deadbeef commented@ptmkenny If it's ok with @SiarheiNik I will refactor using config as soon as I get time and try to keep the interface as close to the legacy module as possible. We just needed this to work like yesterday with our credentials policy.
Another thing to discuss is whether typing the various Android/iOS bits and pieces adds enough value. The message itself is a simple, well-documented JSON string and just building it and sending it is very easy to just template, rather than instantiating loads of objects to later then just simply render it out anyway.
Comment #19
ptmkenny commented@deadbeef Thank you for the additional information.
I think it would be better to build the string than to instantiate lots of objects; this API migration makes the code more complex, so I think we should try to keep it as simple as possible.
Comment #20
ptmkenny commented@deadbeef Interesting. As you suggest, it might make more sense to make a wrapper around that package than to rework the code in this module when that package has already done the work.
At the same time, the big problem is this issue was opened three years ago and never got a single comment from any of the listed maintainers, so if such a wrapper was going to be written, it might be better as a new module than as a new major version of this one, since this module is effectively unmaintained.
I emailed @thalles, the last maintainer to commit to this module, on April 11 but haven't heard back.
Comment #21
leopaccanaro commentedHello @ptmkenny.
Unfortunately I am focused more on Java projects and with a special daughter. Sorry to hear @thalles and @renatog are not active around here.
I know Renato and I will talk to him later. I think is on vacation right now.
In the mean time, any of you want to maintain the module? Let me know.
Comment #22
ptmkenny commented@leopaccanaro Thank you for the response.
As suggested by @deadbeef, firebase-php does 90% of what we want to do already, so it makes sense to use that going forward.
To explore this option, I am currently working on https://www.drupal.org/project/firebase_php.
Comment #23
waropd commentedPending an update on https://www.drupal.org/project/firebase_php I'm currently using the patch.
When using firebase in config split and removing the credentials_path locally in the settings, the upload works but the json credentials file isn't saved to the field anymore.
Remove the logger and give the option to return NULL.
Comment #24
waropd commentedInclude new entities in patch.
Comment #25
rares petru samartean commentedPerhaps this is not proper reporting but I should mention it.
The google credentials file does not stay set properly. I added it in the configuration form, the form saved properly and I could see it saved.
After a bit of time I noticed I was no longer getting notifications from my local env, even though I was getting them before.
I went to check the form and saw that a different, random PNG file was assigned instead of the credentials file.
I readded it and moved on.
After a while, again, instead of being reassinged randomly, it got deleted completely and was no longer appearing as set in the form.
I haven't looked into why it happens yet. I used the v10 patch from #13.
Also, setting the config value programatically using something like
doesn't seem to work, or it at least doesn't get recognised in the form. I don't know which one exactly yet as I'm pretty overwhelmed.
Hope this helps you guys. I'll post a fix if I ever find the time to I hope.
Comment #26
rares petru samartean commentedHi again. I'm not sure about setting the path using settings.php since it's not actually a path but a file ID, but I still think I found the issue.
The generated file was being set as temporary. What I did was loading the file by ID in the submit handler of the configuration form, setting it as permanent, then saving it, then setting the file id as the credentials_path config.
Hope this helps. I can't contribute code from my workplace but that should be good enough for you guys to have at it. Thank you for your contributions!
Comment #27
venezonano commentedHello Team.
I also need to fix the module, Can you let me know if I need to apply all patches or only the last one?
Comment #28
john.karam commentedThank you! I have applied the latest patch in #24 and i have succesfully uploaded the file with the credentials.
However, this broke the functionality and it doesn't send notifications anymore. The code I use is similar to the modules documentation:
It seems that the setNotification does not exist anymore and I am not sure what other changes are done.
Could someone provide me with an example (instructions/code) on how to send a notification after applying the patch?
Comment #29
tri tran commentedShould be like this:
Comment #30
spheresh commentedThe credentials path contains the id file. This can become a problem when migrating configs as for me.
This is an initial solution that uses the key module, which works well with http-v1
https://git.drupalcode.org/issue/firebase-3163053/-/tree/http-v1
The only problem is that GOOGLE_APPLICATION_CREDENTIALS requires a file path.
That's why
'#type' => 'key_select',
'#key_filters' => ['provider' => 'file'],
We can only use the file provider.
I have added a @todo to research if we can use $key_entity->getKeyValue() instead.
Because the patch does not allow you to use all the functionality of the keys module for now.
Comment #31
john.karam commentedTri Tran thank you for your code!
I am now receiving the following error: "Failure code: 403; Failure status: PERMISSION_DENIED; Failure message: Permission 'cloudmessaging.messages.create' denied on resource '//cloudresourcemanager.googleapis.com/projects/MYPROJECTNAME' (or it may not exist)."
Any ideas?
Comment #32
waropd commentedExtension of patch #24
Set uploaded file to permanent
Comment #33
Ana Bozhilova commentedHi,
I have similar problem. This patch from #32 comment was not working for me.
Comment #35
divanova commentedHi everyone,
I have installed the latest patch (#32) and updated the new configuration page accordingly.
I've uploaded a .json file which I was given from the Firebase, but it's not working.
Here is the structure of the .json file I received:
For the "Project ID" field in the "Firebase Push Notification Configuration" page, I've used the "project_id" from the .json file.
For "Credentials" field, I have uploaded the provided .json file.
The old code is:
The new code is:
After I try to send a push message, I get this error:
Error: Class "Google\Auth\ApplicationDefaultCredentials" not found in Drupal\firebase\Service\FirebaseServiceBase->getHandler()
I saw that mieg (#8) reported the same issue, but this dependancy is already integrated in the latest patch and I have it locally and on my DEV system, but it still complains about it.
Does anyone can help with ideas what might be wrong?
I also tried the example from Tri Tran (#29) with the $messageService->sendToTokens();, but then I have another error: Error: The message should contain target.
Any ideas/thoughts would be highly appreciated!
Regards,
Daniela
Comment #36
Ana Bozhilova commentedHi,
Install "google/cloud-firestore": "^0.1.0"
Comment #37
Ana Bozhilova commentedThere is a comment below. Please ignore this.
Comment #38
Ana Bozhilova commentedHi,
Here is and a fix for this warning from patch 31
Deprecated function: Return type of Drupal\firebase\Entity\MessageData::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include()
Comment #39
Ana Bozhilova commentedComment #40
divanova commentedHi Ana Bozhilova,
thanks for your response. Installing "google/cloud-firestore" and applying your latest patch worked for me.
The push messages are sent without any errors.
Comment #41
apparatchik commentedThank you to everyone involved in the successive patches, I can confirm I was able to have notifications working again in my Drupal web app, though not with some work.
A few tips for other people struggling with this:
- After you apply the #38 patch to the latest 3.0.1 version, don't forget to run drush updb or update.php to get all the changes to the module's configuration in the db.
- composer require "google/cloud-firestore"
- The credentials json is found not on the firebase console like usual but on the google cloud console, search for "google service account credentials json"
- This might be obvious, but don't forget to import the needed classes at the top of your file:
use Drupal\firebase\Entity\Message;
use Drupal\firebase\Entity\MessageData;
use Drupal\firebase\Entity\Notification;
use Drupal\firebase\Entity\AndroidConfig;
use Drupal\firebase\Entity\ApnsConfig;
- This is the code that I'm using at the moment:
Regards.
Comment #42
mieg commentedDid anybody succeed in sending data-only messages with the latest patches? I couldn't find a way to send a message without a notification.
Comment #43
chandreshgiri gauswami commentedAnyone has implemented sendMulticast() method to send common notification to multiple devices or any reference?
https://firebase-php.readthedocs.io/en/7.16.0/cloud-messaging.html#send-...
Comment #44
drupalfan2 commentedHow can I help to create a new dev version that is working with the new API and contains the last patch?
I need a working solution as soon as possible and I am willing to help write some code or do the tests.
What are the next steps to do?
Comment #45
ptmkenny commented@drupalfan2 This module is not being actively maintained, so you can start the process to become a maintainer. If you email the current maintainers, you may get access quickly, or it may take as long as a couple months.
Alternately, I have created the Firebase PHP module, which takes a different approach than this one (using the Kreait library, which is more widely used outside Drupal in the PHP world). Although in alpha, my module works now and I am happy to accept MRs for anything that is not working.
Comment #46
drupalfan2 commented@ptmkenny
Thank you for your answer and your info.
In the README file of your firebase_php module I did not find any docs how I can send my Firebase Notifications with custom code in my custom module.
How does it work, where can I find an exmple code etc.?`
Thank you.
Comment #47
ptmkenny commented@drupalfan2 Please open issues with firebase_php in that module's issue queue. The API is in https://git.drupalcode.org/project/firebase_php/-/blob/7.0.x/src/Firebas...
Comment #48
aalin commentedUpdated #38 patch to apply against the latest dev branch.
I also attached a diff (v34-v48.diff) showing changes from #38 patch.
Comment #49
aalin commentedFix previous patch file name
Comment #50
aalin commentedThe previous patch didn’t work on Drupal 11. Attaching an updated patch for D11
Comment #51
lonaloreI merged the changes from the patch file above (#50) into the MR code then I fixed the following:
I attached 2 new patch files:
This file contains the diff compared to the MergeRequest.
This file contains the diff compared to the dev branch.
Comment #52
florianj commentedThanks for contributing all these patches.
I’m using the MR and patch file #51, and it seems to work fine.
Is this MR still being reviewed for merging (and possibly the #51 patch, which includes Drupal 11 compatibility) ?