
    ,h&5                        d dl 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 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mZ d dlmZmZ  G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z
 G d de      Zy)    N)	b64decode)Optional)HTTPException)HTTPBase)
HTTPBearer)SecurityBase)get_authorization_scheme_param)	BaseModel)Request)HTTP_401_UNAUTHORIZEDHTTP_403_FORBIDDEN)	AnnotatedDocc                   R    e Zd ZU dZee ed      f   ed<   ee ed      f   ed<   y)HTTPBasicCredentialsz
    The HTTP Basic credentials given as the result of using `HTTPBasic` in a
    dependency.

    Read more about it in the
    [FastAPI docs for HTTP Basic Auth](https://fastapi.tiangolo.com/advanced/security/http-basic-auth/).
    zThe HTTP Basic username.usernamezThe HTTP Basic password.passwordN__name__
__module____qualname____doc__r   strr   __annotations__     W/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/fastapi/security/http.pyr   r      s5     S!;<<==S!;<<==r   r   c                   R    e Zd ZU dZee ed      f   ed<   ee ed      f   ed<   y)HTTPAuthorizationCredentialsa  
    The HTTP authorization credentials in the result of using `HTTPBearer` or
    `HTTPDigest` in a dependency.

    The HTTP authorization header value is split by the first space.

    The first part is the `scheme`, the second part is the `credentials`.

    For example, in an HTTP Bearer token scheme, the client will send a header
    like:

    ```
    Authorization: Bearer deadbeef12346
    ```

    In this case:

    * `scheme` will have the value `"Bearer"`
    * `credentials` will have the value `"deadbeef12346"`
    zX
            The HTTP authorization scheme extracted from the header value.
            schemez]
            The HTTP authorization credentials extracted from the header value.
            credentialsNr   r   r   r   r   r      sO    * 	
	  	
	 r   r   c            	       P    e Zd Zdddddedee   dee   defdZd	ed
