a
    !f                     @   s<   d dl mZ d dlmZ G dd deZG dd deZdS )    )Jwt)	urlencodec                       sN   e Zd ZdZdZejddf fdd	Zdd Zd	d
 Z	dd Z
dd Z  ZS )ClientCapabilityTokenz1A token to control permissions with Twilio ClientZHS256i  Nc                    s   t t| j| j||||dd || _|| _d| _i | _d|v rR| jf i |d  d|v rn| j	f i |d  d|v r| j
f i |d  dS )a  
        :param str account_sid: The account sid to which this token is granted access.
        :param str auth_token: The secret key used to sign the token. Note, this auth token is not
                               visible to the user of the token.
        :param int nbf: Time in secs from epic before which this token is considered invalid.
        :param int ttl: the amount of time in seconds from generation that this token is valid for.
        :param kwargs:


        :returns: A new CapabilityToken with zero permissions
        N)	algorithmZ
secret_keyZissuernbfttlvalid_untilallow_client_outgoingallow_client_incomingallow_event_stream)superr   __init__	ALGORITHMaccount_sid
auth_tokenclient_namecapabilitiesr	   r
   r   )selfr   r   r   r   r   kwargs	__class__ [/var/www/html/python-backend/venv/lib/python3.9/site-packages/twilio/jwt/client/__init__.pyr      s$    
	zClientCapabilityToken.__init__c                 K   s6   t ddd|i}|r(|dt|dd || jd< dS )z
        Allow the user of this token to make outgoing connections. Keyword arguments are passed
        to the application.

        :param str application_sid: Application to contact
        clientoutgoingZappSidZ	appParamsTdoseqNScopeURI	add_paramr   r   )r   Zapplication_sidr   scoper   r   r   r	   4   s    z+ClientCapabilityToken.allow_client_outgoingc                 C   s    || _ tddd|i| jd< dS )z
        Allow the user of this token to accept incoming connections.

        :param str client_name: Client name to accept calls from
        r   incoming
clientNameN)r   r   r   )r   r   r   r   r   r
   A   s    
z+ClientCapabilityToken.allow_client_incomingc                 K   s6   t ddddi}|r(|dt|dd || jd< d	S )
zL
        Allow the user of this token to access their event stream.
        stream	subscribepathz/2010-04-01/EventsparamsTr   eventsNr   )r   r   r    r   r   r   r   L   s    z(ClientCapabilityToken.allow_event_streamc                 C   sJ   d| j v r(| jd ur(| j d d| j dd | j  D }dd|iS )Nr   r"   c                 S   s   g | ]}|  qS r   )
to_payload).0Z	scope_urir   r   r   
<listcomp>Z   s   z;ClientCapabilityToken._generate_payload.<locals>.<listcomp>r     )r   r   r   valuesjoin)r   Z
scope_urisr   r   r   _generate_payloadV   s    z'ClientCapabilityToken._generate_payload)__name__
__module____qualname____doc__r   r   ZGENERATEr   r	   r
   r   r.   __classcell__r   r   r   r   r      s   )
r   c                   @   s2   e Zd ZdZdddZdd Zdd Zd	d
 ZdS )r   zDA single capability granted to Twilio Client and scoped to a serviceNc                 C   s   || _ || _|pi | _d S N)service	privileger&   )r   r5   r6   r&   r   r   r   r   c   s    zScopeURI.__init__c                 C   s   || j |< d S r4   )r&   )r   keyvaluer   r   r   r   h   s    zScopeURI.add_paramc                 C   sH   | j r2tdd | j  D }t|}d|}nd}d| j| j|S )Nc                 S   s   g | ]\}}||fqS r   r   )r)   kvr   r   r   r*   m       z'ScopeURI.to_payload.<locals>.<listcomp>z?{} zscope:{}:{}{})r&   sorteditemsr   formatr5   r6   )r   Zsorted_paramsZencoded_paramsZparam_stringr   r   r   r(   k   s    zScopeURI.to_payloadc                 C   s   d |  S )Nz<ScopeURI {}>)r?   r(   )r   r   r   r   __str__t   s    zScopeURI.__str__)N)r/   r0   r1   r2   r   r   r(   r@   r   r   r   r   r   `   s
   
	r   N)Z
twilio.jwtr   urllib.parser   r   objectr   r   r   r   r   <module>   s   Z