pusher-platform 0.11.1 → 0.11.2
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/lib/pusher-platform/authenticator.rb +6 -3
- data/lib/pusher-platform/rack_query_parser.rb +218 -0
- metadata +4 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c6548b5f0d008ddd0747ad6c9555eab299cc5290
|
4
|
+
data.tar.gz: 983c96520cd1f1170be45485f7f01436e910e3b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 684ebbf7f39b9c23e972dc281532039f60a8942e296984fdaf97427492eb0026438728c8956fb77ee6447bb1aa39d757914ff1930f05e0d0a37e61557eba6115
|
7
|
+
data.tar.gz: 7e9a19ba538b364df7dfa5eea2ad834be0090f06196dcd5481b5470c04c25df9dd5423a590cdf0f5bb8a93b9da28c442439f8339b9dfd8bac698f62610823089
|
@@ -1,16 +1,19 @@
|
|
1
1
|
require 'jwt'
|
2
|
-
require 'rack'
|
3
2
|
require_relative './common'
|
4
3
|
require_relative './authentication_response'
|
4
|
+
require_relative './rack_query_parser'
|
5
5
|
|
6
6
|
module PusherPlatform
|
7
7
|
TOKEN_EXPIRY = 24*60*60
|
8
8
|
|
9
9
|
class Authenticator
|
10
|
+
|
10
11
|
def initialize(instance_id, key_id, key_secret)
|
11
12
|
@instance_id = instance_id
|
12
13
|
@key_id = key_id
|
13
14
|
@key_secret = key_secret
|
15
|
+
# see https://github.com/rack/rack/blob/5559676e7b5a3107d39552285ce8b714b672bde6/lib/rack/utils.rb#L27
|
16
|
+
@query_parser = QueryParser.make_default(65536, 100)
|
14
17
|
end
|
15
18
|
|
16
19
|
def authenticate(auth_payload, options)
|
@@ -30,7 +33,7 @@ module PusherPlatform
|
|
30
33
|
end
|
31
34
|
|
32
35
|
def authenticate_with_request(request, options)
|
33
|
-
auth_data =
|
36
|
+
auth_data = @query_parser.parse_nested_query request.body.read
|
34
37
|
authenticate(auth_data, options)
|
35
38
|
end
|
36
39
|
|
@@ -39,7 +42,7 @@ module PusherPlatform
|
|
39
42
|
end
|
40
43
|
|
41
44
|
def authenticate_with_refresh_token_and_request(request, options)
|
42
|
-
auth_data =
|
45
|
+
auth_data = @query_parser.parse_nested_query request.body.read
|
43
46
|
authenticate_based_on_grant_type(auth_data, options)
|
44
47
|
end
|
45
48
|
|
@@ -0,0 +1,218 @@
|
|
1
|
+
# Taken from https://github.com/rack/rack
|
2
|
+
# sha: 5559676e7b5a3107d39552285ce8b714b672bde6
|
3
|
+
#
|
4
|
+
# The MIT License (MIT)
|
5
|
+
#
|
6
|
+
# Copyright (C) 2007-2018 Christian Neukirchen <http://chneukirchen.org/infopage.html>
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
# of this software and associated documentation files (the "Software"), to
|
10
|
+
# deal in the Software without restriction, including without limitation the
|
11
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
12
|
+
# sell copies of the Software, and to permit persons to whom the Software is
|
13
|
+
# furnished to do so, subject to the following conditions:
|
14
|
+
#
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
16
|
+
# all copies or substantial portions of the Software.
|
17
|
+
#
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
21
|
+
# THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
22
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
23
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
|
25
|
+
require 'uri'
|
26
|
+
|
27
|
+
module PusherPlatform
|
28
|
+
class QueryParser
|
29
|
+
DEFAULT_SEP = /[&;] */n
|
30
|
+
COMMON_SEP = { ";" => /[;] */n, ";," => /[;,] */n, "&" => /[&] */n }
|
31
|
+
|
32
|
+
# ParameterTypeError is the error that is raised when incoming structural
|
33
|
+
# parameters (parsed by parse_nested_query) contain conflicting types.
|
34
|
+
class ParameterTypeError < TypeError; end
|
35
|
+
|
36
|
+
# InvalidParameterError is the error that is raised when incoming structural
|
37
|
+
# parameters (parsed by parse_nested_query) contain invalid format or byte
|
38
|
+
# sequence.
|
39
|
+
class InvalidParameterError < ArgumentError; end
|
40
|
+
|
41
|
+
def self.make_default(key_space_limit, param_depth_limit)
|
42
|
+
new Params, key_space_limit, param_depth_limit
|
43
|
+
end
|
44
|
+
|
45
|
+
attr_reader :key_space_limit, :param_depth_limit
|
46
|
+
|
47
|
+
def initialize(params_class, key_space_limit, param_depth_limit)
|
48
|
+
@params_class = params_class
|
49
|
+
@key_space_limit = key_space_limit
|
50
|
+
@param_depth_limit = param_depth_limit
|
51
|
+
end
|
52
|
+
|
53
|
+
# Stolen from Mongrel, with some small modifications:
|
54
|
+
# Parses a query string by breaking it up at the '&'
|
55
|
+
# and ';' characters. You can also use this to parse
|
56
|
+
# cookies by changing the characters used in the second
|
57
|
+
# parameter (which defaults to '&;').
|
58
|
+
def parse_query(qs, d = nil, &unescaper)
|
59
|
+
unescaper ||= method(:unescape)
|
60
|
+
|
61
|
+
params = make_params
|
62
|
+
|
63
|
+
(qs || '').split(d ? (COMMON_SEP[d] || /[#{d}] */n) : DEFAULT_SEP).each do |p|
|
64
|
+
next if p.empty?
|
65
|
+
k, v = p.split('=', 2).map!(&unescaper)
|
66
|
+
|
67
|
+
if cur = params[k]
|
68
|
+
if cur.class == Array
|
69
|
+
params[k] << v
|
70
|
+
else
|
71
|
+
params[k] = [cur, v]
|
72
|
+
end
|
73
|
+
else
|
74
|
+
params[k] = v
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
return params.to_params_hash
|
79
|
+
end
|
80
|
+
|
81
|
+
# parse_nested_query expands a query string into structural types. Supported
|
82
|
+
# types are Arrays, Hashes and basic value types. It is possible to supply
|
83
|
+
# query strings with parameters of conflicting types, in this case a
|
84
|
+
# ParameterTypeError is raised. Users are encouraged to return a 400 in this
|
85
|
+
# case.
|
86
|
+
def parse_nested_query(qs, d = nil)
|
87
|
+
return {} if qs.nil? || qs.empty?
|
88
|
+
params = make_params
|
89
|
+
|
90
|
+
(qs || '').split(d ? (COMMON_SEP[d] || /[#{d}] */n) : DEFAULT_SEP).each do |p|
|
91
|
+
k, v = p.split('=', 2).map! { |s| unescape(s) }
|
92
|
+
|
93
|
+
normalize_params(params, k, v, param_depth_limit)
|
94
|
+
end
|
95
|
+
|
96
|
+
return params.to_params_hash
|
97
|
+
rescue ArgumentError => e
|
98
|
+
raise InvalidParameterError, e.message
|
99
|
+
end
|
100
|
+
|
101
|
+
# normalize_params recursively expands parameters into structural types. If
|
102
|
+
# the structural types represented by two different parameter names are in
|
103
|
+
# conflict, a ParameterTypeError is raised.
|
104
|
+
def normalize_params(params, name, v, depth)
|
105
|
+
raise RangeError if depth <= 0
|
106
|
+
|
107
|
+
name =~ %r(\A[\[\]]*([^\[\]]+)\]*)
|
108
|
+
k = $1 || ''
|
109
|
+
after = $' || ''
|
110
|
+
|
111
|
+
if k.empty?
|
112
|
+
if !v.nil? && name == "[]"
|
113
|
+
return Array(v)
|
114
|
+
else
|
115
|
+
return
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
if after == ''
|
120
|
+
params[k] = v
|
121
|
+
elsif after == "["
|
122
|
+
params[name] = v
|
123
|
+
elsif after == "[]"
|
124
|
+
params[k] ||= []
|
125
|
+
raise ParameterTypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array)
|
126
|
+
params[k] << v
|
127
|
+
elsif after =~ %r(^\[\]\[([^\[\]]+)\]$) || after =~ %r(^\[\](.+)$)
|
128
|
+
child_key = $1
|
129
|
+
params[k] ||= []
|
130
|
+
raise ParameterTypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array)
|
131
|
+
if params_hash_type?(params[k].last) && !params_hash_has_key?(params[k].last, child_key)
|
132
|
+
normalize_params(params[k].last, child_key, v, depth - 1)
|
133
|
+
else
|
134
|
+
params[k] << normalize_params(make_params, child_key, v, depth - 1)
|
135
|
+
end
|
136
|
+
else
|
137
|
+
params[k] ||= make_params
|
138
|
+
raise ParameterTypeError, "expected Hash (got #{params[k].class.name}) for param `#{k}'" unless params_hash_type?(params[k])
|
139
|
+
params[k] = normalize_params(params[k], after, v, depth - 1)
|
140
|
+
end
|
141
|
+
|
142
|
+
params
|
143
|
+
end
|
144
|
+
|
145
|
+
def make_params
|
146
|
+
@params_class.new @key_space_limit
|
147
|
+
end
|
148
|
+
|
149
|
+
def new_space_limit(key_space_limit)
|
150
|
+
self.class.new @params_class, key_space_limit, param_depth_limit
|
151
|
+
end
|
152
|
+
|
153
|
+
def new_depth_limit(param_depth_limit)
|
154
|
+
self.class.new @params_class, key_space_limit, param_depth_limit
|
155
|
+
end
|
156
|
+
|
157
|
+
private
|
158
|
+
|
159
|
+
def params_hash_type?(obj)
|
160
|
+
obj.kind_of?(@params_class)
|
161
|
+
end
|
162
|
+
|
163
|
+
def params_hash_has_key?(hash, key)
|
164
|
+
return false if key =~ /\[\]/
|
165
|
+
|
166
|
+
key.split(/[\[\]]+/).inject(hash) do |h, part|
|
167
|
+
next h if part == ''
|
168
|
+
return false unless params_hash_type?(h) && h.key?(part)
|
169
|
+
h[part]
|
170
|
+
end
|
171
|
+
|
172
|
+
true
|
173
|
+
end
|
174
|
+
|
175
|
+
def unescape(s)
|
176
|
+
URI.decode_www_form_component(s, Encoding::UTF_8)
|
177
|
+
end
|
178
|
+
|
179
|
+
class Params
|
180
|
+
def initialize(limit)
|
181
|
+
@limit = limit
|
182
|
+
@size = 0
|
183
|
+
@params = {}
|
184
|
+
end
|
185
|
+
|
186
|
+
def [](key)
|
187
|
+
@params[key]
|
188
|
+
end
|
189
|
+
|
190
|
+
def []=(key, value)
|
191
|
+
@size += key.size if key && !@params.key?(key)
|
192
|
+
raise RangeError, 'exceeded available parameter key space' if @size > @limit
|
193
|
+
@params[key] = value
|
194
|
+
end
|
195
|
+
|
196
|
+
def key?(key)
|
197
|
+
@params.key?(key)
|
198
|
+
end
|
199
|
+
|
200
|
+
def to_params_hash
|
201
|
+
hash = @params
|
202
|
+
hash.keys.each do |key|
|
203
|
+
value = hash[key]
|
204
|
+
if value.kind_of?(self.class)
|
205
|
+
if value.object_id == self.object_id
|
206
|
+
hash[key] = hash
|
207
|
+
else
|
208
|
+
hash[key] = value.to_params_hash
|
209
|
+
end
|
210
|
+
elsif value.kind_of?(Array)
|
211
|
+
value.map! {|x| x.kind_of?(self.class) ? x.to_params_hash : x}
|
212
|
+
end
|
213
|
+
end
|
214
|
+
hash
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pusher-platform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pusher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.1'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rack
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 2.0.5
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 2.0.5
|
55
41
|
description:
|
56
42
|
email: support@pusher.com
|
57
43
|
executables: []
|
@@ -66,6 +52,7 @@ files:
|
|
66
52
|
- lib/pusher-platform/error.rb
|
67
53
|
- lib/pusher-platform/error_response.rb
|
68
54
|
- lib/pusher-platform/instance.rb
|
55
|
+
- lib/pusher-platform/rack_query_parser.rb
|
69
56
|
- lib/pusher-platform/sdk_info.rb
|
70
57
|
homepage:
|
71
58
|
licenses:
|
@@ -87,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
74
|
version: '0'
|
88
75
|
requirements: []
|
89
76
|
rubyforge_project:
|
90
|
-
rubygems_version: 2.
|
77
|
+
rubygems_version: 2.5.2.3
|
91
78
|
signing_key:
|
92
79
|
specification_version: 4
|
93
80
|
summary: Pusher Platform Ruby SDK
|