o
    b                     @   sb   d dl mZ d dlmZ ddlmZmZ ddlmZ G dd de	Z
G dd	 d	e
ZdddZd
S )    )add_params_to_qs)	deprecate   )client_secret_jwt_signprivate_key_jwt_sign)ASSERTION_TYPEc                   @   s2   e Zd ZdZdZdZdddZdd Zd	d
 ZdS )ClientSecretJWTa  Authentication method for OAuth 2.0 Client. This authentication
    method is called ``client_secret_jwt``, which is using ``client_id``
    and ``client_secret`` constructed with JWT to identify a client.

    Here is an example of use ``client_secret_jwt`` with Requests Session::

        from authlib.integrations.requests_client import OAuth2Session

        token_endpoint = 'https://example.com/oauth/token'
        session = OAuth2Session(
            'your-client-id', 'your-client-secret',
            token_endpoint_auth_method='client_secret_jwt'
        )
        session.register_client_auth_method(ClientSecretJWT(token_endpoint))
        session.fetch_token(token_endpoint)

    :param token_endpoint: A string URL of the token endpoint
    :param claims: Extra JWT claims
    client_secret_jwtZHS256Nc                 C   s   || _ || _|| _d S N)token_endpointclaimsheader)selfr   r   r    r   Z/var/www/secure340b-portal/env/lib/python3.10/site-packages/authlib/oauth2/rfc7523/auth.py__init__   s   
zClientSecretJWT.__init__c                 C      t |j|j|| j| j| jdS N)	client_idr   r   r   alg)r   client_secretr   r   r   r   r   authr   r   r   r   sign#      zClientSecretJWT.signc                 C   s>   | j }|s|}| ||}t|pddtfd|fg}|||fS )N Zclient_assertion_typeclient_assertion)r   r   r   r   )r   r   methoduriheadersbodyr   r   r   r   r   __call__-   s   
zClientSecretJWT.__call__)NNN)	__name__
__module____qualname____doc__namer   r   r   r!   r   r   r   r   r      s    

r   c                   @   s    e Zd ZdZdZdZdd ZdS )PrivateKeyJWTa  Authentication method for OAuth 2.0 Client. This authentication
    method is called ``private_key_jwt``, which is using ``client_id``
    and ``private_key`` constructed with JWT to identify a client.

    Here is an example of use ``private_key_jwt`` with Requests Session::

        from authlib.integrations.requests_client import OAuth2Session

        token_endpoint = 'https://example.com/oauth/token'
        session = OAuth2Session(
            'your-client-id', 'your-client-private-key',
            token_endpoint_auth_method='private_key_jwt'
        )
        session.register_client_auth_method(PrivateKeyJWT(token_endpoint))
        session.fetch_token(token_endpoint)

    :param token_endpoint: A string URL of the token endpoint
    :param claims: Extra JWT claims
    private_key_jwtZRS256c                 C   r   r   )r   r   r   r   r   r   r   r   r   r   r   Q   r   zPrivateKeyJWT.signN)r"   r#   r$   r%   r&   r   r   r   r   r   r   r'   :   s
    r'   Nc                 K   sH   t dddd | jdkrt}n| jdkrt}ntd| || dS )	zRegister "client_secret_jwt" or "private_key_jwt" token endpoint auth
    method to OAuth2Session.

    :param session: OAuth2Session instance.
    :param token_url: Optional token endpoint url.
    z1Use `ClientSecretJWT` and `PrivateKeyJWT` insteadz1.0ZJecljcar	   r(   z"Invalid token_endpoint_auth_methodN)r   Ztoken_endpoint_auth_methodr   r'   
ValueErrorZregister_client_auth_method)sessionZ	token_urlkwargsclsr   r   r   #register_session_client_auth_method\   s   

r.   r
   )Zauthlib.common.urlsr   Zauthlib.deprecater   Z	assertionr   r   clientr   objectr   r'   r.   r   r   r   r   <module>   s    3"