o
    PDio                     @   s@   d dl Z d dlZd
ddZdd Zdejfdd	Zee dS )    NFc                 C   s4   |  dpd}| }|dkrt| S td| )zH
    Generates an Azure access token based on provided credentials.
    	auth_type azureserviceprincipalz.Unrecognized auth_type authentication method: )getlower_service_principal_credentials
ValueError)token_auth_configrefreshuser_auth_typer    r   V/var/www/Datamplify/venv/lib/python3.10/site-packages/oracledb/plugins/azure_tokens.pygenerate_token#   s   r   c                 C   sN   | d | d | d d}t jd	i |}|j| d gd}d|v r%|d S dS )
zM
    Returns the access token for authentication as a service principal.
    	authority	client_idclient_credential)r   r   r   scopes)r   access_tokenNr   )msalConfidentialClientApplicationacquire_token_for_client)r	   msal_configccaauth_responser   r   r   r   1   s   r   paramsc                    s*    j dur fdd} j|d dS dS )z5
    Azure-specific hook for generating a token.
    Nc                    s   t  j| S )N)r   extra_auth_params)r
   r   r   r   token_callbackJ   s   z(azure_token_hook.<locals>.token_callback)r   )r   set)r   r   r   r   r   azure_token_hookD   s   
r   )F)r   oracledbr   r   ConnectParamsr   register_params_hookr   r   r   r   <module>   s   