ee   fdZ	y)r   NTscheme_namedescription
auto_errorr    r$   r%   r&   c                t    t        ||      | _        |xs | j                  j                  | _        || _        y )Nr    r%   HTTPBaseModelmodel	__class__r   r$   r&   )selfr    r$   r%   r&   s        r   __init__zHTTPBase.__init__F   s0     #&kJ
&A$..*A*A$r   requestreturnc                    K   |j                   j                  d      }t        |      \  }}|r|r|s| j                  rt	        t
        d      y t        ||      S w)NAuthorizationNot authenticatedstatus_codedetailr    r!   )headersgetr	   r&   r   r   r   r-   r/   authorizationr    r!   s        r   __call__zHTTPBase.__call__R   s^       ++O<<]K&[# 2;N  +6{SSs   AA)
r   r   r   r   r   boolr.   r   r   r<   r   r   r   r   r   E   s`    
 &*%)
% 
% c]	
%
 c]
% 
%TT	.	/Tr   r   c                       e Zd ZdZddddddeee    ed      f   deee    ed      f   d	eee    ed
      f   dee ed      f   fdZ	de
dee   fdZy)	HTTPBasica5  
    HTTP Basic authentication.

    ## Usage

    Create an instance object and use that object as the dependency in `Depends()`.

    The dependency result will be an `HTTPBasicCredentials` object containing the
    `username` and the `password`.

    Read more about it in the
    [FastAPI docs for HTTP Basic Auth](https://fastapi.tiangolo.com/advanced/security/http-basic-auth/).

    ## Example

    ```python
    from typing import Annotated

    from fastapi import Depends, FastAPI
    from fastapi.security import HTTPBasic, HTTPBasicCredentials

    app = FastAPI()

    security = HTTPBasic()


    @app.get("/users/me")
    def read_current_user(credentials: Annotated[HTTPBasicCredentials, Depends(security)]):
        return {"username": credentials.username, "password": credentials.password}
    ```
    NT)r$   realmr%   r&   r$   
                Security scheme name.

                It will be included in the generated OpenAPI (e.g. visible at `/docs`).
                r@   zB
                HTTP Basic authentication realm.
                r%   
                Security scheme description.

                It will be included in the generated OpenAPI (e.g. visible at `/docs`).
                r&   a  
                By default, if the HTTP Basic authentication is not provided (a
                header), `HTTPBasic` will automatically cancel the request and send the
                client an error.

                If `auto_error` is set to `False`, when the HTTP Basic authentication
                is not available, instead of erroring out, the dependency result will
                be `None`.

                This is useful when you want to have optional authentication.

                It is also useful when you want to have authentication that can be
                provided in one of multiple optional ways (for example, in HTTP Basic
                authentication or in an HTTP Bearer token).
                c                    t        d|      | _        |xs | j                  j                  | _        || _        || _        y )Nbasicr(   )r*   r+   r,   r   r$   r@   r&   )r-   r$   r@   r%   r&   s        r   r.   zHTTPBasic.__init__   s8    h #'{K
&A$..*A*A
$r   r/   r0   c                   K   |j                   j                  d      }t        |      \  }}| j                  rdd| j                   di}nddi}|r|j	                         dk7  r| j
                  rt        t        d|      y t        t        d	|      }	 t        |      j                  d
      }|j                  d      \  }}	}
|	s|t        ||
      S # t        t        t        j                  f$ r |w xY ww)Nr2   zWWW-AuthenticatezBasic realm=""BasicrD   r3   )r5   r6   r8   "Invalid authentication credentialsascii:)r   r   )r8   r9   r	   r@   lowerr&   r   r   r   decode
ValueErrorUnicodeDecodeErrorbinasciiError	partitionr   )r-   r/   r;   r    paramunauthorized_headersinvalid_user_credentials_excdatar   	separatorr   s              r   r<   zHTTPBasic.__call__   s      ++O<6}E::$6-

|ST8U#V $6#@ ' 9# 5.0  '4-7((
$
	/U#**73D )-s(;%)X..#XII .? 	/..	/s   BC:C 0&C:!C77C:)r   r   r   r   r   r   r   r   r=   r.   r   r   r<   r   r   r   r?   r?   a   s    X   ( e7% SM	
7% SM
7%* SM	
+7%> 
?7%rJJ	&	'Jr   r?   c                       e Zd ZdZddddddeee    ed      f   deee    ed      f   d	eee    ed
      f   dee ed      f   fdZ	de
dee   fdZy)r   a  
    HTTP Bearer token authentication.

    ## Usage

    Create an instance object and use that object as the dependency in `Depends()`.

    The dependency result will be an `HTTPAuthorizationCredentials` object containing
    the `scheme` and the `credentials`.

    ## Example

    ```python
    from typing import Annotated

    from fastapi import Depends, FastAPI
    from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer

    app = FastAPI()

    security = HTTPBearer()


    @app.get("/users/me")
    def read_current_user(
        credentials: Annotated[HTTPAuthorizationCredentials, Depends(security)]
    ):
        return {"scheme": credentials.scheme, "credentials": credentials.credentials}
    ```
    NT)bearerFormatr$   r%   r&   rX   zBearer token format.r$   rA   r%   rB   r&   a  
                By default, if the HTTP Bearer token is not provided (in an
                `Authorization` header), `HTTPBearer` will automatically cancel the
                request and send the client an error.

                If `auto_error` is set to `False`, when the HTTP Bearer token
                is not available, instead of erroring out, the dependency result will
                be `None`.

                This is useful when you want to have optional authentication.

                It is also useful when you want to have authentication that can be
                provided in one of multiple optional ways (for example, in an HTTP
                Bearer token or in a cookie).
                c                t    t        ||      | _        |xs | j                  j                  | _        || _        y )N)rX   r%   )HTTPBearerModelr+   r,   r   r$   r&   )r-   rX   r$   r%   r&   s        r   r.   zHTTPBearer.__init__   s1    Z %,KX
&A$..*A*A$r   r/   r0   c                    K   |j                   j                  d      }t        |      \  }}|r|r|s| j                  rt	        t
        d      y |j                         dk7  r| j                  rt	        t
        d      y t        ||      S w)Nr2   r3   r4   bearerrH   r7   r8   r9   r	   r&   r   r   rK   r   r:   s        r   r<   zHTTPBearer.__call__-         ++O<<]K&[# 2;N  <<>X%# 2? 
 +6{SS   BBr   r   r   r   r   r   r   r   r=   r.   r   r   r<   r   r   r   r   r      s    D OS  ( W/%  s3I/J JK/% SM	
	/% SM	
/%0 
1/%bTT	.	/Tr   r   c                       e Zd ZdZdddddeee    ed      f   deee    ed      f   d	ee ed
      f   fdZ	de
dee   fdZy)
HTTPDigesta  
    HTTP Digest authentication.

    ## Usage

    Create an instance object and use that object as the dependency in `Depends()`.

    The dependency result will be an `HTTPAuthorizationCredentials` object containing
    the `scheme` and the `credentials`.

    ## Example

    ```python
    from typing import Annotated

    from fastapi import Depends, FastAPI
    from fastapi.security import HTTPAuthorizationCredentials, HTTPDigest

    app = FastAPI()

    security = HTTPDigest()


    @app.get("/users/me")
    def read_current_user(
        credentials: Annotated[HTTPAuthorizationCredentials, Depends(security)]
    ):
        return {"scheme": credentials.scheme, "credentials": credentials.credentials}
    ```
    NTr#   r$   rA   r%   rB   r&   a  
                By default, if the HTTP Digest is not provided, `HTTPDigest` will
                automatically cancel the request and send the client an error.

                If `auto_error` is set to `False`, when the HTTP Digest is not
                available, instead of erroring out, the dependency result will
                be `None`.

                This is useful when you want to have optional authentication.

                It is also useful when you want to have authentication that can be
                provided in one of multiple optional ways (for example, in HTTP
                Digest or in a cookie).
                c                t    t        d|      | _        |xs | j                  j                  | _        || _        y )Ndigestr(   r)   )r-   r$   r%   r&   s       r   r.   zHTTPDigest.__init__d  s1    V #(L
&A$..*A*A$r   r/   r0   c                    K   |j                   j                  d      }t        |      \  }}|r|r|s| j                  rt	        t
        d      y |j                         dk7  r| j                  rt	        t
        d      y t        ||      S w)Nr2   r3   r4   rd   rH   r7   r]   r:   s        r   r<   zHTTPDigest.__call__  r^   r_   r`   r   r   r   rb   rb   D  s    V  & S-% SM	
-% SM	
-%. 
/-%^TT	.	/Tr   rb   )rO   base64r   typingr   fastapi.exceptionsr   fastapi.openapi.modelsr   r*   r   rZ   fastapi.security.baser   fastapi.security.utilsr	   pydanticr
   starlette.requestsr   starlette.statusr   r   typing_extensionsr   r   r   r   r?   rb   r   r   r   <module>rp      s       , < @ . A  & F ,
>9 
>%9 %PT| T8xJ xJveT eTPcT cTr   