§
    iÝ[f|  ã                   óB   — d dl mZ ddlmZmZmZ  G d„ de¦  «        ZdS )é    )Údefault_json_headersé   )ÚTokenEndpointÚInvalidRequestErrorÚUnsupportedTokenTypeErrorc                   ó@   — e Zd ZdZdZd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
S )ÚIntrospectionEndpointz‰Implementation of introspection endpoint which is described in
    `RFC7662`_.

    .. _RFC7662: https://tools.ietf.org/html/rfc7662
    Úintrospectionc                 óÞ   — |                       ||¦  «         |                      |j        d         |j                             d¦  «        ¦  «        }|r|                      |||¦  «        r|S dS dS )aw  The protected resource calls the introspection endpoint using an HTTP
        ``POST`` request with parameters sent as
        "application/x-www-form-urlencoded" data. The protected resource sends a
        parameter representing the token along with optional parameters
        representing additional context that is known by the protected resource
        to aid the authorization server in its response.

        token
            **REQUIRED**  The string value of the token. For access tokens, this
            is the ``access_token`` value returned from the token endpoint
            defined in OAuth 2.0. For refresh tokens, this is the
            ``refresh_token`` value returned from the token endpoint as defined
            in OAuth 2.0.

        token_type_hint
            **OPTIONAL**  A hint about the type of the token submitted for
            introspection.
        ÚtokenÚtoken_type_hintN)Úcheck_paramsÚquery_tokenÚformÚgetÚcheck_permission)ÚselfÚrequestÚclientr   s       úX/var/www/piapp/venv/lib/python3.11/site-packages/authlib/oauth2/rfc7662/introspection.pyÚauthenticate_tokenz(IntrospectionEndpoint.authenticate_token   s�   € ð( 	×Ò˜' 6Ñ*Ô*Ð*Ø× Ò  ¤¨gÔ!6¸¼×8HÒ8HÐIZÑ8[Ô8[Ñ\Ô\ˆØð 	�T×*Ò*¨5°&¸'ÑBÔBð 	ØˆLð	ð 	ð 	ð 	ó    c                 ó˜   — |j         }d|vrt          ¦   «         ‚|                     d¦  «        }|r|| j        vrt	          ¦   «         ‚d S d S )Nr   r   )r   r   r   ÚSUPPORTED_TOKEN_TYPESr   )r   r   r   ÚparamsÚhints        r   r   z"IntrospectionEndpoint.check_params+   sc   € Ø”ˆØ˜&Ð Ð Ý%Ñ'Ô'Ð'à�zŠzÐ+Ñ,Ô,ˆØð 	.�D Ô :Ð:Ð:Ý+Ñ-Ô-Ð-ð	.ð 	.Ð:Ð:r   c                 ó–   — |                       |¦  «        }|                      ||¦  «        }|                      |¦  «        }d|t          fS )zpValidate introspection request and create the response.

        :returns: (status_code, body, headers)
        éÈ   )Úauthenticate_endpoint_clientr   Úcreate_introspection_payloadr   )r   r   r   r   Úbodys        r   Úcreate_endpoint_responsez.IntrospectionEndpoint.create_endpoint_response4   sQ   € ð ×2Ò2°7Ñ;Ô;ˆð ×'Ò'¨°Ñ8Ô8ˆð ×0Ò0°Ñ7Ô7ˆØ�DÕ.Ð.Ð.r   c                 ó¦   — |sddiS |                      ¦   «         s|                     ¦   «         rddiS |                      |¦  «        }d|vrd|d<   |S )NÚactiveFT)Ú
is_expiredÚ
is_revokedÚintrospect_token)r   r   Úpayloads      r   r    z2IntrospectionEndpoint.create_introspection_payloadD   sv   € ð
 ð 	%Ø˜eÐ$Ð$Ø×ÒÑÔð 	% ×!1Ò!1Ñ!3Ô!3ð 	%Ø˜eÐ$Ð$Ø×'Ò'¨Ñ.Ô.ˆØ˜7Ð"Ð"Ø $ˆG�HÑØˆr   c                 ó   — t          ¦   «         ‚)aU  Check if the request has permission to introspect the token. Developers
        MUST implement this method::

            def check_permission(self, token, client, request):
                # only allow a special client to introspect the token
                return client.client_id == 'introspection_client'

        :return: bool
        ©ÚNotImplementedError)r   r   r   r   s       r   r   z&IntrospectionEndpoint.check_permissionR   s   € õ "Ñ#Ô#Ð#r   c                 ó   — t          ¦   «         ‚)a’  Get the token from database/storage by the given token string.
        Developers should implement this method::

            def query_token(self, token_string, token_type_hint):
                if token_type_hint == 'access_token':
                    tok = Token.query_by_access_token(token_string)
                elif token_type_hint == 'refresh_token':
                    tok = Token.query_by_refresh_token(token_string)
                else:
                    tok = Token.query_by_access_token(token_string)
                    if not tok:
                        tok = Token.query_by_refresh_token(token_string)
                return tok
        r*   )r   Útoken_stringr   s      r   r   z!IntrospectionEndpoint.query_token^   s   € õ "Ñ#Ô#Ð#r   c                 ó   — t          ¦   «         ‚)a  Read given token and return its introspection metadata as a
        dictionary following `Section 2.2`_::

            def introspect_token(self, token):
                return {
                    'active': True,
                    'client_id': token.client_id,
                    'token_type': token.token_type,
                    'username': get_token_username(token),
                    'scope': token.get_scope(),
                    'sub': get_token_user_sub(token),
                    'aud': token.client_id,
                    'iss': 'https://server.example.com/',
                    'exp': token.expires_at,
                    'iat': token.issued_at,
                }

        .. _`Section 2.2`: https://tools.ietf.org/html/rfc7662#section-2.2
        r*   )r   r   s     r   r'   z&IntrospectionEndpoint.introspect_tokeno   s   € õ( "Ñ#Ô#Ð#r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚENDPOINT_NAMEr   r   r"   r    r   r   r'   © r   r   r	   r	   	   sŽ   € € € € € ðð ð $€Mðð ð ð2.ð .ð .ð/ð /ð /ð ð ð ð
$ð 
$ð 
$ð$ð $ð $ð"$ð $ð $ð $ð $r   r	   N)Úauthlib.constsr   Úrfc6749r   r   r   r	   r4   r   r   ú<module>r7      s‡   ðØ /Ð /Ð /Ð /Ð /Ð /ðð ð ð ð ð ð ð ð ð ðz$ð z$ð z$ð z$ð z$˜Mñ z$ô z$ð z$ð z$ð z$r   