Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.6/site-packages/oauthlib/oauth2/rfc6749/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.6/site-packages/oauthlib/oauth2/rfc6749/__pycache__/tokens.cpython-36.pyc

3

 ��cl+�@s�dZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZmZddl
mZGd	d
�d
e�Zd d
d�Zdd�Zd!dd�Zd"dd�Zd#dd�Zdd�Zdd�ZGdd�d�ZGdd�de�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
�N)�
b2a_base64)�urlparse)�common)�add_params_to_qs�add_params_to_uri�)�utilscsreZdZd�fdd�	Zedd��Zedd��Zedd	��Zed
d��Zedd
��Z	edd��Z
edd��Z�ZS)�OAuth2TokenNcsnt�j|�d|_d|kr6|dr6ttj|d��|_|dk	rbttj|��|_|jdkrj|j|_n|j|_dS)N�scope)�super�__init__�
_new_scope�setrZ
scope_to_list�
_old_scope)�self�params�	old_scope)�	__class__��B/tmp/pip-build-_uu8ur7s/oauthlib/oauthlib/oauth2/rfc6749/tokens.pyrs

zOAuth2Token.__init__cCs|j|jkS)N)r
r)rrrr�
scope_changed&szOAuth2Token.scope_changedcCstj|j�S)N)r�
list_to_scoper)rrrrr*szOAuth2Token.old_scopecCs
t|j�S)N)�listr)rrrr�
old_scopes.szOAuth2Token.old_scopescCstj|j�S)N)rrr
)rrrrr
2szOAuth2Token.scopecCs
t|j�S)N)rr
)rrrr�scopes6szOAuth2Token.scopescCst|j|j�S)N)rrr
)rrrr�missing_scopes:szOAuth2Token.missing_scopescCst|j|j�S)N)rr
r)rrrr�additional_scopes>szOAuth2Token.additional_scopes)N)
�__name__�
__module__�__qualname__r�propertyrrrr
rrr�
__classcell__rr)rrr	sr	��
hmac-sha-1cCs:|j�}tj|�\}}|j�dkr*tj}
n|j�dkr>tj}
ntd��|
dkrj|pfdjtj	|	�t
j��}nt
j�}t
j�}t
|�\}}}}}}|r�|d|}n|}|dk	r�|
dkr�|jd�}t|
|�j��dd�jd�}nd
}g}|
dkr�|j|�n|j|�|j|�|j|j��|j|�|j|�|j|�|
dk�rN|j|�|j|�pZd
�dj|�d}t|t��r�|jd�}tj||jd�|
�}t|j��dd�jd�}g}|jd|�|
dk�r�|jd
|�|jd|�|�r�|jd|�|�r|jd|�|jd|�|�p&i}dj|�|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.
    z
hmac-sha-1zhmac-sha-256zunknown hash algorithmrz{}:{}�?Nzutf-8rr"�
zMAC id="%s"zts="%s"z
nonce="%s"z
bodyhash="%s"zext="%s"zmac="%s"z, �
Authorization���r')�upperrZ
host_from_uri�lower�hashlib�sha1�sha256�
ValueError�formatZgenerate_agerZgenerate_nonceZgenerate_timestampr�encoder�digest�decode�append�join�
isinstance�str�hmac�new)�token�uri�keyZhttp_method�nonce�headers�body�extZhash_algorithmZ
issue_timeZdraft�host�port�h�tsZsch�net�path�par�queryZfra�request_uriZbodyhash�baseZbase_string�sign�headerrrr�prepare_mac_headerCsd(
 









rKcCst|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)r8r9rrr�prepare_bearer_uri�srMcCs|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)r8r<rrr�prepare_bearer_headers�srNcCst|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:
    rL)r)r8r=rrr�prepare_bearer_body�s
rOFcCstj�S)zp
    :param request: OAuthlib request.
    :type request: oauthlib.common.Request
    :param refresh_token:
    )rZgenerate_token)�request�
refresh_tokenrrr�random_token_generator�srRcs��fdd�}|S)z
    :param private_pem:
    cs�|_tj�|�S)N)ZclaimsrZgenerate_signed_token)rP)�kwargs�private_pemrr�signed_token_generator�sz6signed_token_generator.<locals>.signed_token_generatorr)rTrSrUr)rSrTrrU�srUcCsNd}d|jkrD|jjd�j�}t|�dkrJ|dj�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)rL)rPr8Zsplit_headerrrr�get_token_from_header�s

r[c@s*eZdZfZd	dd�Zdd�Zdd�ZdS)
�	TokenBaseFcCstd��dS)Nz&Subclasses must implement this method.)�NotImplementedError)rrPrQrrr�__call__szTokenBase.__call__cCstd��dS)zb
        :param request: OAuthlib request.
        :type request: oauthlib.common.Request
        z&Subclasses must implement this method.N)r])rrPrrr�validate_request	szTokenBase.validate_requestcCstd��dS)zb
        :param request: OAuthlib request.
        :type request: oauthlib.common.Request
        z&Subclasses must implement this method.N)r])rrPrrr�
estimate_typeszTokenBase.estimate_typeN)F)rrr�	__slots__r^r_r`rrrrr\s
r\c@s4eZdZdZddd�Zdd	d
�Zdd�Zd
d�ZdS)�BearerToken�request_validator�token_generator�refresh_token_generator�
expires_inNcCs*||_|pt|_|p|j|_|p"d|_dS)Ni)rcrRrdrerf)rrcrdrfrerrrrs
zBearerToken.__init__FcKs�d|krtjdt�t|j�r*|j|�}n|j}||_|j|�|dd�}|jdk	rbdj|j�|d<|r�|jr�|j	j
|�r�|j|d<n|j|�|d<|j|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)rLrf�
token_typeN� r
rQ)�warnings�warn�DeprecationWarning�callablerfrdrr3rQrcZrotate_refresh_tokenre�updateZextra_credentialsr	)rrPrQrSrfr8rrr�create_token's&

zBearerToken.create_tokencCst|�}|jj||j|�S)zb
        :param request: OAuthlib request.
        :type request: oauthlib.common.Request
        )r[rcZvalidate_bearer_tokenr)rrPr8rrrr_QszBearerToken.validate_requestcCs:|jjdd�jd�dj�dkr$dS|jdk	r2dSdSdS)	zb
        :param request: OAuthlib request.
        :type request: oauthlib.common.Request
        r&r"rhrrW�	N�)r<rXrYr)rL)rrPrrrr`Zs
 
zBearerToken.estimate_type)rcrdrerf)NNNN)F)rrrrarrnr_r`rrrrrbs

*	rb)NNNr"r#Nr)N)r")F)�__doc__r*r6ri�binasciir�urllib.parserZoauthlibrZoauthlib.commonrrr"r�dictr	rKrMrNrOrRrUr[r\rbrrrr�<module>	s0.
f


	

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists