
    ,Ii                         S SK JrJrJrJr  S SKrS SKrS SKrS SKrS SK	r	S SK
r
S SKrS SKrS SKJrJrJrJrJr  S SKJr  S SKJrJrJrJr  S SKJrJr  S SK7   " S S	\5      rg)
    )print_functionunicode_literalsabsolute_importdivisionN)ensure_textensure_binaryvalidate_channelvalidate_socket_idchannel_name_re)Client)GETPOSTRequestrequest_method)signverify)*c                   P   ^  \ rS rSr          SU 4S jjrSS jrS rSrU =r$ )AuthenticationClient    c                 H   > [         [        U ]
  " UUUUUUUUU	U
UUU40 UD6  g N)superr   __init__)selfapp_idkeysecretsslhostporttimeoutclusterencryption_master_keyencryption_master_key_base64json_encoderjson_decoderbackendbackend_options	__class__s                  B/venv/lib/python3.13/site-packages/pusher/authentication_client.pyr   AuthenticationClient.__init__!   sF    " 	"D2!(	 	    c                    [        U5      n[        R                  " U5      (       d  [        SU-  5      e[	        U5      nU(       a  [
        R                  " X0R                  S9nU< SU< 3nU(       a  USU-  -  n[        U R                  U5      nU R                  < SU< 3nSU0n[        U5      (       a:  [        [        US5      U R                  5      n[        R                   " U5      n	XS'   U(       a  X7S'   U$ )	zUsed to generate delegated client subscription token.

:param channel: name of the channel to authorize subscription to
:param socket_id: id of the socket that requires authorization
:param custom_data: used on presence channels to provide user info
z*Channel should be a valid channel, got: %scls:z:%sauthchannelshared_secretchannel_data)r	   r   match
ValueErrorr
   jsondumps_json_encoderr   r   r   is_encrypted_channelgenerate_shared_secretr   _encryption_master_keybase64	b64encode)
r   r3   	socket_idcustom_datastring_to_sign	signaturer2   response_payloadr4   shared_secret_b64s
             r+   authenticate!AuthenticationClient.authenticateC   s     #7+$$W--IGSTT&y1	**[6H6HIK$-w7ek11Nn5	((I.#T+((2gy143N3NPM & 0 0 ?0A_-/:^,r-   c                    [        US5      n[        US5      n[        US5      nXR                  :w  a  g[        U R                  X25      (       d  g [        R
                  " X0R                  S9nUR                  S5      nU(       d  g[        [        R                  " 5       S-  U-
  5      S:  a  gU$ ! [         a     gf = f)	a  Used to validate incoming webhook messages. When used it guarantees
that the sender is Pusher and not someone else impersonating it.

:param key: key used to sign the body
:param signature: signature that was given with the body
:param body: content that needs to be verified
r   rC   bodyNr/   time_msi  i )r   r   r   r   r8   loads_json_decoderr7   getabstime)r   r   rC   rI   	body_datarJ   s         r+   validate_webhook%AuthenticationClient.validate_webhookj   s     #u%	;7	4(((?dkk433	

4-?-?@I
 --	*tyy{4')*V3  		s   B4 4
C C )
TNN   NNNNNNr   )	__name__
__module____qualname____firstlineno__r   rF   rQ   __static_attributes____classcell__)r*   s   @r+   r   r       s9     "&)-D$ N r-   r   )
__future__r   r   r   r   collectionshashlibr8   osresixrO   r>   pusher.utilr   r   r	   r
   r   pusher.clientr   pusher.httpr   r   r   r   pusher.signaturer   r   pusher.cryptor   rS   r-   r+   <module>rf      sR        	 	 
    ! : : ) i6 ir-   