� K�g�4��B�ddlZddlmZddlmZddlmZddlmZ ddlm Z ddl m Z ddlmZdd lmZdd lmZdd lmZmZdd lmZmZGd �de��ZGd�de��ZGd�de ��ZGd�de��ZGd�de��Z Gd�de��ZdS)�N)� b64decode)�Optional)� HTTPException)�HTTPBase)� HTTPBearer)� SecurityBase)�get_authorization_scheme_param)� BaseModel)�Request)�HTTP_401_UNAUTHORIZED�HTTP_403_FORBIDDEN)� Annotated�Docc�l�eZdZUdZeeed��fed<eeed��fed<dS)�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/). zThe HTTP Basic username.�usernamezThe HTTP Basic password.�passwordN��__name__� __module__� __qualname__�__doc__r�strr�__annotations__���e/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/fastapi/security/http.pyrrs`�����������S�S�!;�<�<�<�=�=�=�=���S�S�!;�<�<�<�=�=�=�=�=�=rrc�l�eZdZUdZeeed��fed<eeed��fed<dS)�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. � credentialsNrrrrrrs����������* � � �� � � � � ����� � �� � � � ������rrc �d�eZdZdddd�dedeedeedefd�Zd ed eefd �Z dS) rNT�� scheme_name� description� auto_errorr r$r%r&c�f�t||���|_|p |jj|_||_dS)N�r r%�� HTTPBaseModel�model� __class__rr$r&)�selfr r$r%r&s r�__init__zHTTPBase.__init__Fs5��#�&�k�J�J�J�� �&�A�$�.�*A���$����r�request�returnc���K�|j�d��}t|��\}}|r|r|s|jrt t d����dSt ||���S)N� Authorization�Not authenticated�� status_code�detail�r r!)�headers�getr r&rr r�r-r/� authorizationr r!s r�__call__zHTTPBase.__call__Rs����� ��+�+�O�<�<� �<�]�K�K��� �� �&� �[� ��� �#� 2�;N������t�+�6�{�S�S�S�Sr) rrrrr�boolr.r rr<rrrrrEs������� &*�%)�� %� %� %�� %��c�]� %� �c�]� %� � %� %� %� %� T�� T� �.� /� T� T� T� T� T� Trrc ���eZdZdZddddd�deeeed��fdeeeed��fd eeeed ��fd eeed ��ffd �Z de dee fd�Z dS)� 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�td|���|_|p |jj|_||_||_dS)N�basicr()r*r+r,rr$r@r&)r-r$r@r%r&s rr.zHTTPBasic.__init__�s=��h#�'�{�K�K�K�� �&�A�$�.�*A����� �$����rr/r0c��K�|j�d��}t|��\}}|jrdd|j�d�i}nddi}|r|���dkr |jrt td|����dSt td |���} t|��� d ��}n"#tttj f$r|�wxYw|�d ��\}} } | s|�t|| � ��S) Nr2zWWW-Authenticatez Basic realm="�"�BasicrDr3)r5r6r8�"Invalid authentication credentials�ascii�:)rr)r8r9r r@�lowerr&rr r�decode� ValueError�UnicodeDecodeError�binascii�Error� partitionr) r-r/r;r �param�unauthorized_headers�invalid_user_credentials_exc�datar� separatorrs rr<zHTTPBasic.__call__�sO���� ��+�+�O�<�<� �6�}�E�E� ��� �:� A�$6�8U�� �8U�8U�8U�#V� � �$6��#@� �� �� � ���'� 9� 9��� �#� 5�.�0����� �t�'4�-�7�(�( �( �( �$�  /��U�#�#�*�*�7�3�3�D�D���.���?� /� /� /�.� .� /����(,���s�(;�(;�%��)�X�� /�.� .�#�X��I�I�I�Is �"B=�=C) rrrrrrrrr=r.r rr<rrrr?r?as=��������X � � �( �e7%�7%�7%�� �S�M� �C�� � � �  �7%�� �S�M� �C�� � � � �7%�*� �S�M� �C�� � � �  �+7%�>� � �C�� � � � �?7%�7%�7%�7%�rJ��J� �&� '�J�J�J�J�J�Jrr?c ���eZdZdZddddd�deeeed��fdeeeed��fd eeeed ��fd eeed ��ffd �Z de dee fd�Z dS)ra� 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&rXzBearer token format.r$rAr%rBr&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�f�t||���|_|p |jj|_||_dS)N)rXr%)�HTTPBearerModelr+r,rr$r&)r-rXr$r%r&s rr.zHTTPBearer.__init__�s6��Z%�,�K�X�X�X�� �&�A�$�.�*A���$����rr/r0c��8K�|j�d��}t|��\}}|r|r|s|jrt t d����dS|���dkr|jrt t d����dSt||���S)Nr2r3r4�bearerrHr7�r8r9r r&rr rKrr:s rr<zHTTPBearer.__call__-s����� ��+�+�O�<�<� �<�]�K�K��� �� �&� �[� ��� �#� 2�;N������t� �<�<�>�>�X� %� %��� �#� 2�?����� �t�+�6�{�S�S�S�Sr� rrrrrrrrr=r.r rr<rrrrr�s3��������DOS� � �( �W/%�/%�/%� ��� �s�s�3I�/J�/J� J�K�/%�� �S�M� �C�� � � �  � /%�� �S�M� �C�� � � �  �/%�0� � �C�� � � � �1/%�/%�/%�/%�bT��T� �.� /�T�T�T�T�T�Trrc ���eZdZdZdddd�deeeed��fdeeeed��fd eeed ��ffd �Z d e d ee fd�Z dS)� 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$rAr%rBr&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�f�td|���|_|p |jj|_||_dS)N�digestr(r))r-r$r%r&s rr.zHTTPDigest.__init__ds6��V#�(� �L�L�L�� �&�A�$�.�*A���$����rr/r0c��&K�|j�d��}t|��\}}|r|r|s|jrt t d����dS|���dkrt t d����t||���S)Nr2r3r4rbrHr7r]r:s rr<zHTTPDigest.__call__�s����� ��+�+�O�<�<� �<�]�K�K��� �� �&� �[� ��� �#� 2�;N������t� �<�<�>�>�X� %� %��.�;���� �,�6�{�S�S�S�Srr^rrrr`r`Ds ��������V � �& �S-%�-%�-%�� �S�M� �C�� � � �  �-%�� �S�M� �C�� � � �  �-%�.� � �C� � � � � �/-%�-%�-%�-%�^T��T� �.� /�T�T�T�T�T�Trr`)rO�base64r�typingr�fastapi.exceptionsr�fastapi.openapi.modelsrr*rrZ�fastapi.security.baser�fastapi.security.utilsr �pydanticr �starlette.requestsr �starlette.statusr r �typing_extensionsrrrrr?r`rrr�<module>rns%������������������,�,�,�,�,�,�<�<�<�<�<�<�@�@�@�@�@�@�.�.�.�.�.�.�A�A�A�A�A�A�������&�&�&�&�&�&�F�F�F�F�F�F�F�F�,�,�,�,�,�,�,�,� >� >� >� >� >�9� >� >� >�%�%�%�%�%�9�%�%�%�PT�T�T�T�T�|�T�T�T�8xJ�xJ�xJ�xJ�xJ��xJ�xJ�xJ�veT�eT�eT�eT�eT��eT�eT�eT�P`T�`T�`T�`T�`T��`T�`T�`T�`T�`Tr
Memory