HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/oauthlib/oauth2/rfc6749/__pycache__/tokens.cpython-38.pyc
U

��I],�@s
dZddlmZmZddlZddlZddlmZddlZddl	m
Z
ddlmZm
Z
mZddlmZzdd	lmZWn ek
r�dd	lmZYnXGd
d�de�Zd!dd�Zdd�Zd"dd�Zd#dd�Zd$dd�Zdd�Zdd�ZGdd�de�ZGdd �d e�ZdS)%z�
oauthlib.oauth2.rfc6749.tokens
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This module contains methods for adding two types of access tokens to requests.

- Bearer https://tools.ietf.org/html/rfc6750
- MAC https://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01
�)�absolute_import�unicode_literalsN)�
b2a_base64)�common)�add_params_to_qs�add_params_to_uri�unicode_type�)�utils)�urlparsecsreZdZd�fdd�	Zedd��Zedd��Zedd	��Zed
d��Zedd
��Z	edd��Z
edd��Z�ZS)�OAuth2TokenNcsrtt|��|�d|_d|kr:|dr:tt�|d��|_|dk	rftt�|��|_|jdkrn|j|_n|j|_dS)N�scope)�superr�__init__�
_new_scope�setr
Z
scope_to_list�
_old_scope)�selfZparams�	old_scope��	__class__��@/usr/lib/python3/dist-packages/oauthlib/oauth2/rfc6749/tokens.pyrs

zOAuth2Token.__init__cCs|j|jkS�N)rr�rrrr�
scope_changed,szOAuth2Token.scope_changedcCst�|j�Sr)r
�
list_to_scoperrrrrr0szOAuth2Token.old_scopecCs
t|j�Sr)�listrrrrr�
old_scopes4szOAuth2Token.old_scopescCst�|j�Sr)r
rrrrrrr
8szOAuth2Token.scopecCs
t|j�Sr)rrrrrr�scopes<szOAuth2Token.scopescCst|j|j�Sr)rrrrrrr�missing_scopes@szOAuth2Token.missing_scopescCst|j|j�Sr)rrrrrrr�additional_scopesDszOAuth2Token.additional_scopes)N)
�__name__�
__module__�__qualname__r�propertyrrrr
rr r!�
__classcell__rrrrrs





r��
hmac-sha-1cCs:|��}t�|�\}}|��dkr*tj}
n|��dkr>tj}
ntd��|
dkrj|pfd�t�	|	�t
���}nt
��}t
��}t
|�\}}}}}}|r�|d|}n|}|dk	r�|
dkr�|�d�}t|
|����dd	��d�}nd
}g}|
dkr�|�|�n|�|�|�|�|�|���|�|�|�|�|�|�|
dk�rN|�|�|�|�pZd
�d�|�d}t|t��r�|�d�}t�||�d�|
�}t|���dd	��d�}g}|�d|�|
dk�r�|�d
|�|�d|�|�r�|�d|�|�r|�d|�|�d|�|�p&i}d�|�|d<|S)a_Add an `MAC Access Authentication`_ signature to headers.

    Unlike OAuth 1, this HMAC signature does not require inclusion of the
    request payload/body, neither does it use a combination of client_secret
    and token_secret but rather a mac_key provided together with the access
    token.

    Currently two algorithms are supported, "hmac-sha-1" and "hmac-sha-256",
    `extension algorithms`_ are not supported.

    Example MAC Authorization header, linebreaks added for clarity

    Authorization: MAC id="h480djs93hd8",
                       nonce="1336363200:dj83hs9s",
                       mac="bhCQXTVyfj5cmA9uKkPFx1zeOXM="

    .. _`MAC Access Authentication`: https://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01
    .. _`extension algorithms`: https://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01#section-7.1

    :param token:
    :param uri: Request URI.
    :param key: MAC given provided by token endpoint.
    :param http_method: HTTP Request method.
    :param nonce:
    :param headers: Request headers as a dictionary.
    :param body:
    :param ext:
    :param hash_algorithm: HMAC algorithm provided by token endpoint.
    :param issue_time: Time when the MAC credentials were issued (datetime).
    :param draft: MAC authentication specification version.
    :return: headers dictionary with the authorization field added.
    r(zhmac-sha-256zunknown hash algorithmrz{0}:{1}�?Nzutf-8���r'�
zMAC id="%s"zts="%s"z
nonce="%s"z
bodyhash="%s"zext="%s"zmac="%s"z, �
Authorization)�upperr
Z
host_from_uri�lower�hashlibZsha1Zsha256�
ValueError�formatZgenerate_agerZgenerate_nonceZgenerate_timestampr�encoderZdigest�decode�append�join�
isinstancer�hmac�new)�token�uri�keyZhttp_methodZnonce�headers�bodyZextZhash_algorithmZ
issue_timeZdraftZhostZport�hZtsZschZnet�pathZparZqueryZfraZrequest_uriZbodyhash�baseZbase_stringZsign�headerrrr�prepare_mac_headerIsf(�
 









rBcCst|d|fg�S)aAdd a `Bearer Token`_ to the request URI.
    Not recommended, use only if client can't use authorization header or body.

    http://www.example.com/path?access_token=h480djs93hd8

    .. _`Bearer Token`: https://tools.ietf.org/html/rfc6750

    :param token:
    :param uri:
    �access_token)r)r9r:rrr�prepare_bearer_uri�srDcCs|pi}d||d<|S)z�Add a `Bearer Token`_ to the request URI.
    Recommended method of passing bearer tokens.

    Authorization: Bearer h480djs93hd8

    .. _`Bearer Token`: https://tools.ietf.org/html/rfc6750

    :param token:
    :param headers:
    z	Bearer %sr,r)r9r<rrr�prepare_bearer_headers�srEcCst|d|fg�S)z�Add a `Bearer Token`_ to the request body.

    access_token=h480djs93hd8

    .. _`Bearer Token`: https://tools.ietf.org/html/rfc6750

    :param token:
    :param body:
    rC)r)r9r=rrr�prepare_bearer_body�s
