
    ,hUT                        d dl mZmZmZmZmZ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      Z G d de      Z G d de      Z
 G d de
      Z G d de
      Z G d d      Z y)    )AnyDictListOptionalUnioncast)HTTPException)OAuth2)
OAuthFlows)Form)SecurityBase)get_authorization_scheme_param)Request)HTTP_401_UNAUTHORIZEDHTTP_403_FORBIDDEN)	AnnotatedDocc                   *   e Zd ZdZddddddeeedf    ed       ed      f   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    e        ed      f   deeedf    e        ed      f   fdZ	y)OAuth2PasswordRequestFormaD  
    This is a dependency class to collect the `username` and `password` as form data
    for an OAuth2 password flow.

    The OAuth2 specification dictates that for a password flow the data should be
    collected using form data (instead of JSON) and that it should have the specific
    fields `username` and `password`.

    All the initialization parameters are extracted from the request.

    Read more about it in the
    [FastAPI docs for Simple OAuth2 with Password and Bearer](https://fastapi.tiangolo.com/tutorial/security/simple-oauth2/).

    ## Example

    ```python
    from typing import Annotated

    from fastapi import Depends, FastAPI
    from fastapi.security import OAuth2PasswordRequestForm

    app = FastAPI()


    @app.post("/login")
    def login(form_data: Annotated[OAuth2PasswordRequestForm, Depends()]):
        data = {}
        data["scopes"] = []
        for scope in form_data.scopes:
            data["scopes"].append(scope)
        if form_data.client_id:
            data["client_id"] = form_data.client_id
        if form_data.client_secret:
            data["client_secret"] = form_data.client_secret
        return data
    ```

    Note that for OAuth2 the scope `items:read` is a single scope in an opaque string.
    You could have custom internal logic to separate it by colon characters (`:`) or
    similar, and get the two parts `items` and `read`. Many applications do that to
    group and organize permissions, you could do it as well in your application, just
    know that that it is application specific, it's not part of the specification.
    N )
grant_typescope	client_idclient_secretr   
^password$patternaD  
                The OAuth2 spec says it is required and MUST be the fixed string
                "password". Nevertheless, this dependency class is permissive and
                allows not passing it. If you want to enforce it, use instead the
                `OAuth2PasswordRequestFormStrict` dependency.
                username~
                `username` string. The OAuth2 spec requires the exact field name
                `username`.
                password~
                `password` string. The OAuth2 spec requires the exact field name
                `password".
                r     
                A single string with actually several scopes separated by spaces. Each
                scope is also a string.

                For example, a single string with:

                ```python
                "items:read items:write users:read profile openid"
                ````

                would represent the scopes:

                * `items:read`
                * `items:write`
                * `users:read`
                * `profile`
                * `openid`
                r   
                If there's a `client_id`, it can be sent as part of the form fields.
                But the OAuth2 specification recommends sending the `client_id` and
                `client_secret` (if any) using HTTP Basic auth.
                r   &  
                If there's a `client_password` (and a `client_id`), they can be sent
                as part of the form fields. But the OAuth2 specification recommends
                sending the `client_id` and `client_secret` (if any) using HTTP Basic
                auth.
                c                t    || _         || _        || _        |j                         | _        || _        || _        y N)r   r   r    splitscopesr   r   )selfr   r   r    r   r   r   s          Y/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/fastapi/security/oauth2.py__init__z"OAuth2PasswordRequestForm.__init__=   s6    f %  kkm"*    )
__name__
__module____qualname____doc__r   r   strr   r   r+    r,   r*   r   r      sD   *t X   cX+ #t)&	
X+ F	
X+2 F	
3X+F F
GX+v #t)F

