Merge branch 'master' of github.com:web-push-libs/pywebpush
This commit is contained in:
commit
6a6e26872e
27
README.md
27
README.md
|
@ -14,7 +14,8 @@ Source is available on
|
||||||
|
|
||||||
You'll need to run `python virtualenv`.
|
You'll need to run `python virtualenv`.
|
||||||
Then
|
Then
|
||||||
```commandline
|
|
||||||
|
```
|
||||||
bin/pip install -r requirements.txt
|
bin/pip install -r requirements.txt
|
||||||
bin/python setup.py develop
|
bin/python setup.py develop
|
||||||
```
|
```
|
||||||
|
@ -29,6 +30,7 @@ object. This object has a .toJSON() method that will return a JSON object that c
|
||||||
and push data.
|
and push data.
|
||||||
|
|
||||||
As illustration, a `subscription_info` object may look like:
|
As illustration, a `subscription_info` object may look like:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{"endpoint": "https://updates.push.services.mozilla.com/push/v1/gAA...", "keys": {"auth": "k8J...", "p256dh": "BOr..."}}
|
{"endpoint": "https://updates.push.services.mozilla.com/push/v1/gAA...", "keys": {"auth": "k8J...", "p256dh": "BOr..."}}
|
||||||
```
|
```
|
||||||
|
@ -44,14 +46,15 @@ In many cases, your code will be sending a single message to many
|
||||||
recipients. There's a "One Call" function which will make things
|
recipients. There's a "One Call" function which will make things
|
||||||
easier.
|
easier.
|
||||||
|
|
||||||
```pythonstub
|
```python
|
||||||
from pywebpush import webpush
|
from pywebpush import webpush
|
||||||
|
|
||||||
webpush(subscription_info,
|
webpush(subscription_info,
|
||||||
data,
|
data,
|
||||||
vapid_private_key="Private Key or File Path[1]",
|
vapid_private_key="Private Key or File Path[1]",
|
||||||
vapid_claims={"sub": "mailto:YourEmailAddress"})
|
vapid_claims={"sub": "mailto:YourEmailAddress"})
|
||||||
```
|
```
|
||||||
|
|
||||||
This will encode `data`, add the appropriate VAPID auth headers if required and send it to the push server identified
|
This will encode `data`, add the appropriate VAPID auth headers if required and send it to the push server identified
|
||||||
in the `subscription_info` block.
|
in the `subscription_info` block.
|
||||||
|
|
||||||
|
@ -74,13 +77,14 @@ pywebpush will attempt to auto-fill from the `endpoint`.
|
||||||
a base64 encoded DER formatted private key, or the path to an OpenSSL exported private key file.
|
a base64 encoded DER formatted private key, or the path to an OpenSSL exported private key file.
|
||||||
|
|
||||||
e.g. the output of:
|
e.g. the output of:
|
||||||
```commandline
|
|
||||||
|
```
|
||||||
openssl ecparam -name prime256v1 -genkey -noout -out private_key.pem
|
openssl ecparam -name prime256v1 -genkey -noout -out private_key.pem
|
||||||
```
|
```
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
|
|
||||||
```pythonstub
|
```python
|
||||||
from pywebpush import webpush, WebPushException
|
from pywebpush import webpush, WebPushException
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -133,7 +137,8 @@ named `encrpypted.data`. This command is meant to be used for debugging purposes
|
||||||
**Example**
|
**Example**
|
||||||
|
|
||||||
to send from Chrome using the old GCM mode:
|
to send from Chrome using the old GCM mode:
|
||||||
```pythonstub
|
|
||||||
|
```python
|
||||||
WebPusher(subscription_info).send(data, headers, ttl, gcm_key)
|
WebPusher(subscription_info).send(data, headers, ttl, gcm_key)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -149,7 +154,7 @@ Encode the `data` for future use. On error, returns a `WebPushException`
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
|
|
||||||
```pythonstub
|
```python
|
||||||
encoded_data = WebPush(subscription_info).encode(data)
|
encoded_data = WebPush(subscription_info).encode(data)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
22
README.rst
22
README.rst
|
@ -12,7 +12,7 @@ Installation
|
||||||
|
|
||||||
You'll need to run ``python virtualenv``. Then
|
You'll need to run ``python virtualenv``. Then
|
||||||
|
|
||||||
.. code:: commandline
|
::
|
||||||
|
|
||||||
bin/pip install -r requirements.txt
|
bin/pip install -r requirements.txt
|
||||||
bin/python setup.py develop
|
bin/python setup.py develop
|
||||||
|
@ -43,14 +43,14 @@ Sending Data using ``webpush()`` One Call
|
||||||
In many cases, your code will be sending a single message to many
|
In many cases, your code will be sending a single message to many
|
||||||
recipients. There's a "One Call" function which will make things easier.
|
recipients. There's a "One Call" function which will make things easier.
|
||||||
|
|
||||||
.. code:: pythonstub
|
.. code:: python
|
||||||
|
|
||||||
from pywebpush import webpush
|
from pywebpush import webpush
|
||||||
|
|
||||||
webpush(subscription_info,
|
webpush(subscription_info,
|
||||||
data,
|
data,
|
||||||
vapid_private_key="Private Key or File Path[1]",
|
vapid_private_key="Private Key or File Path[1]",
|
||||||
vapid_claims={"sub": "mailto:YourEmailAddress"})
|
vapid_claims={"sub": "mailto:YourEmailAddress"})
|
||||||
|
|
||||||
This will encode ``data``, add the appropriate VAPID auth headers if
|
This will encode ``data``, add the appropriate VAPID auth headers if
|
||||||
required and send it to the push server identified in the
|
required and send it to the push server identified in the
|
||||||
|
@ -84,13 +84,13 @@ file.
|
||||||
|
|
||||||
e.g. the output of:
|
e.g. the output of:
|
||||||
|
|
||||||
.. code:: commandline
|
::
|
||||||
|
|
||||||
openssl ecparam -name prime256v1 -genkey -noout -out private_key.pem
|
openssl ecparam -name prime256v1 -genkey -noout -out private_key.pem
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
|
|
||||||
.. code:: pythonstub
|
.. code:: python
|
||||||
|
|
||||||
from pywebpush import webpush, WebPushException
|
from pywebpush import webpush, WebPushException
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ purposes.
|
||||||
|
|
||||||
to send from Chrome using the old GCM mode:
|
to send from Chrome using the old GCM mode:
|
||||||
|
|
||||||
.. code:: pythonstub
|
.. code:: python
|
||||||
|
|
||||||
WebPusher(subscription_info).send(data, headers, ttl, gcm_key)
|
WebPusher(subscription_info).send(data, headers, ttl, gcm_key)
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ Encode the ``data`` for future use. On error, returns a
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
|
|
||||||
.. code:: pythonstub
|
.. code:: python
|
||||||
|
|
||||||
encoded_data = WebPush(subscription_info).encode(data)
|
encoded_data = WebPush(subscription_info).encode(data)
|
||||||
|
|
||||||
|
|
|
@ -1 +1,7 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# You will need pandoc to be installed for this to work correctly, as well as the PyPI packages docutils and pygments
|
||||||
|
|
||||||
|
set -e
|
||||||
pandoc --from=markdown --to=rst --output README.rst README.md
|
pandoc --from=markdown --to=rst --output README.rst README.md
|
||||||
|
python setup.py check --restructuredtext --strict --metadata
|
||||||
|
|
|
@ -249,13 +249,11 @@ class WebPusher:
|
||||||
# use ';' instead of ',' to append the headers.
|
# use ';' instead of ',' to append the headers.
|
||||||
# see https://github.com/webpush-wg/webpush-encryption/issues/6
|
# see https://github.com/webpush-wg/webpush-encryption/issues/6
|
||||||
crypto_key += ';'
|
crypto_key += ';'
|
||||||
crypto_key += (
|
crypto_key += ("dh=" + encoded["crypto_key"].decode('utf8'))
|
||||||
"keyid=p256dh;dh=" + encoded["crypto_key"].decode('utf8'))
|
|
||||||
headers.update({
|
headers.update({
|
||||||
'crypto-key': crypto_key,
|
'crypto-key': crypto_key,
|
||||||
'content-encoding': content_encoding,
|
'content-encoding': content_encoding,
|
||||||
'encryption': "keyid=p256dh;salt=" +
|
'encryption': "salt=" + encoded['salt'].decode('utf8'),
|
||||||
encoded['salt'].decode('utf8'),
|
|
||||||
})
|
})
|
||||||
if gcm_key:
|
if gcm_key:
|
||||||
endpoint = 'https://android.googleapis.com/gcm/send'
|
endpoint = 'https://android.googleapis.com/gcm/send'
|
||||||
|
|
|
@ -265,7 +265,7 @@ class WebpushTestCase(unittest.TestCase):
|
||||||
"-H \"crypto-key: p256ecdsa=",
|
"-H \"crypto-key: p256ecdsa=",
|
||||||
"-H \"content-encoding: aesgcm\"",
|
"-H \"content-encoding: aesgcm\"",
|
||||||
"-H \"authorization: WebPush ",
|
"-H \"authorization: WebPush ",
|
||||||
"-H \"encryption: keyid=p256dh;salt=",
|
"-H \"encryption: salt=",
|
||||||
"-H \"ttl: 0\"",
|
"-H \"ttl: 0\"",
|
||||||
"-H \"content-length:"
|
"-H \"content-length:"
|
||||||
]:
|
]:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
cryptography==1.8.1
|
cryptography==1.8.1
|
||||||
http-ece==1.0.1
|
http-ece==1.0.1
|
||||||
requests==2.13.0
|
requests==2.13.0
|
||||||
py-vapid==1.2.1
|
py-vapid==1.2.3
|
||||||
|
|
Loading…
Reference in New Issue