a
    o=ic                     @   sF   d Z ddlZddlmZ ddlmZmZ eeZ	G dd deZ
dS )z
oauthlib.oauth2.rfc6749
~~~~~~~~~~~~~~~~~~~~~~~

This module is an implementation of various logic needed
for consuming and providing OAuth 2.0 RFC6749.
    N)Request   )BaseEndpointcatch_errors_and_unavailabilityc                   @   sR   e Zd ZdZdd Zedd Zedd Zedd	 Ze	dddZ
dd ZdS )ResourceEndpointa  Authorizes access to protected resources.

    The client accesses protected resources by presenting the access
    token to the resource server.  The resource server MUST validate the
    access token and ensure that it has not expired and that its scope
    covers the requested resource.  The methods used by the resource
    server to validate the access token (as well as any error responses)
    are beyond the scope of this specification but generally involve an
    interaction or coordination between the resource server and the
    authorization server::

        # For most cases, returning a 403 should suffice.

    The method in which the client utilizes the access token to
    authenticate with the resource server depends on the type of access
    token issued by the authorization server.  Typically, it involves
    using the HTTP "Authorization" request header field [RFC2617] with an
    authentication scheme defined by the specification of the access
    token type used, such as [RFC6750]::

        # Access tokens may also be provided in query and body
        https://example.com/protected?access_token=kjfch2345sdf   # Query
        access_token=sdf23409df   # Body
    c                 C   s   t |  || _|| _d S N)r   __init___tokens_default_token)selfdefault_tokenZtoken_types r   {/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/endpoints/resource.pyr   ,   s    
zResourceEndpoint.__init__c                 C   s   | j S r   )r
   r   r   r   r   r   1   s    zResourceEndpoint.default_tokenc                 C   s   | j | jS r   )tokensgetr   r   r   r   r   default_token_type_handler5   s    z+ResourceEndpoint.default_token_type_handlerc                 C   s   | j S r   )r	   r   r   r   r   r   9   s    zResourceEndpoint.tokensGETNc                 C   sP   t ||||}| ||_||_| j|j| j}td|j| |	||fS )z0Validate client, code etc, return body + headersz(Dispatching token_type %s request to %r.)
r   find_token_type
token_typescopesr   r   r   logdebugZvalidate_request)r   uriZhttp_methodbodyheadersr   requestZtoken_type_handlerr   r   r   verify_request=   s    
zResourceEndpoint.verify_requestc                    s8   t  fdd| j D dd}t|r4|d d S dS )a>  Token type identification.

        RFC 6749 does not provide a method for easily differentiating between
        different token types during protected resource access. We estimate
        the most likely token type (if any) by asking each known token type
        to give an estimation based on the request.
        c                 3   s    | ]\}}|  |fV  qd S r   )Zestimate_type).0ntr   r   r   	<genexpr>R   s   z3ResourceEndpoint.find_token_type.<locals>.<genexpr>T)reverser   r   N)sortedr   itemslen)r   r   Z	estimatesr   r!   r   r   J   s    z ResourceEndpoint.find_token_type)r   NNN)__name__
__module____qualname____doc__r   propertyr   r   r   r   r   r   r   r   r   r   r      s   


  r   )r*   loggingZoauthlib.commonr   baser   r   	getLoggerr'   r   r   r   r   r   r   <module>   s
   
