a
    o=ic\                     @   sR   d Z ddlZddlm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.endpoint.revocation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

An implementation of the OAuth 2 `Token Revocation`_ spec (draft 11).

.. _`Token Revocation`: https://tools.ietf.org/html/draft-ietf-oauth-revocation-11
    N)Request   )OAuth2Error   )BaseEndpointcatch_errors_and_unavailabilityc                   @   s8   e Zd ZdZdZdZdddZedd	d
Zdd Z	dS )RevocationEndpointzToken revocation endpoint.

    Endpoint used by authenticated clients to revoke access and refresh tokens.
    Commonly this will be part of the Authorization Endpoint.
    )Zaccess_tokenZrefresh_token)POSTNFc                 C   s&   t |  || _|p| j| _|| _d S )N)r   __init__request_validatorvalid_token_typessupported_token_typesenable_jsonp)selfr   r   r    r   }/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/endpoints/revocation.pyr
      s
    
zRevocationEndpoint.__init__r	   c           	   
   C   s   dddd}t ||||d}z| | td| W nj ty } zRtd|| |j}| jrt|jrtd|j|}|	|j
 |||jfW  Y d	}~S d	}~0 0 | j|j|j| d
}| jr|jr|jd }i |dfS )a  Revoke supplied access or refresh token.


        The authorization server responds with HTTP status code 200 if the
        token has been revoked successfully or if the client submitted an
        invalid token.

        Note: invalid tokens do not cause an error response since the client
        cannot handle such an error in a reasonable way.  Moreover, the purpose
        of the revocation request, invalidating the particular token, is
        already achieved.

        The content of the response body is ignored by the client as all
        necessary information is conveyed in the response code.

        An invalid token type hint value is ignored by the authorization server
        and does not influence the revocation response.
        zapplication/jsonzno-storezno-cache)zContent-TypezCache-ControlZPragma)http_methodbodyheaderszToken revocation valid for %r.z)Client error during validation of %r. %r.z{}({});N z();   )r   validate_revocation_requestlogdebugr   jsonr   callbackformatupdater   status_coder   Zrevoke_tokentokenZtoken_type_hint)	r   urir   r   r   Zresp_headersrequesteZresponse_bodyr   r   r   create_revocation_response&   s0    
"

z-RevocationEndpoint.create_revocation_responsec                 C   s6   |  | | | | | | | | | dS )a  Ensure the request is valid.

        The client constructs the request by including the following parameters
        using the "application/x-www-form-urlencoded" format in the HTTP
        request entity-body:

        token (REQUIRED).  The token that the client wants to get revoked.

        token_type_hint (OPTIONAL).  A hint about the type of the token
        submitted for revocation.  Clients MAY pass this parameter in order to
        help the authorization server to optimize the token lookup.  If the
        server is unable to locate the token using the given hint, it MUST
        extend its search across all of its supported token types.  An
        authorization server MAY ignore this parameter, particularly if it is
        able to detect the token type automatically.  This specification
        defines two such values:

                *  access_token: An Access Token as defined in [RFC6749],
                    `section 1.4`_

                *  refresh_token: A Refresh Token as defined in [RFC6749],
                    `section 1.5`_

                Specific implementations, profiles, and extensions of this
                specification MAY define other values for this parameter using
                the registry defined in `Section 4.1.2`_.

        The client also includes its authentication credentials as described in
        `Section 2.3`_. of [`RFC6749`_].

        .. _`section 1.4`: https://tools.ietf.org/html/rfc6749#section-1.4
        .. _`section 1.5`: https://tools.ietf.org/html/rfc6749#section-1.5
        .. _`section 2.3`: https://tools.ietf.org/html/rfc6749#section-2.3
        .. _`Section 4.1.2`: https://tools.ietf.org/html/draft-ietf-oauth-revocation-11#section-4.1.2
        .. _`RFC6749`: https://tools.ietf.org/html/rfc6749
        N)Z_raise_on_bad_methodZ_raise_on_bad_post_requestZ_raise_on_missing_tokenZ_raise_on_invalid_clientZ_raise_on_unsupported_token)r   r!   r   r   r   r   U   s
    %



z.RevocationEndpoint.validate_revocation_request)NF)r	   NN)
__name__
__module____qualname____doc__r   Zvalid_request_methodsr
   r   r#   r   r   r   r   r   r      s     
  .r   )r'   loggingZoauthlib.commonr   errorsr   baser   r   	getLoggerr$   r   r   r   r   r   r   <module>   s   
