pusher 1.3.2 → 2.0.3
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 +5 -5
- data/CHANGELOG.md +96 -66
- data/README.md +86 -34
- data/lib/pusher/channel.rb +9 -0
- data/lib/pusher/client.rb +99 -69
- data/lib/pusher/version.rb +1 -1
- data/lib/pusher.rb +4 -5
- metadata +43 -47
- data/.document +0 -5
- data/.gemtest +0 -0
- data/.gitignore +0 -24
- data/.travis.yml +0 -16
- data/Gemfile +0 -2
- data/Rakefile +0 -11
- data/examples/async_message.rb +0 -28
- data/lib/pusher/native_notification/client.rb +0 -69
- data/pusher.gemspec +0 -33
- data/spec/channel_spec.rb +0 -170
- data/spec/client_spec.rb +0 -668
- data/spec/spec_helper.rb +0 -26
- data/spec/web_hook_spec.rb +0 -117
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 71dc5eb4f9d389dce37f6ec8c1f78390402b31bd94edcb6f22094c70edeb2d72
|
|
4
|
+
data.tar.gz: 3b2d0db0ffe052cbd8c71b252ced1d5910ece64a08100a92c0f17b5ac9b6fa8a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2f644cc58f1b8accd8785eeffc3fc74bad4c20677032455d96e655944ee0818f99802ed339a3f5f9049acd57ea1166817f6c01feba926c9b61256260239c6354
|
|
7
|
+
data.tar.gz: c0d4edd095918225bea29707df4e8e0364b16218c367b40f72c5541fe98232e4698e83e58ea8260b7caeeea54d314ec343ea25050f1f7847747d01a003c68221
|
data/CHANGELOG.md
CHANGED
|
@@ -1,103 +1,133 @@
|
|
|
1
|
-
|
|
2
|
-
==================
|
|
1
|
+
# Changelog
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
* Document raised exception in the `authenticate` method
|
|
6
|
-
* Fixes em-http-request from using v2.5.0 of `addressable` breaking builds.
|
|
3
|
+
## 2.0.3
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
==================
|
|
5
|
+
* [FIXED] Corrected the channels limit when publishing events. Upped from 10 to 100.
|
|
10
6
|
|
|
11
|
-
|
|
7
|
+
## 2.0.2
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
==================
|
|
9
|
+
* [CHANGED] made encryption_master_key_base64 globally configurable
|
|
15
10
|
|
|
16
|
-
|
|
11
|
+
## 2.0.1
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
==================
|
|
13
|
+
* [CHANGED] Only include lib and essential docs in gem.
|
|
20
14
|
|
|
21
|
-
|
|
15
|
+
## 2.0.0
|
|
22
16
|
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
* [CHANGED] Use TLS by default.
|
|
18
|
+
* [REMOVED] Support for Ruby 2.4 and 2.5.
|
|
19
|
+
* [FIXED] Handle empty or nil configuration.
|
|
20
|
+
* [REMOVED] Legacy Push Notification integration.
|
|
21
|
+
* [ADDED] Stalebot and Github actions.
|
|
22
|
+
|
|
23
|
+
## 1.4.3
|
|
25
24
|
|
|
26
|
-
*
|
|
25
|
+
* [FIXED] Remove newline from end of base64 encoded strings, some decoders don't like
|
|
26
|
+
them.
|
|
27
27
|
|
|
28
|
-
1.
|
|
28
|
+
## 1.4.2
|
|
29
29
|
==================
|
|
30
30
|
|
|
31
|
-
*
|
|
31
|
+
* [FIXED] Return `shared_secret` to support authenticating encrypted channels. Thanks
|
|
32
|
+
@Benjaminpjacobs
|
|
32
33
|
|
|
33
|
-
1.
|
|
34
|
-
==================
|
|
34
|
+
## 1.4.1
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
* [CHANGED] Remove rbnacl from dependencies so we don't get errors when it isn't
|
|
37
|
+
required. Thanks @y-yagi!
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
==================
|
|
39
|
+
## 1.4.0
|
|
41
40
|
|
|
42
|
-
*
|
|
43
|
-
* Improve error handling on missing config
|
|
41
|
+
* [ADDED] Support for end-to-end encryption.
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
==================
|
|
43
|
+
## 1.3.3
|
|
47
44
|
|
|
48
|
-
*
|
|
45
|
+
* [CHANGED] Rewording to clarify "Pusher Channels" or simply "Channels" product name.
|
|
49
46
|
|
|
50
|
-
|
|
51
|
-
==================
|
|
47
|
+
## 1.3.2
|
|
52
48
|
|
|
53
|
-
*
|
|
54
|
-
*
|
|
49
|
+
* [FIXED] Return a specific error for "Request Entity Too Large" (body over 10KB).
|
|
50
|
+
* [ADDED] Add a `use_tls` option for SSL (defaults to false).
|
|
51
|
+
* [ADDED] Add a `from_url` client method (in addition to existing `from_env` option).
|
|
52
|
+
* [CHANGED] Improved documentation and fixed typos.
|
|
53
|
+
* [ADDED] Add Ruby 2.4 to test matrix.
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
==================
|
|
55
|
+
## 1.3.1
|
|
58
56
|
|
|
59
|
-
*
|
|
60
|
-
*
|
|
57
|
+
* [FIXED] Added missing client batch methods to default client delegations
|
|
58
|
+
* [CHANGED] Document raised exception in the `authenticate` method
|
|
59
|
+
* [FIXED] Fixes em-http-request from using v2.5.0 of `addressable` breaking builds.
|
|
61
60
|
|
|
62
|
-
|
|
63
|
-
==================
|
|
61
|
+
## 1.3.0
|
|
64
62
|
|
|
65
|
-
*
|
|
63
|
+
* [ADDED] Add support for sending push notifications on up to 10 interests.
|
|
66
64
|
|
|
67
|
-
|
|
68
|
-
==================
|
|
65
|
+
## 1.2.1
|
|
69
66
|
|
|
70
|
-
*
|
|
71
|
-
This is prefered over the older `Pusher['a_channel'].authenticate(...)` style.
|
|
67
|
+
* [FIXED] Fixes Rails 5 compatibility. Use duck-typing to detect request object
|
|
72
68
|
|
|
73
|
-
|
|
74
|
-
==================
|
|
75
|
-
* Updated to use the `pusher-signature` gem instead of `signature`.
|
|
76
|
-
This resolves namespace related issues.
|
|
69
|
+
## 1.2.0
|
|
77
70
|
|
|
78
|
-
|
|
79
|
-
==================
|
|
71
|
+
* [CHANGED] Minor release for Native notifications
|
|
80
72
|
|
|
81
|
-
|
|
73
|
+
## 1.2.0.rc1
|
|
82
74
|
|
|
83
|
-
|
|
84
|
-
==================
|
|
75
|
+
* [ADDED] Add support for Native notifications
|
|
85
76
|
|
|
86
|
-
|
|
87
|
-
* SECURITY: Prevent POODLE. Disable SSLv3, update httpclient to v2.5
|
|
88
|
-
* Fix channel name character limit.
|
|
89
|
-
* Adds support for listing users on a presence channel
|
|
77
|
+
## 1.1.0
|
|
90
78
|
|
|
91
|
-
|
|
92
|
-
==================
|
|
79
|
+
* [ADDED] Add support for batch events
|
|
93
80
|
|
|
94
|
-
|
|
81
|
+
## 1.0.0
|
|
95
82
|
|
|
96
|
-
|
|
97
|
-
|
|
83
|
+
* [CHANGED] No breaking changes, this release is just to follow semver and show that we
|
|
84
|
+
are stable.
|
|
85
|
+
|
|
86
|
+
## 0.18.0
|
|
87
|
+
|
|
88
|
+
* [ADDED] Introduce `Pusher::Client.from_env`
|
|
89
|
+
* [FIXED] Improve error handling on missing config
|
|
90
|
+
|
|
91
|
+
## 0.17.0
|
|
92
|
+
|
|
93
|
+
* [ADDED] Introduce the `cluster` option.
|
|
94
|
+
|
|
95
|
+
## 0.16.0
|
|
96
|
+
|
|
97
|
+
* [CHANGED] Bump httpclient version to 2.7
|
|
98
|
+
* [REMOVED] Ruby 1.8.7 is not supported anymore.
|
|
99
|
+
|
|
100
|
+
## 0.15.2
|
|
101
|
+
|
|
102
|
+
* [CHANGED] Documented `Pusher.channel_info`, `Pusher.channels`
|
|
103
|
+
* [ADDED] Added `Pusher.channel_users`
|
|
104
|
+
|
|
105
|
+
## 0.15.1
|
|
106
|
+
|
|
107
|
+
* [FIXED] Fixed a bug where the `authenticate` method added in 0.15.0 wasn't exposed on the Pusher class.
|
|
108
|
+
|
|
109
|
+
## 0.15.0
|
|
110
|
+
|
|
111
|
+
* [ADDED] Added `Pusher.authenticate` method for authenticating private and presence channels.
|
|
112
|
+
This is prefered over the older `Pusher['a_channel'].authenticate(...)` style.
|
|
113
|
+
|
|
114
|
+
## 0.14.6
|
|
115
|
+
|
|
116
|
+
* [CHANGED] Updated to use the `pusher-signature` gem instead of `signature`.
|
|
117
|
+
This resolves namespace related issues.
|
|
118
|
+
|
|
119
|
+
## 0.14.5
|
|
120
|
+
|
|
121
|
+
* [SECURITY] Prevent auth delegation trough crafted socket IDs
|
|
122
|
+
|
|
123
|
+
## 0.14.4
|
|
98
124
|
|
|
99
|
-
|
|
125
|
+
* [SECURITY] Prevent timing attack, update signature to v0.1.8
|
|
126
|
+
* [SECURITY] Prevent POODLE. Disable SSLv3, update httpclient to v2.5
|
|
127
|
+
* [FIXED] Fix channel name character limit.
|
|
128
|
+
* [ADDED] Adds support for listing users on a presence channel
|
|
100
129
|
|
|
101
|
-
|
|
102
|
-
* Fix limited channel count at README.md. Thanks @tricknotes
|
|
130
|
+
## 0.14.2
|
|
103
131
|
|
|
132
|
+
* [CHANGED] Bump httpclient to v2.4. See #62 (POODLE SSL)
|
|
133
|
+
* [CHANGED] Fix limited channel count at README.md. Thanks @tricknotes
|
data/README.md
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
# Gem for Pusher Channels
|
|
2
2
|
|
|
3
|
-
This Gem provides a Ruby interface to [the Pusher HTTP API for Pusher Channels](https://pusher.com/docs/
|
|
3
|
+
This Gem provides a Ruby interface to [the Pusher HTTP API for Pusher Channels](https://pusher.com/docs/channels/library_auth_reference/rest-api).
|
|
4
4
|
|
|
5
|
-
[](https://github.com/pusher/pusher-http-ruby/actions?query=workflow%3ATests+branch%3Amaster) [](https://rubygems.org/gems/pusher) [](https://rubygems.org/gems/pusher)
|
|
6
|
+
|
|
7
|
+
## Supported Platforms
|
|
8
|
+
|
|
9
|
+
* Ruby - supports **Ruby 2.6 or greater**.
|
|
6
10
|
|
|
7
11
|
## Installation and Configuration
|
|
8
12
|
|
|
@@ -18,7 +22,7 @@ or install via gem
|
|
|
18
22
|
gem install pusher
|
|
19
23
|
```
|
|
20
24
|
|
|
21
|
-
After registering at
|
|
25
|
+
After registering at [Pusher](https://dashboard.pusher.com/accounts/sign_up), configure your Channels app with the security credentials.
|
|
22
26
|
|
|
23
27
|
### Instantiating a Pusher Channels client
|
|
24
28
|
|
|
@@ -27,7 +31,7 @@ Creating a new Pusher Channels `client` can be done as follows.
|
|
|
27
31
|
``` ruby
|
|
28
32
|
require 'pusher'
|
|
29
33
|
|
|
30
|
-
|
|
34
|
+
pusher = Pusher::Client.new(
|
|
31
35
|
app_id: 'your-app-id',
|
|
32
36
|
key: 'your-app-key',
|
|
33
37
|
secret: 'your-app-secret',
|
|
@@ -36,14 +40,14 @@ channels_client = Pusher::Client.new(
|
|
|
36
40
|
)
|
|
37
41
|
```
|
|
38
42
|
|
|
39
|
-
The `cluster` value will set the `host` to `api-<cluster>.pusher.com`. The `use_tls` value is optional and defaults to `
|
|
43
|
+
The `cluster` value will set the `host` to `api-<cluster>.pusher.com`. The `use_tls` value is optional and defaults to `true`. It will set the `scheme` and `port`. A custom `port` value takes precendence over `use_tls`.
|
|
40
44
|
|
|
41
45
|
If you want to set a custom `host` value for your client then you can do so when instantiating a Pusher Channels client like so:
|
|
42
46
|
|
|
43
47
|
``` ruby
|
|
44
48
|
require 'pusher'
|
|
45
49
|
|
|
46
|
-
|
|
50
|
+
pusher = Pusher::Client.new(
|
|
47
51
|
app_id: 'your-app-id',
|
|
48
52
|
key: 'your-app-key',
|
|
49
53
|
secret: 'your-app-secret',
|
|
@@ -57,12 +61,12 @@ Finally, if you have the configuration set in an `PUSHER_URL` environment
|
|
|
57
61
|
variable, you can use:
|
|
58
62
|
|
|
59
63
|
``` ruby
|
|
60
|
-
|
|
64
|
+
pusher = Pusher::Client.from_env
|
|
61
65
|
```
|
|
62
66
|
|
|
63
67
|
### Global configuration
|
|
64
68
|
|
|
65
|
-
|
|
69
|
+
The library can also be configured globally on the `Pusher` class.
|
|
66
70
|
|
|
67
71
|
``` ruby
|
|
68
72
|
Pusher.app_id = 'your-app-id'
|
|
@@ -79,11 +83,11 @@ If you need to make requests via a HTTP proxy then it can be configured
|
|
|
79
83
|
Pusher.http_proxy = 'http://(user):(password)@(host):(port)'
|
|
80
84
|
```
|
|
81
85
|
|
|
82
|
-
By default API requests are made over
|
|
86
|
+
By default API requests are made over HTTPS. HTTP can be used by setting `use_tls` to `false`.
|
|
83
87
|
Issuing this command is going to reset `port` value if it was previously specified.
|
|
84
88
|
|
|
85
89
|
``` ruby
|
|
86
|
-
Pusher.
|
|
90
|
+
Pusher.use_tls = false
|
|
87
91
|
```
|
|
88
92
|
|
|
89
93
|
As of version 0.12, SSL certificates are verified when using the synchronous http client. If you need to disable this behaviour for any reason use:
|
|
@@ -92,9 +96,9 @@ As of version 0.12, SSL certificates are verified when using the synchronous htt
|
|
|
92
96
|
Pusher.default_client.sync_http_client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
93
97
|
```
|
|
94
98
|
|
|
95
|
-
## Interacting with the
|
|
99
|
+
## Interacting with the Channels HTTP API
|
|
96
100
|
|
|
97
|
-
The
|
|
101
|
+
The `pusher` gem contains a number of helpers for interacting with the API. As a general rule, the library adheres to a set of conventions that we have aimed to make universal.
|
|
98
102
|
|
|
99
103
|
### Handling errors
|
|
100
104
|
|
|
@@ -102,7 +106,7 @@ Handle errors by rescuing `Pusher::Error` (all errors are descendants of this er
|
|
|
102
106
|
|
|
103
107
|
``` ruby
|
|
104
108
|
begin
|
|
105
|
-
|
|
109
|
+
pusher.trigger('a_channel', 'an_event', :some => 'data')
|
|
106
110
|
rescue Pusher::Error => e
|
|
107
111
|
# (Pusher::AuthenticationError, Pusher::HTTPError, or Pusher::Error)
|
|
108
112
|
end
|
|
@@ -121,14 +125,14 @@ Pusher.logger = Rails.logger
|
|
|
121
125
|
An event can be published to one or more channels (limited to 10) in one API call:
|
|
122
126
|
|
|
123
127
|
``` ruby
|
|
124
|
-
|
|
125
|
-
|
|
128
|
+
pusher.trigger('channel', 'event', foo: 'bar')
|
|
129
|
+
pusher.trigger(['channel_1', 'channel_2'], 'event_name', foo: 'bar')
|
|
126
130
|
```
|
|
127
131
|
|
|
128
|
-
An optional fourth argument may be used to send additional parameters to the API, for example to [exclude a single connection from receiving the event](
|
|
132
|
+
An optional fourth argument may be used to send additional parameters to the API, for example to [exclude a single connection from receiving the event](https://pusher.com/docs/channels/server_api/excluding-event-recipients).
|
|
129
133
|
|
|
130
134
|
``` ruby
|
|
131
|
-
|
|
135
|
+
pusher.trigger('channel', 'event', {foo: 'bar'}, {socket_id: '123.456'})
|
|
132
136
|
```
|
|
133
137
|
|
|
134
138
|
#### Batches
|
|
@@ -137,7 +141,7 @@ It's also possible to send multiple events with a single API call (max 10
|
|
|
137
141
|
events per call on multi-tenant clusters):
|
|
138
142
|
|
|
139
143
|
``` ruby
|
|
140
|
-
|
|
144
|
+
pusher.trigger_batch([
|
|
141
145
|
{channel: 'channel_1', name: 'event_name', data: { foo: 'bar' }},
|
|
142
146
|
{channel: 'channel_1', name: 'event_name', data: { hello: 'world' }}
|
|
143
147
|
])
|
|
@@ -151,36 +155,36 @@ Most examples and documentation will refer to the following syntax for triggerin
|
|
|
151
155
|
Pusher['a_channel'].trigger('an_event', :some => 'data')
|
|
152
156
|
```
|
|
153
157
|
|
|
154
|
-
This will continue to work, but has been replaced by `
|
|
158
|
+
This will continue to work, but has been replaced by `pusher.trigger` which supports one or multiple channels.
|
|
155
159
|
|
|
156
160
|
### Getting information about the channels in your Pusher Channels app
|
|
157
161
|
|
|
158
|
-
This gem provides methods for accessing information from the [
|
|
162
|
+
This gem provides methods for accessing information from the [Channels HTTP API](https://pusher.com/docs/channels/library_auth_reference/rest-api). The documentation also shows an example of the responses from each of the API endpoints.
|
|
159
163
|
|
|
160
164
|
The following methods are provided by the gem.
|
|
161
165
|
|
|
162
|
-
- `
|
|
166
|
+
- `pusher.channel_info('channel_name', {info:"user_count,subscription_count"})` returns a hash describing the state of the channel([docs](https://pusher.com/docs/channels/library_auth_reference/rest-api#get-channels-fetch-info-for-multiple-channels-)).
|
|
163
167
|
|
|
164
|
-
- `
|
|
168
|
+
- `pusher.channel_users('presence-channel_name')` returns a list of all the users subscribed to the channel (only for Presence Channels) ([docs](https://pusher.com/docs/channels/library_auth_reference/rest-api#get-channels-fetch-info-for-multiple-channels-)).
|
|
165
169
|
|
|
166
|
-
- `
|
|
170
|
+
- `pusher.channels({filter_by_prefix: 'presence-', info: 'user_count'})` returns a hash of occupied channels (optionally filtered by prefix, f.i. `presence-`), and optionally attributes for these channels ([docs](https://pusher.com/docs/channels/library_auth_reference/rest-api#get-channels-fetch-info-for-multiple-channels-)).
|
|
167
171
|
|
|
168
172
|
### Asynchronous requests
|
|
169
173
|
|
|
170
174
|
There are two main reasons for using the `_async` methods:
|
|
171
175
|
|
|
172
|
-
* In a web application where the response from the
|
|
176
|
+
* In a web application where the response from the Channels HTTP API is not used, but you'd like to avoid a blocking call in the request-response cycle
|
|
173
177
|
* Your application is running in an event loop and you need to avoid blocking the reactor
|
|
174
178
|
|
|
175
179
|
Asynchronous calls are supported either by using an event loop (eventmachine, preferred), or via a thread.
|
|
176
180
|
|
|
177
181
|
The following methods are available (in each case the calling interface matches the non-async version):
|
|
178
182
|
|
|
179
|
-
* `
|
|
180
|
-
* `
|
|
181
|
-
* `
|
|
183
|
+
* `pusher.get_async`
|
|
184
|
+
* `pusher.post_async`
|
|
185
|
+
* `pusher.trigger_async`
|
|
182
186
|
|
|
183
|
-
It is of course also possible to make calls to the
|
|
187
|
+
It is of course also possible to make calls to the Channels HTTP API via a job queue. This approach is recommended if you're sending a large number of events.
|
|
184
188
|
|
|
185
189
|
#### With EventMachine
|
|
186
190
|
|
|
@@ -190,14 +194,14 @@ It is of course also possible to make calls to the Pusher Channels HTTP API via
|
|
|
190
194
|
The `_async` methods return an `EM::Deferrable` which you can bind callbacks to:
|
|
191
195
|
|
|
192
196
|
``` ruby
|
|
193
|
-
|
|
197
|
+
pusher.get_async("/channels").callback { |response|
|
|
194
198
|
# use reponse[:channels]
|
|
195
199
|
}.errback { |error|
|
|
196
200
|
# error is an instance of Pusher::Error
|
|
197
201
|
}
|
|
198
202
|
```
|
|
199
203
|
|
|
200
|
-
A HTTP error or an error response from
|
|
204
|
+
A HTTP error or an error response from Channels will cause the errback to be called with an appropriate error object.
|
|
201
205
|
|
|
202
206
|
#### Without EventMachine
|
|
203
207
|
|
|
@@ -208,12 +212,12 @@ An `HTTPClient::Connection` object is returned immediately which can be [interro
|
|
|
208
212
|
|
|
209
213
|
## Authenticating subscription requests
|
|
210
214
|
|
|
211
|
-
It's possible to use the gem to authenticate subscription requests to private or presence channels. The `authenticate` method is available on a channel object for this purpose and returns a JSON object that can be returned to the client that made the request. More information on this authentication scheme can be found in the docs on <
|
|
215
|
+
It's possible to use the gem to authenticate subscription requests to private or presence channels. The `authenticate` method is available on a channel object for this purpose and returns a JSON object that can be returned to the client that made the request. More information on this authentication scheme can be found in the docs on <https://pusher.com/docs/channels/server_api/authenticating-users>
|
|
212
216
|
|
|
213
217
|
### Private channels
|
|
214
218
|
|
|
215
219
|
``` ruby
|
|
216
|
-
|
|
220
|
+
pusher.authenticate('private-my_channel', params[:socket_id])
|
|
217
221
|
```
|
|
218
222
|
|
|
219
223
|
### Presence channels
|
|
@@ -221,7 +225,7 @@ channels_client.authenticate('private-my_channel', params[:socket_id])
|
|
|
221
225
|
These work in a very similar way, but require a unique identifier for the user being authenticated, and optionally some attributes that are provided to clients via presence events:
|
|
222
226
|
|
|
223
227
|
``` ruby
|
|
224
|
-
|
|
228
|
+
pusher.authenticate('presence-my_channel', params[:socket_id],
|
|
225
229
|
user_id: 'user_id',
|
|
226
230
|
user_info: {} # optional
|
|
227
231
|
)
|
|
@@ -232,7 +236,7 @@ channels_client.authenticate('presence-my_channel', params[:socket_id],
|
|
|
232
236
|
A WebHook object may be created to validate received WebHooks against your app credentials, and to extract events. It should be created with the `Rack::Request` object (available as `request` in Rails controllers or Sinatra handlers for example).
|
|
233
237
|
|
|
234
238
|
``` ruby
|
|
235
|
-
webhook =
|
|
239
|
+
webhook = pusher.webhook(request)
|
|
236
240
|
if webhook.valid?
|
|
237
241
|
webhook.events.each do |event|
|
|
238
242
|
case event["name"]
|
|
@@ -247,3 +251,51 @@ else
|
|
|
247
251
|
render text: 'invalid', status: 401
|
|
248
252
|
end
|
|
249
253
|
```
|
|
254
|
+
|
|
255
|
+
### End-to-end encryption
|
|
256
|
+
|
|
257
|
+
This library supports [end-to-end encrypted channels](https://pusher.com/docs/channels/using_channels/encrypted-channels). This means that only you and your connected clients will be able to read your messages. Pusher cannot decrypt them. You can enable this feature by following these steps:
|
|
258
|
+
|
|
259
|
+
1. Add the `rbnacl` gem to your Gemfile (it's not a gem dependency).
|
|
260
|
+
|
|
261
|
+
2. Install [Libsodium](https://github.com/jedisct1/libsodium), which we rely on to do the heavy lifting. [Follow the installation instructions for your platform.](https://github.com/RubyCrypto/rbnacl/wiki/Installing-libsodium)
|
|
262
|
+
|
|
263
|
+
3. Encrypted channel subscriptions must be authenticated in the exact same way as private channels. You should therefore [create an authentication endpoint on your server](https://pusher.com/docs/authenticating_users).
|
|
264
|
+
|
|
265
|
+
4. Next, generate your 32 byte master encryption key, encode it as base64 and pass it to the Pusher constructor.
|
|
266
|
+
|
|
267
|
+
This is secret and you should never share this with anyone.
|
|
268
|
+
Not even Pusher.
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
openssl rand -base64 32
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
```rb
|
|
275
|
+
pusher = new Pusher::Client.new({
|
|
276
|
+
app_id: 'your-app-id',
|
|
277
|
+
key: 'your-app-key',
|
|
278
|
+
secret: 'your-app-secret',
|
|
279
|
+
cluster: 'your-app-cluster',
|
|
280
|
+
use_tls: true
|
|
281
|
+
encryption_master_key_base64: '<KEY GENERATED BY PREVIOUS COMMAND>',
|
|
282
|
+
});
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
5. Channels where you wish to use end-to-end encryption should be prefixed with `private-encrypted-`.
|
|
286
|
+
|
|
287
|
+
6. Subscribe to these channels in your client, and you're done! You can verify it is working by checking out the debug console on the [https://dashboard.pusher.com/](dashboard) and seeing the scrambled ciphertext.
|
|
288
|
+
|
|
289
|
+
**Important note: This will __not__ encrypt messages on channels that are not prefixed by `private-encrypted-`.**
|
|
290
|
+
|
|
291
|
+
**Limitation**: you cannot trigger a single event on multiple channels in a call to `trigger`, e.g.
|
|
292
|
+
|
|
293
|
+
```rb
|
|
294
|
+
pusher.trigger(
|
|
295
|
+
['channel-1', 'private-encrypted-channel-2'],
|
|
296
|
+
'test_event',
|
|
297
|
+
{ message: 'hello world' },
|
|
298
|
+
)
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
Rationale: the methods in this library map directly to individual Channels HTTP API requests. If we allowed triggering a single event on multiple channels (some encrypted, some unencrypted), then it would require two API requests: one where the event is encrypted to the encrypted channels, and one where the event is unencrypted for unencrypted channels.
|
data/lib/pusher/channel.rb
CHANGED
|
@@ -174,6 +174,15 @@ module Pusher
|
|
|
174
174
|
r
|
|
175
175
|
end
|
|
176
176
|
|
|
177
|
+
def shared_secret(encryption_master_key)
|
|
178
|
+
return unless encryption_master_key
|
|
179
|
+
|
|
180
|
+
secret_string = @name + encryption_master_key
|
|
181
|
+
digest = OpenSSL::Digest::SHA256.new
|
|
182
|
+
digest << secret_string
|
|
183
|
+
digest.digest
|
|
184
|
+
end
|
|
185
|
+
|
|
177
186
|
private
|
|
178
187
|
|
|
179
188
|
def validate_socket_id(socket_id)
|