wX+L !#t)F	
MX+r,   r   c                   (    e Zd ZdZ	 	 	 ddee ed       ed      f   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    e        ed      f   deeedf    e        ed      f   f fdZ	 xZ
S )OAuth2PasswordRequestFormStrictaG  
    This is a dependency class to collect the `username` and `password` as form data
    for an OAuth2 password flow.

    The OAuth2 specification dictates that for a password flow the data should be
    collected using form data (instead of JSON) and that it should have the specific
    fields `username` and `password`.

    All the initialization parameters are extracted from the request.

    The only difference between `OAuth2PasswordRequestFormStrict` and
    `OAuth2PasswordRequestForm` is that `OAuth2PasswordRequestFormStrict` requires the
    client to send the form field `grant_type` with the value `"password"`, which
    is required in the OAuth2 specification (it seems that for no particular reason),
    while for `OAuth2PasswordRequestForm` `grant_type` is optional.

    Read more about it in the
    [FastAPI docs for Simple OAuth2 with Password and Bearer](https://fastapi.tiangolo.com/tutorial/security/simple-oauth2/).

    ## Example

    ```python
    from typing import Annotated

    from fastapi import Depends, FastAPI
    from fastapi.security import OAuth2PasswordRequestForm

    app = FastAPI()


    @app.post("/login")
    def login(form_data: Annotated[OAuth2PasswordRequestFormStrict, Depends()]):
        data = {}
        data["scopes"] = []
        for scope in form_data.scopes:
            data["scopes"].append(scope)
        if form_data.client_id:
            data["client_id"] = form_data.client_id
        if form_data.client_secret:
            data["client_secret"] = form_data.client_secret
        return data
    ```

    Note that for OAuth2 the scope `items:read` is a single scope in an opaque string.
    You could have custom internal logic to separate it by colon characters (`:`) or
    similar, and get the two parts `items` and `read`. Many applications do that to
    group and organize permissions, you could do it as well in your application, just
    know that that it is application specific, it's not part of the specification.


    grant_type: the OAuth2 spec says it is required and MUST be the fixed string "password".
        This dependency is strict about it. If you want to be permissive, use instead the
        OAuth2PasswordRequestForm dependency class.
    username: username string. The OAuth2 spec requires the exact field name "username".
    password: password string. The OAuth2 spec requires the exact field name "password".
    scope: Optional string. Several scopes (each one a string) separated by spaces. E.g.
        "items:read items:write users:read profile openid"
    client_id: optional string. OAuth2 recommends sending the client_id and client_secret (if any)
        using HTTP Basic auth, as: client_id:client_secret
    client_secret: optional string. OAuth2 recommends sending the client_id and client_secret (if any)
        using HTTP Basic auth, as: client_id:client_secret
    Nr   r   r   a  
                The OAuth2 spec says it is required and MUST be the fixed string
                "password". This dependency is strict about it. If you want to be
                permissive, use instead the `OAuth2PasswordRequestForm` dependency
                class.
                r   r   r    r!   r   r"   r   r#   r   r$   c                 0    t         |   ||||||       y )N)r   r   r    r   r   r   )superr+   )r)   r   r   r    r   r   r   	__class__s          r*   r+   z(OAuth2PasswordRequestFormStrict.__init__   s*    d 	!' 	 	
r,   )r   NN)r-   r.   r/   r0   r   r1   r   r   r   r+   __classcell__r7   s   @r*   r4   r4      s:   =p   aY
&	
Y
 F	
Y
0 F	
1Y
D F
EY
t #t)F

uY
J !#t)F	
KY
 Y
r,   r4   c                       e Zd ZdZ e       dddddeeeeeeee	f   f   f    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  
    This is the base class for OAuth2 authentication, an instance of it would be used
    as a dependency. All other OAuth2 classes inherit from it and customize it for
    each OAuth2 flow.

    You normally would not create a new class inheriting from it but use one of the
    existing subclasses, and maybe compose them if you want to support multiple flows.

    Read more about it in the
    [FastAPI docs for Security](https://fastapi.tiangolo.com/tutorial/security/).
    NTflowsscheme_namedescription
auto_errorr<   zA
                The dictionary of OAuth2 flows.
                r=   
                Security scheme name.

                It will be included in the generated OpenAPI (e.g. visible at `/docs`).
                r>   
                Security scheme description.

                It will be included in the generated OpenAPI (e.g. visible at `/docs`).
                r?     
                By default, if no HTTP Authorization header is provided, required for
                OAuth2 authentication, it will automatically cancel the request and
                send the client an error.

                If `auto_error` is set to `False`, when the HTTP Authorization header
                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, with OAuth2
                or in a cookie).
                c                    t        t        t        |      |      | _        |xs | j                  j
                  | _        || _        y )N)r<   r>   )OAuth2Modelr   OAuthFlowsModelmodelr7   r-   r=   r?   )r)   r<   r=   r>   r?   s        r*   r+   zOAuth2.__init__A  s=    h !.K

 'A$..*A*A$r,   requestreturnc                    K   |j                   j                  d      }|s| j                  rt        t        d      y |S w)NAuthorizationNot authenticated)status_codedetail)headersgetr?   r	   r   )r)   rG   authorizations      r*   __call__zOAuth2.__call__{  sB     ++O<# 2;N  s   >A )r-   r.   r/   r0   rE   r   r   r   r1   r   r   r   boolr+   r   rQ   r2   r,   r*   r
   r
   4  s    
