U
    ÔÉ>i  ã                   @   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eee	e
f dœ‡ fdd„Zedœd	d
„Z‡  ZS )Ú	TokenAuthzv
    Use the OIDC access token to authenticate and the scopes attached to the
    token to authorize the request.
    Z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__© úK/tmp/pip-unpacked-wheel-upujnpc2/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rX|jjrX|jj|_|jS )NZscopes)r   r   Úverify_requestr   r
   Zaccess_tokenÚmethodÚuser)r   r   ÚserverZorequestZ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   Zdjango.httpr   Zninja.security.baser   Z)allauth.idp.oidc.internal.oauthlib.serverr   Z(allauth.idp.oidc.internal.oauthlib.utilsr   Zallauth.idp.oidc.internal.scoper   r   r   r   r   r   Ú<module>   s   