webpush 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +20 -0
- data/lib/webpush/request.rb +5 -1
- data/lib/webpush/vapid_key.rb +19 -0
- data/lib/webpush/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a7dfdadec9ade5140f48e4b7643202630c9e14700e8366011464b0c6d3bfade
|
4
|
+
data.tar.gz: 6e8bed89a1abd252c703f1f79e865e23d69a5cd6e973709bd1e86d85977fb893
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf031e189b8d2637968605500b14abd1c3941f1ff8229ebf2131e5e6c4343badff7295f308c5a192fcccfeca90ad696873f891f47ead43fd3398057333786ce2
|
7
|
+
data.tar.gz: 3b3097ce59cb726d4009cb8dc5e7c5b17a330b4cd8a5f97a9dd424c337f91a1c3570d5ef9459e69be3a5f61cbf42eee8536b110716d373744df78e7ae74da741
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v0.3.6](https://github.com/zaru/webpush/tree/v0.3.6) (2019-01-09)
|
4
|
+
[Full Changelog](https://github.com/zaru/webpush/compare/v0.3.5...v0.3.6)
|
5
|
+
|
6
|
+
**Merged pull requests:**
|
7
|
+
|
8
|
+
- Added a error class to arguments of raise\_error [\#62](https://github.com/zaru/webpush/pull/62) ([zaru](https://github.com/zaru))
|
9
|
+
- Fix TravisCI bundler version [\#61](https://github.com/zaru/webpush/pull/61) ([zaru](https://github.com/zaru))
|
10
|
+
- Raise Webpush::Unauthorized on HTTP 403 [\#59](https://github.com/zaru/webpush/pull/59) ([collimarco](https://github.com/collimarco))
|
11
|
+
|
3
12
|
## [v0.3.5](https://github.com/zaru/webpush/tree/v0.3.5) (2019-01-02)
|
4
13
|
[Full Changelog](https://github.com/zaru/webpush/compare/v0.3.4...v0.3.5)
|
5
14
|
|
data/README.md
CHANGED
@@ -45,6 +45,9 @@ vapid_key = Webpush.generate_key
|
|
45
45
|
# Save these in your application server settings
|
46
46
|
vapid_key.public_key
|
47
47
|
vapid_key.private_key
|
48
|
+
|
49
|
+
# Or you can save in PEM format if you prefer
|
50
|
+
vapid_key.to_pem
|
48
51
|
```
|
49
52
|
|
50
53
|
### Declaring manifest.json
|
@@ -281,6 +284,23 @@ Webpush.payload_send(
|
|
281
284
|
)
|
282
285
|
```
|
283
286
|
|
287
|
+
### With VAPID in PEM format
|
288
|
+
|
289
|
+
This library also supports the PEM format for the VAPID keys:
|
290
|
+
|
291
|
+
```ruby
|
292
|
+
Webpush.payload_send(
|
293
|
+
endpoint: "https://fcm.googleapis.com/gcm/send/eah7hak....",
|
294
|
+
message: "A message",
|
295
|
+
p256dh: "BO/aG9nYXNkZmFkc2ZmZHNmYWRzZmFl...",
|
296
|
+
auth: "aW1hcmthcmFpa3V6ZQ==",
|
297
|
+
vapid: {
|
298
|
+
subject: "mailto:sender@example.com"
|
299
|
+
pem: ENV['VAPID_KEYS']
|
300
|
+
}
|
301
|
+
)
|
302
|
+
```
|
303
|
+
|
284
304
|
### With GCM api key
|
285
305
|
|
286
306
|
```ruby
|
data/lib/webpush/request.rb
CHANGED
@@ -70,7 +70,7 @@ module Webpush
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def build_vapid_headers
|
73
|
-
vapid_key = VapidKey.from_keys(vapid_public_key, vapid_private_key)
|
73
|
+
vapid_key = vapid_pem ? VapidKey.from_pem(vapid_pem) : VapidKey.from_keys(vapid_public_key, vapid_private_key)
|
74
74
|
jwt = JWT.encode(jwt_payload, vapid_key.curve, 'ES256', jwt_header_fields)
|
75
75
|
p256ecdsa = vapid_key.public_key_for_push_header
|
76
76
|
|
@@ -138,6 +138,10 @@ module Webpush
|
|
138
138
|
@vapid_options.fetch(:private_key, nil)
|
139
139
|
end
|
140
140
|
|
141
|
+
def vapid_pem
|
142
|
+
@vapid_options.fetch(:pem, nil)
|
143
|
+
end
|
144
|
+
|
141
145
|
def default_options
|
142
146
|
{
|
143
147
|
ttl: 60*60*24*7*4, # 4 weeks
|
data/lib/webpush/vapid_key.rb
CHANGED
@@ -14,6 +14,18 @@ module Webpush
|
|
14
14
|
key
|
15
15
|
end
|
16
16
|
|
17
|
+
# Create a VapidKey instance from pem encoded elliptic curve public and private keys
|
18
|
+
#
|
19
|
+
# @return [Webpush::VapidKey] a VapidKey instance for the given public and private keys
|
20
|
+
def self.from_pem(pem)
|
21
|
+
key = new
|
22
|
+
src = OpenSSL::PKey.read pem
|
23
|
+
key.curve.public_key = src.public_key
|
24
|
+
key.curve.private_key = src.private_key
|
25
|
+
|
26
|
+
key
|
27
|
+
end
|
28
|
+
|
17
29
|
attr_reader :curve
|
18
30
|
|
19
31
|
def initialize
|
@@ -63,6 +75,13 @@ module Webpush
|
|
63
75
|
end
|
64
76
|
alias to_hash to_h
|
65
77
|
|
78
|
+
def to_pem
|
79
|
+
public_key = OpenSSL::PKey::EC.new curve
|
80
|
+
public_key.private_key = nil
|
81
|
+
|
82
|
+
curve.to_pem + public_key.to_pem
|
83
|
+
end
|
84
|
+
|
66
85
|
def inspect
|
67
86
|
"#<#{self.class}:#{object_id.to_s(16)} #{to_h.map { |k, v| ":#{k}=#{v}" }.join(" ")}>"
|
68
87
|
end
|
data/lib/webpush/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webpush
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zaru@sakuraba
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hkdf
|
@@ -168,7 +168,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
- !ruby/object:Gem::Version
|
169
169
|
version: '0'
|
170
170
|
requirements: []
|
171
|
-
|
171
|
+
rubyforge_project:
|
172
|
+
rubygems_version: 2.7.6
|
172
173
|
signing_key:
|
173
174
|
specification_version: 4
|
174
175
|
summary: Encryption Utilities for Web Push payload.
|