o
    e5                     @   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 ClientHS256i  Nc                    s   t t| j| j||||dd || _|| _d| _i | _d|v r)| jdi |d  d|v r7| j	di |d  d|v rG| j
di |d  dS 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)	algorithm
secret_key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__r   M/var/www/html/venv/lib/python3.10/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outgoingappSid	appParamsTdoseqNScopeURI	add_paramr   r   )r   application_sidr   scoper   r   r   r   -   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   :   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   C   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).0	scope_urir   r   r   
<listcomp>Q   s    z;ClientCapabilityToken._generate_payload.<locals>.<listcomp>r&    )r   r   r$   valuesjoin)r   
scope_urisr   r   r   _generate_payloadM   s   z'ClientCapabilityToken._generate_payload)__name__
__module____qualname____doc__r   r   GENERATEr   r   r   r   r6   __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   r>   r?   r,   r   r   r   r   X   s   zScopeURI.__init__c                 C   s   || j |< d S r=   )r,   )r   keyvaluer   r   r   r$   ]      zScopeURI.add_paramc                 C   sH   | j rt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   r1   b   s    z'ScopeURI.to_payload.<locals>.<listcomp>z?{} zscope:{}:{}{})r,   sorteditemsr   formatr>   r?   )r   sorted_paramsencoded_paramsparam_stringr   r   r   r.   `   s   zScopeURI.to_payloadc                 C   s   d |  S )Nz<ScopeURI {}>)rH   r.   )r   r   r   r   __str__i   rB   zScopeURI.__str__r=   )r7   r8   r9   r:   r   r$   r.   rL   r   r   r   r   r#   U   s    
	r#   N)
twilio.jwtr   urllib.parser   r   objectr#   r   r   r   r   <module>   s    O