Motivation

In order to use FCM you should save the device tokens in Drupal. This service provide an easy way to check that the token sent by the device is really a registered token in Firebase.

Proposed resolution

In order to validate device token you should:

// Token is generated by app. You'll have to send the token to Drupal.
$fakeToken = 'e3vUiwcvkpY:APA91bEDZzKTIkaL0e-UTwiV6EGi1m5J5PrDMxejm6-d85vdwAgd';

// Before saving this token, validate it through firbase
$tokenValidation = \Drupal::service('firebase.token_validation');

// Get TRUE if validated or FALSE if not
$result = $tokenValidation->validateDeviceToken($fakeToken);

Issue fork firebase-3088291

Command icon 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

jginer created an issue. See original summary.

jginer’s picture

StatusFileSize
new2.43 KB

And the proposed patch

espurnes’s picture

Issue summary: View changes

updated issue description.

krzysztof domański’s picture

Version: 8.x-1.0 » 3.0.x-dev
Status: Active » Needs review

ptmkenny made their first commit to this issue’s fork.

ptmkenny’s picture

Added an MR of patch #2 to make this easier to 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 service 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...

ptmkenny’s picture

@handkerchief This module currently has no feature for managing whether tokens are still valid. That would be a useful feature to have, but it should probably be made as a feature request in a separate issue.

Also, for what it's worth, this module is not actively maintained, so hopefully you're able to contribute the code yourself.

handkerchief’s picture

I switched to the project firebase_php. It has validation features as well as the modern way of API as google is discontinuing the old one soon.