,   ( e8% /4T#s(^(;#<<=
8% SM	
8%* SM	
+8%> 
?8%t	g 	(3- 	r,   r
   c                        e Zd ZdZ	 	 	 	 ddee ed      f   deee    ed      f   deeeeef       ed      f   deee    ed	      f   d
ee	 ed      f   f
 fdZ
dedee   fdZ xZS )OAuth2PasswordBearera)  
    OAuth2 flow for authentication using a bearer token obtained with a password.
    An instance of it would be used as a dependency.

    Read more about it in the
    [FastAPI docs for Simple OAuth2 with Password and Bearer](https://fastapi.tiangolo.com/tutorial/security/simple-oauth2/).
    tokenUrlz
                The URL to obtain the OAuth2 token. This would be the *path operation*
                that has `OAuth2PasswordRequestForm` as a dependency.
                r=   r@   r(   
                The OAuth2 scopes that would be required by the *path operations* that
                use this dependency.
                r>   rA   r?   rB   c                 n    |si }t        t        t        ||d            }t        |   ||||       y )N)rU   r(   )r    r;   rE   r   r   r6   r+   )r)   rU   r=   r(   r>   r?   r<   r7   s          r*   r+   zOAuth2PasswordBearer.__init__  sG    z F#HGH
 	##!	 	 	
r,   rG   rH   c                    K   |j                   j                  d      }t        |      \  }}|r|j                         dk7  r!| j                  rt        t        dddi      y |S wNrJ   bearerrK   zWWW-AuthenticateBearer)rL   rM   rN   rN   rO   r   lowerr?   r	   r   r)   rG   rP   schemeparams        r*   rQ   zOAuth2PasswordBearer.__call__  d     ++O<6}E( :# 5./:     A"A$)NNNT)r-   r.   r/   r0   r   r1   r   r   r   rR   r+   r   rQ   r8   r9   s   @r*   rT   rT     s	   8   ( wG

G
 SM	
G
* T#s(^$
+G
< SM	
=G
P 
QG
Rg (3- r,   rT   c                       e Zd ZdZ	 	 	 	 	 ddedee ed      f   deee    ed      f   deee    ed      f   d	eeeeef       ed
      f   deee    ed      f   dee	 ed      f   f fdZ
dedee   fdZ xZS )OAuth2AuthorizationCodeBearerz
    OAuth2 flow for authentication using a bearer token obtained with an OAuth2 code
    flow. An instance of it would be used as a dependency.
    authorizationUrlrU   zE
                The URL to obtain the OAuth2 token.
                
refreshUrlzT
                The URL to refresh the token and obtain a new one.
                r=   r@   r(   rV   r>   rA   r?   rB   c           
      r    |si }t        t        t        ||||d            }t        	|   ||||       y )N)rf   rU   rg   r(   )authorizationCoder;   rX   )
r)   rf   rU   rg   r=   r(   r>   r?   r<   r7   s
            r*   r+   z&OAuth2AuthorizationCodeBearer.__init__  sT    J F"(8 (",$	

 	##!	 	 	
r,   rG   rH   c                    K   |j                   j                  d      }t        |      \  }}|r|j                         dk7  r!| j                  rt        t        dddi      y |S wrZ   r]   r_   s        r*   rQ   z&OAuth2AuthorizationCodeBearer.__call__G  rb   rc   )NNNNT)r-   r.   r/   r0   r1   r   r   r   r   rR   r+   r   rQ   r8   r9   s   @r*   re   re     sD   .    ( GW
W
 
W
 SM
W
& SM	
'W
: T#s(^$
;W
L SM	
MW
` 
aW
rg (3- r,   re   c                   B    e Zd ZdZ	 ddeeee       ed      f   fdZ	y)SecurityScopesa  
    This is a special class that you can define in a parameter in a dependency to
    obtain the OAuth2 scopes required by all the dependencies in the same chain.

    This way, multiple dependencies can have different scopes, even when used in the
    same *path operation*. And with this, you can access all the scopes required in
    all those dependencies in a single place.

    Read more about it in the
    [FastAPI docs for OAuth2 scopes](https://fastapi.tiangolo.com/advanced/security/oauth2-scopes/).
    Nr(   zA
                This will be filled by FastAPI.
                c                 Z    |xs g | _         dj                  | j                         | _        y )N )r(   join	scope_str)r)   r(   s     r*   r+   zSecurityScopes.__init__c  s+    $ Lb 	  HHT[[! 	r,   r&   )
r-   r.   r/   r0   r   r   r   r1   r   r+   r2   r,   r*   rl   rl   V  s<    
* "T#Y
"r,   rl   N)!typingr   r   r   r   r   r   fastapi.exceptionsr	   fastapi.openapi.modelsr
   rD   r   rE   fastapi.param_functionsr   fastapi.security.baser   fastapi.security.utilsr   starlette.requestsr   starlette.statusr   r   typing_extensionsr   r   r   r4   rT   re   rl   r2   r,   r*   <module>rz      s|    9 9 , 8 @ ( . A & F -E+ E+PY
&? Y
xP\ Pf^6 ^BkF k\(" ("r,   