o
    õÁh  ã                   @   s\   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„ deƒZd	S )
é    )ÚUnion)ÚHttpRequest)ÚAuthBase)Ú
get_server)Úextract_params)Úis_scope_grantedc                       sP   e Zd ZU dZdZeed< dZdeee	e
f f‡ fdd„Zdefd	d
„Z‡  ZS )Ú	TokenAuthzv
    Use the OIDC access token to authenticate and the scopes attached to the
    token to authorize the request.
    ÚapiKeyÚopenapi_typeNÚscopec                    s   t ƒ  ¡  || _dS )aÊ  The scope passed can either be:

        - a single scope (``str``),
        - a list of scopes, all of which should be granted.
        - a list of scope lists. Your token should match at least all scopes of one of the scope lists.
        - A dictionary, with the request method (e.g. ``GET``) as key, and one
          of the scope values from the previous bullet. The scopes to match are
          then dynamically selected based on the request.
        N)ÚsuperÚ__init__r   )Úselfr   ©Ú	__class__© ú^/var/www/html/pos/venv/lib/python3.10/site-packages/allauth/idp/oidc/contrib/ninja/security.pyr      s   


zTokenAuth.__init__Úrequestc                 C   s^   t ƒ }t|ƒ}|j|dg iŽ\}}|sd S t| j|j|jƒs d S |jr,|jjr,|jj|_|jS )NÚscopes)r   r   Úverify_requestr   r   Úaccess_tokenÚmethodÚuser)r   r   ÚserverÚorequestÚvalidÚctxr   r   r   Ú__call__"   s   
zTokenAuth.__call__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   ÚstrÚ__annotations__r   r   ÚlistÚdictr   r   r   Ú__classcell__r   r   r   r   r      s   
 r   N)Útypingr   Údjango.httpr   Úninja.security.baser   Ú)allauth.idp.oidc.internal.oauthlib.serverr   Ú(allauth.idp.oidc.internal.oauthlib.utilsr   Úallauth.idp.oidc.internal.scoper   r   r   r   r   r   Ú<module>   s    