
    ?h                        d dl mZ d dlmZmZmZ d dlmZ d dlZd dlm	Z	 d dl
mZmZmZmZ d dlmZmZ dd	lmZ dd
lmZ erddlmZ dZeeeeee   f   f   Z G d d      Zy)    )annotations)DictListUnion)TYPE_CHECKINGN)OAuth2Session)AuthCredentialsAuthClientPasswordAuthBearerTokenAuthClientCredentials)MissingScopeExceptionAuthenticationFailedException   )_decode_json_response_dict)	_Warnings   )
Connection   c                  T    e Zd Z	 	 	 	 	 	 	 	 d	dZd
dZddZddZddZddZddZ	y)_Authc                2   || _         || _        |d   }|d   }t        |t              rt        |t              sJ || _        || _        g | _        d|v r|d   }t        |t              sJ || _        | j                         | _	        | j                  |       y )NhrefclientIdscopes)_credentials_connection
isinstancestr_open_id_config_url
_client_id_default_scopeslist_get_token_endpoint_token_endpoint	_validate)selfoidc_configcredentials
connection
config_url	client_iddefault_scopess          ]/home/chris/cleankitchens-env/lib/python3.12/site-packages/weaviate/connect/authentication.py__init__z_Auth.__init__   s     .9'1 (

+	*c*z)S/III(2 (*,{"(2Nnd333#1D $($<$<$>{#    c                    t        | j                  t              r>| j                  j	                  d      rt        d      d|v rd|d   vrt        d      y y y )N!https://login.microsoftonline.comzMicrosoft/azure does not recommend to authenticate using username and password and this method is
                    not supported by the python client.grant_types_supportedpasswordzThe grant_types supported by the third-party authentication service are insufficient. Please add
                    the 'password' grant type.)r   r   r
   r$   
startswithr   )r&   r'   s     r-   r%   z_Auth._validate1   st    d'');<##../RS3;  (;6k2I&JJ32  K 7 =r/   c                    t        j                  | j                  | j                  j                        }t        |d      }|J |d   }t        |t              sJ |S )N)proxieszGet token endpointtoken_endpoint)requestsgetr   r   r6   r   r   r   )r&   response_authresponse_auth_jsonr7   s       r-   r#   z_Auth._get_token_endpointC   s_     T%=%=tGWGWG_G_`7G[\!---+,<=.#...r/   c                P   t        | j                  t              r| j                  | j                        }|S t        | j                  t              r| j                  | j                        }|S t        | j                  t              sJ | j                  | j                        }|S )N)r   r   r   _get_session_auth_bearer_tokenr   _get_session_client_credentialr
   _get_session_user_pw)r&   sessionss     r-   get_auth_sessionz_Auth.get_auth_sessionK   s    d''9::4;L;LMH  ))+@A::4;L;LMH
  d//1CDDD001B1BCHr/   c                   d|j                   i}|j                  |j                  |d<   |j                  |j                  |d<   d|vrt        j                  |j                         t        || j                  | j                  t              S )Naccess_token
expires_inrefresh_token)tokenr7   r+   default_timeout)	rC   rD   rE   r   auth_no_refresh_tokenr   r$   r    AUTH_DEFAULT_TIMEOUT)r&   configrF   s      r-   r=   z$_Auth._get_session_auth_bearer_tokenV   s    -;V=P=P,Q("("3"3E,+%+%9%9E/"%'++F,=,=> //oo0	
 	
r/   c                F   | j                   j                         }|j                  |j                         t	        | j
                  | j                  d|t              }|j                  |j                  |j                        }d|vrt        j                  |d          |S )Nr3   )r+   r7   
grant_typescoperG   )usernamer3   rE   rD   )r!   copyextend
scope_listr   r    r$   rI   fetch_tokenrN   r3   r   rH   )r&   rJ   rM   sessionrF   s        r-   r?   z_Auth._get_session_user_pwh   s    //446V&&'oo//!0
 ##V__v#W%'++E,,?@r/   c                   | j                   j                         }|j                  |j                  |j                         t	        |      dk(  r2| j
                  j                  d      r| j                  dz   g}nt        t        | j                  |j                  d|| j
                  dd ddt              }|j                          |S )	Nr   r1   z	/.defaultclient_secret_postclient_credentialsi)rC   rD   )r+   client_secrettoken_endpoint_auth_methodrM   r7   rL   rF   rG   )r!   rO   rQ   rP   lenr$   r4   r    r   r   rW   rI   rR   )r&   rJ   rM   rS   s       r-   r>   z$_Auth._get_session_client_credentialx   s    //446(LL**+u:?##../RS;67++oo ..';//+#'t<0	
 	r/   N)r'   OIDC_CONFIGr(   r	   r)   r   returnNone)r'   rZ   r[   r\   )r[   r   )r[   r   )rJ   r   r[   r   )rJ   r
   r[   r   )rJ   r   r[   r   )
__name__
__module____qualname__r.   r%   r#   rA   r=   r?   r>    r/   r-   r   r      sK    $ $ %$ 	$
 
$,$	
$ r/   r   )
__future__r   typingr   r   r   r   r8   $authlib.integrations.requests_clientr   weaviate.authr	   r
   r   r   weaviate.exceptionsr   r   utilr   warningsr   r)   r   rI   r   rZ   r   r`   r/   r-   <module>rh      sa    " $ $    >  U -  & 3c49n--.v vr/   