Code Monkey home page Code Monkey logo

web-push-bundle's Introduction

MinishlinkWebPushBundle

This bundle provides a simple integration of the WebPush library.

SensioLabsInsight

Usage

Web Push sends notifications to endpoints which server delivers web push notifications as described in the Web Push API specification.

<?php
/** @var \Minishlink\WebPush\WebPush */
$webPush = $this->container->get('minishlink_web_push');

The bundle provides a new minishlink_web_push service that returns an instance of Minishlink\WebPush\WebPush.

For more info on what you can do with $webPush, check Minishlink/web-push.

Installation

  1. composer require minishlink/web-push-bundle
  2. Enable the bundle in your app/AppKernel.php.
<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Minishlink\Bundle\WebPushBundle\MinishlinkWebPushBundle(),
        // ...
    );
}

Configuration

Here is the default configuration, you may change it in your app/config/config.yml.

minishlink_web_push:
  VAPID:
    subject: https://yoursite.com # can be an URL or a mailto:
    publicKey: ~88 chars          # uncompressed public key P-256 encoded in Base64-URL
    privateKey: ~44 chars         # the secret multiplier of the private key encoded in Base64-URL
    pemFile: path/to/pem          # if you have a PEM file and can link to it on your filesystem
    pem: pemFileContent           # if you have a PEM file and want to hardcode its content
  ttl: 2419200                    # Time to Live of notifications in seconds
  urgency: ~                      # can be very-low / low / normal / high
  topic: ~                        # default identifier for your notifications
  timeout: 30                     # Timeout of each request in seconds
  automatic_padding: true         # pad messages automatically for better security (against more bandwith usage)

web-push-bundle's People

Contributors

franciscosantamaria avatar gab3sz avatar genietim avatar juliusstoerrle avatar minishlink avatar stephanvierkant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

web-push-bundle's Issues

Not all configs are handled

PHP Fatal error: Uncaught exception 'Symfony\Component\Config\Definition\Exception\InvalidConfigurationException' with message 'Unrecognized option "automatic_padding" under "minishlink_web_push"'

I think automatic_padding is not handled in this bundle.

Sending with payload not working

I am unable to send notifications with payloads.
Each time the payload is not empty, the request is sent and sendNotification method returns true (when I dumped response, status code was 201), but no notification is delivered.

$webPush = $this->get('minishlink_web_push');

        $notifications = [
            [
                'subscription' => Subscription::create([
                    'endpoint' => 'https://fcm.googleapis.com/fcm/send/chvo9gq76WU:APA91bHh661rEeUWR14F9VTyghQTu1qNAQOGFEH0rbwWSsKRjxR9NP2hzyoryMOYLNHBgGnEnCeOuPwXOtTd2uSd8Ks8lWeLyzzXvNWWBj-H1DzN5rQGgsij7lv-2sZWPu6kZJ9dlUZm', // Firefox 43+,
                    'publicKey' => 'publicKey', // base 64 encoded, should be 88 chars
                    'authToken' => 'authToken', // base 64 encoded, should be 24 chars
                ]),
                'payload' => 'hello !',
            ]
        ];

        foreach ($notifications as $notification) {
            $webPush->sendNotification(
                $notification['subscription'],
                $notification['payload']
            );
        }
        $webPush->flush();

web push api issues in using wamp

hi i am trying to use https://github.com/web-push-libs/web-push-php

there are issues in using on local server wamp

want to use this for send push notification

use Minishlink\WebPush\WebPush;

// array of notifications
$notifications = array(
array(
'endpoint' => 'https://updates.push.services.mozilla.com/push/abc...', // Firefox 43+
'payload' => 'hello !',
'userPublicKey' => 'BPcMbnWQL5GOYX/5LKZXT6sLmHiMsJSiEvIFvfcDvX7IZ9qqtq68onpTPEYmyxSQNiH7UD/98AUcQ12kBoxz/0s=', // base 64 encoded, should be 88 chars
'userAuthToken' => 'CxVX6QsVToEGEcjfYPqXQw==', // base 64 encoded, should be 24 chars
), array(
'endpoint' => 'https://android.googleapis.com/gcm/send/abcdef...', // Chrome
'payload' => null,
'userPublicKey' => null,
'userAuthToken' => null,
), array(
'endpoint' => 'https://example.com/other/endpoint/of/another/vendor/abcdef...',
'payload' => '{msg:"test"}',
'userPublicKey' => '(stringOf88Chars)',
'userAuthToken' => '(stringOf24Chars)',
),
);

$webPush = new WebPush();

// send multiple notifications with payload
foreach ($notifications as $notification) {
$webPush->sendNotification(
$notification['endpoint'],
$notification['payload'], // optional (defaults null)
$notification['userPublicKey'], // optional (defaults null)
$notification['userAuthToken'] // optional (defaults null)
);
}
$webPush->flush();

