1
- # WebPush
1
+ # WebPushEx
2
2
3
- This library implements RFC 8291 Message Encryption for Web Push.
3
+ This library implements
4
+ [ RFC 8291] ( https://datatracker.ietf.org/doc/html/rfc8291/ ) Message Encryption
5
+ for Web Push in Elixir.
4
6
5
7
It generates request details but does not make the HTTP POST request itself. The
6
8
generated details should be enough to feed to your HTTP client of choice.
7
9
8
- ## Installation
9
-
10
- If [ available in Hex] ( https://hex.pm/docs/publish ) , the package can be installed
11
- by adding ` web_push ` to your list of dependencies in ` mix.exs ` :
10
+ #### Features
12
11
13
- ``` elixir
14
- def deps do
15
- [
16
- {:web_push , " ~> 0.1.0" }
17
- ]
18
- end
19
- ```
12
+ * ` aes128gcm ` content encoding method
13
+ * uses ` :json ` (requires Erlang/OTP >=27)
14
+ * uses JOSE for handling JWT
15
+ * bring your own HTTP client
16
+ * tested using RFC examples
20
17
21
18
## Configuration
22
19
@@ -27,18 +24,18 @@ generated config to your needs:
27
24
$ mix web_push.vapid
28
25
# in config/config.exs:
29
26
30
- config :web_push , :vapid,
27
+ config :web_push_ex , :vapid,
31
28
public_key: "<base64 encoded public key>"
32
29
33
30
34
31
# in config/runtime.exs:
35
32
36
- config :web_push , :vapid,
33
+ config :web_push_ex , :vapid,
37
34
private_key: System.fetch_env!("WEB_PUSH_VAPID_PRIVATE_KEY")
38
35
39
36
# in your environment:
40
37
41
- export WEB_PUSH_VAPID_PRIVATE_KEY =<base64 encoded private key>
38
+ export WEB_PUSH_EX_VAPID_PRIVATE_KEY =<base64 encoded private key>
42
39
```
43
40
44
41
## Usage
@@ -54,21 +51,21 @@ pushManager.subscribe({
54
51
}).then (... );
55
52
```
56
53
57
- Once you have your subscription data, you may construct a ` WebPush .Request` and
54
+ Once you have your subscription data, you may construct a ` WebPushEx .Request` and
58
55
use it to make the push notification via the HTTP client of your choice.
59
56
60
57
``` elixir
61
58
# create the struct from the subscription JSON data
62
59
subscription =
63
- WebPush .Subscription .from_json ("""
60
+ WebPushEx .Subscription .from_json ("""
64
61
{"endpoint":"https://push.example.com/123","keys":{"p256dh":"user_agent_public_key","auth":"auth_secret"}}
65
62
""" )
66
63
67
64
# structured message, see example serviceWorker.js linked below
68
65
message = %{title: " Notification Title" , body: " lorem ipsum etc" }
69
66
70
67
# generate request details
71
- %WebPush .Request {} = request = WebPush .request (subscription, :json .encode (message))
68
+ %WebPushEx .Request {} = request = WebPushEx .request (subscription, :json .encode (message))
72
69
73
70
request.endpoint
74
71
# => "https://push.example.com/123"
@@ -86,14 +83,29 @@ request.headers
86
83
# "Urgency" => "normal"
87
84
# }
88
85
89
- # send web push notification via http client e.g. tesla
90
- Tesla .post (request.endpoint, request.body, headers: Map .to_list (request.headers))
86
+ # send web push notification via http client e.g. req
87
+ {:ok , resp} = Req .post (request.endpoint, body: request.body, headers: request.headers)
88
+ ```
89
+
90
+ ## Installation
91
+
92
+ If [ available in Hex] ( https://hex.pm/docs/publish ) , the package can be installed
93
+ by adding ` web_push ` to your list of dependencies in ` mix.exs ` :
94
+
95
+ ``` elixir
96
+ def deps do
97
+ [
98
+ {:web_push_ex , " ~> 0.1.0" }
99
+ ]
100
+ end
91
101
```
92
102
93
103
## tl()
94
104
95
105
#### Motivation && Inspiration
96
106
107
+ Many thanks to maintainers and contributors to all these repos 🙇
108
+
97
109
* [ web-push-elixir] ( https://github.com/midarrlabs/web-push-elixir )
98
110
* [ web-push-encryption] ( https://github.com/tuvistavie/elixir-web-push-encryption )
99
111
* [ web-push] ( https://github.com/web-push-libs/web-push )
0 commit comments