@@ -136,73 +136,16 @@ def users_info(self, channel):
136136 return self ._pusher_client .users_info (channel )
137137
138138
139- @doc_string (NotificationClient .notify .__doc__ )
140- def notify (self , interest , notification ):
141- return self ._notification_client .notify (interest , notification )
142-
143-
139+ @doc_string (PusherClient .authenticate .__doc__ )
144140 def authenticate (self , channel , socket_id , custom_data = None ):
145- """Used to generate delegated client subscription token.
146-
147- :param channel: name of the channel to authorize subscription to
148- :param socket_id: id of the socket that requires authorization
149- :param custom_data: used on presence channels to provide user info
150- """
151- channel = validate_channel (channel )
152-
153- if not channel_name_re .match (channel ):
154- raise ValueError ('Channel should be a valid channel, got: %s' % channel )
155-
156- socket_id = validate_socket_id (socket_id )
157-
158- if custom_data :
159- custom_data = json .dumps (custom_data , cls = self ._json_encoder )
160-
161- string_to_sign = "%s:%s" % (socket_id , channel )
162-
163- if custom_data :
164- string_to_sign += ":%s" % custom_data
165-
166- signature = sign (self .secret , string_to_sign )
141+ return self .pusher_client .authenticate (channel , socket_id , custom_data )
167142
168- auth = "%s:%s" % (self .key , signature )
169- result = {'auth' : auth }
170143
171- if custom_data :
172- result ['channel_data' ] = custom_data
144+ @doc_string (PusherClient .validate_webhook .__doc__ )
145+ def authenticate (self , key , signature , body ):
146+ return self .pusher_client .validate_webhook (key , signature , body )
173147
174- return result
175148
176-
177- def validate_webhook (self , key , signature , body ):
178- """Used to validate incoming webhook messages. When used it guarantees
179- that the sender is Pusher and not someone else impersonating it.
180-
181- :param key: key used to sign the body
182- :param signature: signature that was given with the body
183- :param body: content that needs to be verified
184- """
185- key = ensure_text (key , "key" )
186- signature = ensure_text (signature , "signature" )
187- body = ensure_text (body , "body" )
188-
189- if key != self .key :
190- return None
191-
192- if not verify (self .secret , body , signature ):
193- return None
194-
195- try :
196- body_data = json .loads (body , cls = self ._json_decoder )
197-
198- except ValueError :
199- return None
200-
201- time_ms = body_data .get ('time_ms' )
202- if not time_ms :
203- return None
204-
205- if abs (time .time ()* 1000 - time_ms ) > 300000 :
206- return None
207-
208- return body_data
149+ @doc_string (NotificationClient .notify .__doc__ )
150+ def notify (self , interest , notification ):
151+ return self ._notification_client .notify (interest , notification )
0 commit comments