rFFcCst��S)zp
    :param request: OAuthlib request.
    :type request: oauthlib.common.Request
    :param refresh_token:
    )rZgenerate_token)�request�
refresh_tokenrrr�random_token_generator�srIcs��fdd�}|S)z
    :param private_pem:
    cs�|_t��|�Sr)ZclaimsrZgenerate_signed_token)rG��kwargs�private_pemrr�signed_token_generator�sz6signed_token_generator.<locals>.signed_token_generatorr)rLrKrMrrJrrM�srMcCsNd}d|jkrD|j�d���}t|�dkrJ|d��dkrJ|d}n|j}|S)z�
    Helper function to extract a token from the request header.

    :param request: OAuthlib request.
    :type request: oauthlib.common.Request
    :return: Return the token or None if the Authorization header is malformed.
    Nr,�r�bearerr	)r<�get�split�lenr.rC)rGr9Zsplit_headerrrr�get_token_from_header�s

rSc@s&eZdZd	dd�Zdd�Zdd�ZdS)
�	TokenBaseFcCstd��dS)N�&Subclasses must implement this method.��NotImplementedError)rrGrHrrr�__call__szTokenBase.__call__cCstd��dS��b
        :param request: OAuthlib request.
        :type request: oauthlib.common.Request
        rUNrV�rrGrrr�validate_requestszTokenBase.validate_requestcCstd��dSrYrVr[rrr�
estimate_typeszTokenBase.estimate_typeN)F)r"r#r$rXr\r]rrrrrT	s
rTc@s4eZdZdZddd�Zd
dd�Zdd	�Zd
d�ZdS)�BearerToken)�request_validator�token_generator�refresh_token_generator�
expires_inNcCs*||_|pt|_|p|j|_|p"d|_dS)Ni)r_rIr`rarb)rr_r`rbrarrrr#s

�zBearerToken.__init__FcKs�d|krt�dt�t|j�r*|�|�}n|j}||_|�|�|dd�}|jdk	rbd�|j�|d<|r�|jr�|j	�
|�s�|j|d<n|�|�|d<|�|j
p�i�t|�S)	z�
        Create a BearerToken, by default without refresh token.

        :param request: OAuthlib request.
        :type request: oauthlib.common.Request
        :param refresh_token:
        Z
save_tokenzx`save_token` has been deprecated, it was not called internally.If you do, call `request_validator.save_token()` instead.ZBearer)rCrb�
token_typeN� r
rH)�warnings�warn�DeprecationWarning�callablerbr`rr5rHr_Zrotate_refresh_tokenra�updateZextra_credentialsr)rrGrHrKrbr9rrr�create_token,s,�
�	

�zBearerToken.create_tokencCst|�}|j�||j|�S)rZ)rSr_Zvalidate_bearer_tokenr)rrGr9rrrr\Vs�zBearerToken.validate_requestcCs:|j�dd��d�d��dkr$dS|jdk	r2dSdSdS)	rZr,r'rdrrO�	N�)r<rPrQr.rCr[rrrr]_s
 
zBearerToken.estimate_type)NNNN)F)r"r#r$�	__slots__rrjr\r]rrrrr^s�
	
*	r^)NNNr'r(Nr)N)r')F) �__doc__Z
__future__rrr/r7ZbinasciirreZoauthlibrZoauthlib.commonrrrr'r
r�ImportErrorZurllib.parse�dictrrBrDrErFrIrMrS�objectrTr^rrrr�<module>s:	.�
m