
    i[f                     v    d dl mZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ  G d	 d
e          ZdS )   )IntrospectionEndpoint    )ContinueIteration)default_json_headers)ExpiredTokenError)InvalidClaimError)InvalidTokenError)JWTBearerTokenValidatorc                   P     e Zd ZdZdZd fd	Zd Zd Zd Zd Z	d	e
d
e
fdZ xZS )JWTIntrospectionEndpointa  
    JWTIntrospectionEndpoint inherits from :ref:`specs/rfc7662`
    :class:`~authlib.oauth2.rfc7662.IntrospectionEndpoint` and implements the machinery
    to automatically process the JWT access tokens.

    :param issuer: The issuer identifier for which tokens will be introspected.

    :param \*\*kwargs: Other parameters are inherited from
        :class:`~authlib.oauth2.rfc7662.introspection.IntrospectionEndpoint`.

    ::

        class MyJWTAccessTokenIntrospectionEndpoint(JWTRevocationEndpoint):
            def get_jwks(self):
                ...

            def get_username(self, user_id):
                ...

        authorization_server.register_endpoint(
            MyJWTAccessTokenIntrospectionEndpoint(
                issuer="https://authorization-server.example.org",
            )
        )
        authorization_server.register_endpoint(MyRefreshTokenIntrospectionEndpoint)

    introspectionNc                 L     t                      j        |d|i| || _        d S )Nserver)super__init__issuer)selfr   r   argskwargs	__class__s        X/var/www/piapp/venv/lib/python3.11/site-packages/authlib/oauth2/rfc9068/introspection.pyr   z!JWTIntrospectionEndpoint.__init__*   s/    $8v8888    c                     |                      |          }|                     ||          }|                     |          }d|t          fS )    )authenticate_endpoint_clientauthenticate_tokencreate_introspection_payloadr   )r   requestclienttokenbodys        r   create_endpoint_responsez1JWTIntrospectionEndpoint.create_endpoint_response.   sQ     227;; ''88 0077D...r   c                    |                      ||           |j                            d          dvrt                      t	          | j        d          }| j        |_        	 |                    |j        d                   }n# t          $ r t                      w xY w|r| 	                    |||          r|S dS dS )r   token_type_hint)access_tokenNN)r   resource_serverr!   )
check_paramsformgetr   r
   r   get_jwksr   r	   check_permission)r   r   r    	validatorr!   s        r   r   z+JWTIntrospectionEndpoint.authenticate_token;   s    '6*** <-..6LLL#%%%+4;PTUUU	!]		&00g1FGGEE ! 	& 	& 	&#%%%	&  	T**5&'BB 	L	 	 	 	s   $ B Bc           
      ~   |sddiS 	 |                                  nH# t          $ r ddicY S t          $ r,}|j        dk    rt	                      t                      d }~ww xY wdd|d         |d         |d         |d	         |d         |d
         |d         d	}|                     |d                   x}r||d<   |S )NactiveFissTBearer	client_idscopesubaudexpiat)	r/   
token_typer2   r3   r4   r5   r0   r6   r7   username)validater   r   
claim_namer   r	   get_username)r   r!   excpayloadr9   s        r   r   z5JWTIntrospectionEndpoint.create_introspection_payloadO   s
    	%e$$	&NN  	% 	% 	%e$$$$  	& 	& 	&~&&')))#%%%	& "{+7^<<<<<

 

 ((u6668 	+"*GJs    A"	A"'AA"c                     t                      )zReturn the JWKs that will be used to check the JWT access token signature.
        Developers MUST re-implement this method::

            def get_jwks(self):
                return load_jwks("jwks.json")
        )NotImplementedError)r   s    r   r+   z!JWTIntrospectionEndpoint.get_jwksn   s     "###r   user_idreturnc                     dS )zReturns an username from a user ID.
        Developers MAY re-implement this method::

            def get_username(self, user_id):
                return User.get(id=user_id).username
        N )r   rA   s     r   r<   z%JWTIntrospectionEndpoint.get_usernamew   s	     tr   )N)__name__
__module____qualname____doc__ENDPOINT_NAMEr   r#   r   r   r+   strr<   __classcell__)r   s   @r   r   r   
   s         : $M     / / /  (  >$ $ $C C        r   r   N)rfc7662r   authlib.common.errorsr   authlib.constsr   authlib.jose.errorsr   r   authlib.oauth2.rfc6750.errorsr	   &authlib.oauth2.rfc9068.token_validatorr
   r   rD   r   r   <module>rR      s    + + + + + + 3 3 3 3 3 3 / / / / / / 1 1 1 1 1 1 1 1 1 1 1 1 ; ; ; ; ; ; J J J J J Jt t t t t4 t t t t tr   