// send one notification and flush directly
$webPush->sendNotification(
$notifications[0]['endpoint'],
$notifications[0]['payload'], // optional (defaults null)
$notifications[0]['userPublicKey'], // optional (defaults null)
$notifications[0]['userAuthToken'], // optional (defaults null)
true // optional (defaults false)
);

issues in using use Minishlink\WebPush\WebPush;
and plz which url to use in endpoint ?

Outdated dependency

Thank you for this bundle. I have a question regarding its actuality; when running composer outdated, it lists the dependency minishlink/web-push v2.0.1 as outdated. The current version is ~ v4.0.2. Is there a specific reason for beeing outdated? If not, is someone working or should I open a PR for an upgrade?

Best regards

PHP 8 support

Hi,

Thank you for your job.
It would be nice to add support to PHP 8 :)

Best regards

[Symfony 6] Problems with the "minishlink_web_push" service

Good morning

install the Minishlink/web-push-bundle v6.0.3 package on a symfony 6.

When trying to recover the service as the documentation says:

$webPush = $this->container->get('minishlink_web_push');

symfony complains that the indicated service is not found in the container.

So try dependency injection:

use Doctrine\Persistence\ManagerRegistry;
use Minishlink\WebPush\WebPush;

class functionsNotifications
{
public function __construct(private WebPush $webPush, private ManagerRegistry $doctrine)
{}

public function notify()
{
    dd($this->webPush);
}

}

but symfony throws the error

Cannot autowire service "App\Utils\NotificationFunctions": argument "$webPush" of method "__construct()" references class "Minishlink\WebPush\WebPush" but no such service exists. You should maybe alias this class to the existing "minishlink_web_push" service.

I would appreciate any help.

VAPID config not found in bundle config resulting in endpoint reporting 401 missing auth headers

$container->setParameter('minishlink_web_push.auth', $config['VAPID']);

I'm not sure but the last bundle update to version 6 seems to break the VAPID-config.
Currently the auth array seems to miss the VAPID-key. Adding the key fixes the missing config for me:

$container->setParameter('minishlink_web_push.auth', isset($config['VAPID']) ? ['VAPID' => $config['VAPID']] : []);

Support of PHP versions?

I see this library still supports PHP 7.1, which is End of Life (EOL) for a long time. Even 7.3 is EOL as of today.

What's the policy about PHP support? The only supported versions are 7.4, 8.0 and 8.1

In my opinion libraries should drop support of PHP versions that are end of life, because it makes contributing to this library much easier.

not installable under Symfony 3.1

Hi,

would like to try your bundle, but can't install it under Symfony 3.1. The requirement of mdanter/ecc seems to conflict with the requirements from symfony/polyfill-php70, which is a requirement of symfony:

composer require minishlink/web-push-bundle:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for minishlink/web-push-bundle ^1.3 -> satisfiable by minishlink/web-push-bundle[v1.
3].
    - minishlink/web-push-bundle v1.3 requires minishlink/web-push ^1.3.0 -> satisfiable by minishlink/web-push
[v1.3, v1.3.1, v1.3.2].
    - minishlink/web-push v1.3 requires mdanter/ecc ^0.4.0 -> satisfiable by mdanter/ecc[v0.4.0].
    - minishlink/web-push v1.3.1 requires mdanter/ecc ^0.4.0 -> satisfiable by mdanter/ecc[v0.4.0].
    - minishlink/web-push v1.3.2 requires mdanter/ecc ^0.4.0 -> satisfiable by mdanter/ecc[v0.4.0].
    - Conclusion: don't install mdanter/ecc v0.4.0

composer require mdanter/ecc:

  Problem 1
    - Installation request for mdanter/ecc ^0.4.0 -> satisfiable by mdanter/ecc[v0.4.0].
    - Conclusion: remove paragonie/random_compat v2.0.3
    - Conclusion: don't install paragonie/random_compat v2.0.3
    - mdanter/ecc v0.4.0 requires paragonie/random_compat 1.4.1|2.0.2 -> satisfiable by paragonie/random_compat[v1.4.1, v2.0.2].
    - Can only install one of: paragonie/random_compat[v1.4.1, v2.0.3].
    - Can only install one of: paragonie/random_compat[v2.0.2, v2.0.3].
    - Installation request for paragonie/random_compat (locked at v2.0.3) -> satisfiable by paragonie/random_compat[v2.0.3].

Is there a way to get around this?

Support Symfony 5

I would like to use this library with Symfony 5.

I have not used the bundle with version 4, therefore I don't know if any deprecations came up. I guess it is only required to update the composer.json?

Support Minishlink/web-push version 5

This bundle is limited to version 4 of minishlink/web-push, but version 5 is here for some time now. Please support it in a new major version of the.

And perhaps just skip version 4 in that bundle to synchronize the major version of the bundle with the main library :)

It appears there is one deprecation which pops up with 4.2

$treeBuilder = new TreeBuilder();

        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('minishlink_web_push');
// Should become
        $treeBuilder = new TreeBuilder('minishlink_web_push');
        $rootNode = $treeBuilder->getRootNode();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.