Motivation

The form fields server_key and sender_id of the configuration form have set the required property. But if you fill this fields with erroneous data the form save and responds "Ok". This can produce errors during the implementation of this module.

 Proposed resolution

FCM does not have a specific endpoint to ensure your server_key and your sender_id are working properly. Despite this fact, here I propose a workaround by sending a "fake request" to validate a "fake device token" and control de response.

If the server_key is not valid a form_state error message is thrown and the user is returned to the form without saving. This message points to the server_key if the return code is 401, and shows the specific error in other cases (p.e. server error).

In case of no error thrown the code is saved as usual.

Comments

jginer created an issue. See original summary.

jginer’s picture

Issue summary: View changes
jginer’s picture

And the patch of the propose.

krzysztof domański’s picture

Status: Active » Needs review
handkerchief’s picture

A related question to this topic: What do you recommend for regularly checking whether the tokens already saved are still valid?

Would a good option be, for example, a cronjob that tests all stored tokens with this validation handler every week/month and deletes them from the database if they are negative?

@see https://firebase.google.com/docs/cloud-messaging/manage-tokens#update-to...

edit: Wrong issue sorry, better suited to this issue: #3088291: Add token validation service
https://www.drupal.org/project/firebase/issues/3088291#comment-15570028