2024-11-12T02:51:21,953 Created temporary directory: /tmp/pip-build-tracker-hpzr8roj 2024-11-12T02:51:21,954 Initialized build tracking at /tmp/pip-build-tracker-hpzr8roj 2024-11-12T02:51:21,955 Created build tracker: /tmp/pip-build-tracker-hpzr8roj 2024-11-12T02:51:21,955 Entered build tracker: /tmp/pip-build-tracker-hpzr8roj 2024-11-12T02:51:21,956 Created temporary directory: /tmp/pip-wheel-y6ecwm8o 2024-11-12T02:51:21,960 Created temporary directory: /tmp/pip-ephem-wheel-cache-0th1437_ 2024-11-12T02:51:22,003 Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple 2024-11-12T02:51:22,005 2 location(s) to search for versions of fastapi-casbin-auth: 2024-11-12T02:51:22,005 * https://pypi.org/simple/fastapi-casbin-auth/ 2024-11-12T02:51:22,005 * https://www.piwheels.org/simple/fastapi-casbin-auth/ 2024-11-12T02:51:22,006 Fetching project page and analyzing links: https://pypi.org/simple/fastapi-casbin-auth/ 2024-11-12T02:51:22,007 Getting page https://pypi.org/simple/fastapi-casbin-auth/ 2024-11-12T02:51:22,008 Found index url https://pypi.org/simple/ 2024-11-12T02:51:22,229 Fetched page https://pypi.org/simple/fastapi-casbin-auth/ as application/vnd.pypi.simple.v1+json 2024-11-12T02:51:22,232 Skipping link: No binaries permitted for fastapi-casbin-auth: https://files.pythonhosted.org/packages/26/6f/ed8983cfacaff21ee5b00bb4b4956e94173f4f34b5d43996a08548cb5f3d/fastapi_casbin_auth-1.0.0-py3-none-any.whl (from https://pypi.org/simple/fastapi-casbin-auth/) (requires-python:>=3.6) 2024-11-12T02:51:22,233 Found link https://files.pythonhosted.org/packages/27/dc/231c89d63933efef394c116496dc9a2dfc06c4afad2018d07e7a752a210e/fastapi_casbin_auth-1.0.0.tar.gz (from https://pypi.org/simple/fastapi-casbin-auth/) (requires-python:>=3.6), version: 1.0.0 2024-11-12T02:51:22,233 Skipping link: No binaries permitted for fastapi-casbin-auth: https://files.pythonhosted.org/packages/a7/ce/4c9d8c38ac54ac8db8925cd22642e24a132feb29a996576adea8b51b67f1/fastapi_casbin_auth-1.1.0-py3-none-any.whl (from https://pypi.org/simple/fastapi-casbin-auth/) (requires-python:>=3.6) 2024-11-12T02:51:22,234 Found link https://files.pythonhosted.org/packages/0f/95/f53a9b697d665bff1a84b7367d1a947608852402358cf04ef31ad2532ea3/fastapi_casbin_auth-1.1.0.tar.gz (from https://pypi.org/simple/fastapi-casbin-auth/) (requires-python:>=3.6), version: 1.1.0 2024-11-12T02:51:22,235 Skipping link: No binaries permitted for fastapi-casbin-auth: https://files.pythonhosted.org/packages/0e/95/f915de6d877cbe8608fe41f55ea796ccbab5f61869819356bfed5d5711f8/fastapi_casbin_auth-1.2.0-py3-none-any.whl (from https://pypi.org/simple/fastapi-casbin-auth/) (requires-python:>=3.6) 2024-11-12T02:51:22,237 Found link https://files.pythonhosted.org/packages/2d/70/c023a165d83aab3b0d9253f8a70979e9aa671ef49b94fdf7050da3e42f01/fastapi_casbin_auth-1.2.0.tar.gz (from https://pypi.org/simple/fastapi-casbin-auth/) (requires-python:>=3.6), version: 1.2.0 2024-11-12T02:51:22,238 Fetching project page and analyzing links: https://www.piwheels.org/simple/fastapi-casbin-auth/ 2024-11-12T02:51:22,239 Getting page https://www.piwheels.org/simple/fastapi-casbin-auth/ 2024-11-12T02:51:22,240 Found index url https://www.piwheels.org/simple/ 2024-11-12T02:51:22,407 Fetched page https://www.piwheels.org/simple/fastapi-casbin-auth/ as text/html 2024-11-12T02:51:22,408 Skipping link: not a file: https://www.piwheels.org/simple/fastapi-casbin-auth/ 2024-11-12T02:51:22,409 Skipping link: not a file: https://pypi.org/simple/fastapi-casbin-auth/ 2024-11-12T02:51:22,427 Given no hashes to check 1 links for project 'fastapi-casbin-auth': discarding no candidates 2024-11-12T02:51:22,428 Collecting fastapi-casbin-auth==1.0.0 2024-11-12T02:51:22,431 Created temporary directory: /tmp/pip-unpack-8l_edssb 2024-11-12T02:51:22,570 Downloading fastapi_casbin_auth-1.0.0.tar.gz (9.4 kB) 2024-11-12T02:51:22,607 Added fastapi-casbin-auth==1.0.0 from https://files.pythonhosted.org/packages/27/dc/231c89d63933efef394c116496dc9a2dfc06c4afad2018d07e7a752a210e/fastapi_casbin_auth-1.0.0.tar.gz to build tracker '/tmp/pip-build-tracker-hpzr8roj' 2024-11-12T02:51:22,609 Running setup.py (path:/tmp/pip-wheel-y6ecwm8o/fastapi-casbin-auth_79974226a0df4729b7eeeb619a05d78e/setup.py) egg_info for package fastapi-casbin-auth 2024-11-12T02:51:22,610 Created temporary directory: /tmp/pip-pip-egg-info-7t0k6mfx 2024-11-12T02:51:22,610 Preparing metadata (setup.py): started 2024-11-12T02:51:22,612 Running command python setup.py egg_info 2024-11-12T02:51:23,681 # fastapi-casbin-auth 2024-11-12T02:51:23,682 [![Build Status](https://github.com/officialpycasbin/fastapi-casbin-auth/actions/workflows/release.yml/badge.svg)](https://github.com/officialpycasbin/fastapi-casbin-auth/actions/workflows/release.yml) 2024-11-12T02:51:23,682 [![Coverage Status](https://coveralls.io/repos/github/officialpycasbin/fastapi-casbin-auth/badge.svg)](https://coveralls.io/github/officialpycasbin/fastapi-casbin-auth) 2024-11-12T02:51:23,683 [![Version](https://img.shields.io/pypi/v/fastapi-casbin-auth.svg)](https://pypi.org/project/fastapi-casbin-auth/) 2024-11-12T02:51:23,683 [![PyPI - Wheel](https://img.shields.io/pypi/wheel/fastapi-casbin-auth.svg)](https://pypi.org/project/fastapi-casbin-auth/) 2024-11-12T02:51:23,684 [![Pyversions](https://img.shields.io/pypi/pyversions/fastapi-casbin-auth.svg)](https://pypi.org/project/fastapi-casbin-auth/) 2024-11-12T02:51:23,684 [![Download](https://img.shields.io/pypi/dm/fastapi-casbin-auth.svg)](https://pypi.org/project/fastapi-casbin-auth/) 2024-11-12T02:51:23,685 [![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord&label=discord&color=5865F2)](https://discord.gg/S5UjpzGZjN) 2024-11-12T02:51:23,686 fastapi-casbin-auth is an authorization middleware for [FastAPI](https://fastapi.tiangolo.com/), it's based on [PyCasbin](https://github.com/casbin/pycasbin). 2024-11-12T02:51:23,687 ## Installation 2024-11-12T02:51:23,688 Install from pip 2024-11-12T02:51:23,689 ```bash 2024-11-12T02:51:23,690 pip install fastapi-casbin-auth 2024-11-12T02:51:23,691 ``` 2024-11-12T02:51:23,692 Clone this repo 2024-11-12T02:51:23,693 ```bash 2024-11-12T02:51:23,694 git clone https://github.com/officialpycasbin/fastapi-casbin-auth.git 2024-11-12T02:51:23,694 python setup.py install 2024-11-12T02:51:23,695 ``` 2024-11-12T02:51:23,696 ## Quickstart 2024-11-12T02:51:23,697 This middleware is designed to work with another middleware which implement `AuthenticationMiddleware` interface. 2024-11-12T02:51:23,698 ```python 2024-11-12T02:51:23,699 import base64 2024-11-12T02:51:23,699 import binascii 2024-11-12T02:51:23,701 import casbin 2024-11-12T02:51:23,702 from fastapi import FastAPI 2024-11-12T02:51:23,702 from starlette.authentication import AuthenticationBackend, AuthenticationError, SimpleUser, AuthCredentials 2024-11-12T02:51:23,703 from starlette.middleware.authentication import AuthenticationMiddleware 2024-11-12T02:51:23,704 from fastapi_casbin_auth import CasbinMiddleware 2024-11-12T02:51:23,705 app = FastAPI() 2024-11-12T02:51:23,707 class BasicAuth(AuthenticationBackend): 2024-11-12T02:51:23,708 async def authenticate(self, request): 2024-11-12T02:51:23,708 if "Authorization" not in request.headers: 2024-11-12T02:51:23,709 return None 2024-11-12T02:51:23,710 auth = request.headers["Authorization"] 2024-11-12T02:51:23,711 try: 2024-11-12T02:51:23,711 scheme, credentials = auth.split() 2024-11-12T02:51:23,712 decoded = base64.b64decode(credentials).decode("ascii") 2024-11-12T02:51:23,712 except (ValueError, UnicodeDecodeError, binascii.Error): 2024-11-12T02:51:23,713 raise AuthenticationError("Invalid basic auth credentials") 2024-11-12T02:51:23,714 username, _, password = decoded.partition(":") 2024-11-12T02:51:23,715 return AuthCredentials(["authenticated"]), SimpleUser(username) 2024-11-12T02:51:23,716 enforcer = casbin.Enforcer('../examples/rbac_model.conf', '../examples/rbac_policy.csv') 2024-11-12T02:51:23,717 app.add_middleware(CasbinMiddleware, enforcer=enforcer) 2024-11-12T02:51:23,718 app.add_middleware(AuthenticationMiddleware, backend=BasicAuth()) 2024-11-12T02:51:23,720 @app.get('/') 2024-11-12T02:51:23,720 async def index(): 2024-11-12T02:51:23,721 return "If you see this, you have been authenticated." 2024-11-12T02:51:23,722 @app.get('/dataset1/protected') 2024-11-12T02:51:23,723 async def auth_test(): 2024-11-12T02:51:23,723 return "You must be alice to see this." 2024-11-12T02:51:23,724 ``` 2024-11-12T02:51:23,725 - anonymous request 2024-11-12T02:51:23,726 ```bash 2024-11-12T02:51:23,726 curl -i http://127.0.0.1:8000/dataset1/protected 2024-11-12T02:51:23,727 ``` 2024-11-12T02:51:23,728 ```bash 2024-11-12T02:51:23,729 HTTP/1.1 403 Forbidden 2024-11-12T02:51:23,729 date: Mon, 01 Mar 2021 09:00:08 GMT 2024-11-12T02:51:23,730 server: uvicorn 2024-11-12T02:51:23,730 content-length: 11 2024-11-12T02:51:23,731 content-type: application/json 2024-11-12T02:51:23,732 "Forbidden" 2024-11-12T02:51:23,732 ``` 2024-11-12T02:51:23,733 - authenticated request 2024-11-12T02:51:23,734 ```bash 2024-11-12T02:51:23,735 curl -i -u alice:password http://127.0.0.1:8000/dataset1/protected 2024-11-12T02:51:23,735 ``` 2024-11-12T02:51:23,736 ```bash 2024-11-12T02:51:23,737 HTTP/1.1 200 OK 2024-11-12T02:51:23,737 date: Mon, 01 Mar 2021 09:04:54 GMT 2024-11-12T02:51:23,738 server: uvicorn 2024-11-12T02:51:23,738 content-length: 32 2024-11-12T02:51:23,739 content-type: application/json 2024-11-12T02:51:23,740 "You must be alice to see this." 2024-11-12T02:51:23,740 ``` 2024-11-12T02:51:23,741 It used the casbin config from `examples` folder, and you can find this demo in `demo` folder. 2024-11-12T02:51:23,742 You can also view the unit tests to understand this middleware. 2024-11-12T02:51:23,743 Besides, there is another example for `CasbinMiddleware` which is designed to work with JWT authentication. You can find 2024-11-12T02:51:23,744 it in `demo/jwt_test.py`. 2024-11-12T02:51:23,745 ## Development 2024-11-12T02:51:23,746 ### Run unit tests 2024-11-12T02:51:23,747 1. Fork/Clone repository 2024-11-12T02:51:23,748 2. Install fastapi-casbin-auth dependencies, and run `pytest` 2024-11-12T02:51:23,749 ```bash 2024-11-12T02:51:23,750 pip install -r dev_requirements.txt 2024-11-12T02:51:23,750 pip install -r requirements.txt 2024-11-12T02:51:23,751 pytest 2024-11-12T02:51:23,752 ``` 2024-11-12T02:51:23,753 ### Update requirements with pip-tools 2024-11-12T02:51:23,754 ```bash 2024-11-12T02:51:23,755 # update requirements.txt 2024-11-12T02:51:23,755 pip-compile --no-annotate --no-header --rebuild requirements.in 2024-11-12T02:51:23,756 # sync venv 2024-11-12T02:51:23,756 pip-sync 2024-11-12T02:51:23,757 ``` 2024-11-12T02:51:23,758 ### Manually Bump Version 2024-11-12T02:51:23,759 ``` 2024-11-12T02:51:23,760 bumpversion major # major release 2024-11-12T02:51:23,760 or 2024-11-12T02:51:23,761 bumpversion minor # minor release 2024-11-12T02:51:23,761 or 2024-11-12T02:51:23,762 bumpversion patch # hotfix release 2024-11-12T02:51:23,762 ``` 2024-11-12T02:51:23,764 ## Documentation 2024-11-12T02:51:23,765 The authorization determines a request based on ``{subject, object, action}``, which means what ``subject`` can perform 2024-11-12T02:51:23,765 what ``action`` on what ``object``. In this plugin, the meanings are: 2024-11-12T02:51:23,767 1. ``subject``: the logged-in user name 2024-11-12T02:51:23,767 2. ``object``: the URL path for the web resource like `dataset1/item1` 2024-11-12T02:51:23,768 3. ``action``: HTTP method like GET, POST, PUT, DELETE, or the high-level actions you defined like "read-file", " 2024-11-12T02:51:23,768 write-blog" (currently no official support in this middleware) 2024-11-12T02:51:23,770 For how to write authorization policy and other details, please refer 2024-11-12T02:51:23,770 to [the Casbin's documentation](https://casbin.org). 2024-11-12T02:51:23,771 ## Getting Help 2024-11-12T02:51:23,773 - [Casbin](https://casbin.org) 2024-11-12T02:51:23,776 ## License 2024-11-12T02:51:23,778 This project is under Apache 2.0 License. See the [LICENSE](LICENSE) file for the full license text. 2024-11-12T02:51:23,779 running egg_info 2024-11-12T02:51:23,779 creating /tmp/pip-pip-egg-info-7t0k6mfx/fastapi_casbin_auth.egg-info 2024-11-12T02:51:23,780 writing /tmp/pip-pip-egg-info-7t0k6mfx/fastapi_casbin_auth.egg-info/PKG-INFO 2024-11-12T02:51:23,780 writing dependency_links to /tmp/pip-pip-egg-info-7t0k6mfx/fastapi_casbin_auth.egg-info/dependency_links.txt 2024-11-12T02:51:23,781 writing requirements to /tmp/pip-pip-egg-info-7t0k6mfx/fastapi_casbin_auth.egg-info/requires.txt 2024-11-12T02:51:23,781 writing top-level names to /tmp/pip-pip-egg-info-7t0k6mfx/fastapi_casbin_auth.egg-info/top_level.txt 2024-11-12T02:51:23,782 writing manifest file '/tmp/pip-pip-egg-info-7t0k6mfx/fastapi_casbin_auth.egg-info/SOURCES.txt' 2024-11-12T02:51:23,824 reading manifest file '/tmp/pip-pip-egg-info-7t0k6mfx/fastapi_casbin_auth.egg-info/SOURCES.txt' 2024-11-12T02:51:23,826 adding license file 'LICENSE' 2024-11-12T02:51:23,828 writing manifest file '/tmp/pip-pip-egg-info-7t0k6mfx/fastapi_casbin_auth.egg-info/SOURCES.txt' 2024-11-12T02:51:23,937 Preparing metadata (setup.py): finished with status 'done' 2024-11-12T02:51:23,941 Source in /tmp/pip-wheel-y6ecwm8o/fastapi-casbin-auth_79974226a0df4729b7eeeb619a05d78e has version 1.0.0, which satisfies requirement fastapi-casbin-auth==1.0.0 from https://files.pythonhosted.org/packages/27/dc/231c89d63933efef394c116496dc9a2dfc06c4afad2018d07e7a752a210e/fastapi_casbin_auth-1.0.0.tar.gz 2024-11-12T02:51:23,942 Removed fastapi-casbin-auth==1.0.0 from https://files.pythonhosted.org/packages/27/dc/231c89d63933efef394c116496dc9a2dfc06c4afad2018d07e7a752a210e/fastapi_casbin_auth-1.0.0.tar.gz from build tracker '/tmp/pip-build-tracker-hpzr8roj' 2024-11-12T02:51:23,949 Created temporary directory: /tmp/pip-unpack-pby_lqtm 2024-11-12T02:51:23,950 Created temporary directory: /tmp/pip-unpack-dmq5jc7c 2024-11-12T02:51:23,951 Building wheels for collected packages: fastapi-casbin-auth 2024-11-12T02:51:23,955 Created temporary directory: /tmp/pip-wheel-c47tt9h8 2024-11-12T02:51:23,956 Building wheel for fastapi-casbin-auth (setup.py): started 2024-11-12T02:51:23,957 Destination directory: /tmp/pip-wheel-c47tt9h8 2024-11-12T02:51:23,957 Running command python setup.py bdist_wheel 2024-11-12T02:51:24,411 # fastapi-casbin-auth 2024-11-12T02:51:24,412 [![Build Status](https://github.com/officialpycasbin/fastapi-casbin-auth/actions/workflows/release.yml/badge.svg)](https://github.com/officialpycasbin/fastapi-casbin-auth/actions/workflows/release.yml) 2024-11-12T02:51:24,413 [![Coverage Status](https://coveralls.io/repos/github/officialpycasbin/fastapi-casbin-auth/badge.svg)](https://coveralls.io/github/officialpycasbin/fastapi-casbin-auth) 2024-11-12T02:51:24,413 [![Version](https://img.shields.io/pypi/v/fastapi-casbin-auth.svg)](https://pypi.org/project/fastapi-casbin-auth/) 2024-11-12T02:51:24,414 [![PyPI - Wheel](https://img.shields.io/pypi/wheel/fastapi-casbin-auth.svg)](https://pypi.org/project/fastapi-casbin-auth/) 2024-11-12T02:51:24,415 [![Pyversions](https://img.shields.io/pypi/pyversions/fastapi-casbin-auth.svg)](https://pypi.org/project/fastapi-casbin-auth/) 2024-11-12T02:51:24,415 [![Download](https://img.shields.io/pypi/dm/fastapi-casbin-auth.svg)](https://pypi.org/project/fastapi-casbin-auth/) 2024-11-12T02:51:24,416 [![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord&label=discord&color=5865F2)](https://discord.gg/S5UjpzGZjN) 2024-11-12T02:51:24,417 fastapi-casbin-auth is an authorization middleware for [FastAPI](https://fastapi.tiangolo.com/), it's based on [PyCasbin](https://github.com/casbin/pycasbin). 2024-11-12T02:51:24,419 ## Installation 2024-11-12T02:51:24,420 Install from pip 2024-11-12T02:51:24,421 ```bash 2024-11-12T02:51:24,422 pip install fastapi-casbin-auth 2024-11-12T02:51:24,422 ``` 2024-11-12T02:51:24,423 Clone this repo 2024-11-12T02:51:24,424 ```bash 2024-11-12T02:51:24,425 git clone https://github.com/officialpycasbin/fastapi-casbin-auth.git 2024-11-12T02:51:24,425 python setup.py install 2024-11-12T02:51:24,426 ``` 2024-11-12T02:51:24,427 ## Quickstart 2024-11-12T02:51:24,428 This middleware is designed to work with another middleware which implement `AuthenticationMiddleware` interface. 2024-11-12T02:51:24,429 ```python 2024-11-12T02:51:24,429 import base64 2024-11-12T02:51:24,430 import binascii 2024-11-12T02:51:24,431 import casbin 2024-11-12T02:51:24,432 from fastapi import FastAPI 2024-11-12T02:51:24,432 from starlette.authentication import AuthenticationBackend, AuthenticationError, SimpleUser, AuthCredentials 2024-11-12T02:51:24,433 from starlette.middleware.authentication import AuthenticationMiddleware 2024-11-12T02:51:24,434 from fastapi_casbin_auth import CasbinMiddleware 2024-11-12T02:51:24,434 app = FastAPI() 2024-11-12T02:51:24,436 class BasicAuth(AuthenticationBackend): 2024-11-12T02:51:24,436 async def authenticate(self, request): 2024-11-12T02:51:24,437 if "Authorization" not in request.headers: 2024-11-12T02:51:24,437 return None 2024-11-12T02:51:24,438 auth = request.headers["Authorization"] 2024-11-12T02:51:24,439 try: 2024-11-12T02:51:24,439 scheme, credentials = auth.split() 2024-11-12T02:51:24,439 decoded = base64.b64decode(credentials).decode("ascii") 2024-11-12T02:51:24,440 except (ValueError, UnicodeDecodeError, binascii.Error): 2024-11-12T02:51:24,441 raise AuthenticationError("Invalid basic auth credentials") 2024-11-12T02:51:24,442 username, _, password = decoded.partition(":") 2024-11-12T02:51:24,442 return AuthCredentials(["authenticated"]), SimpleUser(username) 2024-11-12T02:51:24,444 enforcer = casbin.Enforcer('../examples/rbac_model.conf', '../examples/rbac_policy.csv') 2024-11-12T02:51:24,445 app.add_middleware(CasbinMiddleware, enforcer=enforcer) 2024-11-12T02:51:24,446 app.add_middleware(AuthenticationMiddleware, backend=BasicAuth()) 2024-11-12T02:51:24,448 @app.get('/') 2024-11-12T02:51:24,448 async def index(): 2024-11-12T02:51:24,449 return "If you see this, you have been authenticated." 2024-11-12T02:51:24,450 @app.get('/dataset1/protected') 2024-11-12T02:51:24,451 async def auth_test(): 2024-11-12T02:51:24,452 return "You must be alice to see this." 2024-11-12T02:51:24,452 ``` 2024-11-12T02:51:24,453 - anonymous request 2024-11-12T02:51:24,455 ```bash 2024-11-12T02:51:24,455 curl -i http://127.0.0.1:8000/dataset1/protected 2024-11-12T02:51:24,456 ``` 2024-11-12T02:51:24,457 ```bash 2024-11-12T02:51:24,458 HTTP/1.1 403 Forbidden 2024-11-12T02:51:24,458 date: Mon, 01 Mar 2021 09:00:08 GMT 2024-11-12T02:51:24,459 server: uvicorn 2024-11-12T02:51:24,460 content-length: 11 2024-11-12T02:51:24,460 content-type: application/json 2024-11-12T02:51:24,461 "Forbidden" 2024-11-12T02:51:24,462 ``` 2024-11-12T02:51:24,463 - authenticated request 2024-11-12T02:51:24,465 ```bash 2024-11-12T02:51:24,465 curl -i -u alice:password http://127.0.0.1:8000/dataset1/protected 2024-11-12T02:51:24,466 ``` 2024-11-12T02:51:24,467 ```bash 2024-11-12T02:51:24,468 HTTP/1.1 200 OK 2024-11-12T02:51:24,468 date: Mon, 01 Mar 2021 09:04:54 GMT 2024-11-12T02:51:24,469 server: uvicorn 2024-11-12T02:51:24,470 content-length: 32 2024-11-12T02:51:24,470 content-type: application/json 2024-11-12T02:51:24,471 "You must be alice to see this." 2024-11-12T02:51:24,472 ``` 2024-11-12T02:51:24,473 It used the casbin config from `examples` folder, and you can find this demo in `demo` folder. 2024-11-12T02:51:24,474 You can also view the unit tests to understand this middleware. 2024-11-12T02:51:24,476 Besides, there is another example for `CasbinMiddleware` which is designed to work with JWT authentication. You can find 2024-11-12T02:51:24,476 it in `demo/jwt_test.py`. 2024-11-12T02:51:24,477 ## Development 2024-11-12T02:51:24,478 ### Run unit tests 2024-11-12T02:51:24,479 1. Fork/Clone repository 2024-11-12T02:51:24,479 2. Install fastapi-casbin-auth dependencies, and run `pytest` 2024-11-12T02:51:24,480 ```bash 2024-11-12T02:51:24,481 pip install -r dev_requirements.txt 2024-11-12T02:51:24,481 pip install -r requirements.txt 2024-11-12T02:51:24,481 pytest 2024-11-12T02:51:24,482 ``` 2024-11-12T02:51:24,483 ### Update requirements with pip-tools 2024-11-12T02:51:24,484 ```bash 2024-11-12T02:51:24,484 # update requirements.txt 2024-11-12T02:51:24,485 pip-compile --no-annotate --no-header --rebuild requirements.in 2024-11-12T02:51:24,485 # sync venv 2024-11-12T02:51:24,486 pip-sync 2024-11-12T02:51:24,486 ``` 2024-11-12T02:51:24,487 ### Manually Bump Version 2024-11-12T02:51:24,488 ``` 2024-11-12T02:51:24,489 bumpversion major # major release 2024-11-12T02:51:24,489 or 2024-11-12T02:51:24,489 bumpversion minor # minor release 2024-11-12T02:51:24,490 or 2024-11-12T02:51:24,490 bumpversion patch # hotfix release 2024-11-12T02:51:24,491 ``` 2024-11-12T02:51:24,492 ## Documentation 2024-11-12T02:51:24,493 The authorization determines a request based on ``{subject, object, action}``, which means what ``subject`` can perform 2024-11-12T02:51:24,493 what ``action`` on what ``object``. In this plugin, the meanings are: 2024-11-12T02:51:24,494 1. ``subject``: the logged-in user name 2024-11-12T02:51:24,495 2. ``object``: the URL path for the web resource like `dataset1/item1` 2024-11-12T02:51:24,495 3. ``action``: HTTP method like GET, POST, PUT, DELETE, or the high-level actions you defined like "read-file", " 2024-11-12T02:51:24,496 write-blog" (currently no official support in this middleware) 2024-11-12T02:51:24,497 For how to write authorization policy and other details, please refer 2024-11-12T02:51:24,497 to [the Casbin's documentation](https://casbin.org). 2024-11-12T02:51:24,498 ## Getting Help 2024-11-12T02:51:24,500 - [Casbin](https://casbin.org) 2024-11-12T02:51:24,501 ## License 2024-11-12T02:51:24,502 This project is under Apache 2.0 License. See the [LICENSE](LICENSE) file for the full license text. 2024-11-12T02:51:25,001 running bdist_wheel 2024-11-12T02:51:25,134 running build 2024-11-12T02:51:25,135 running build_py 2024-11-12T02:51:25,164 creating build/lib/fastapi_casbin_auth 2024-11-12T02:51:25,167 copying fastapi_casbin_auth/middleware.py -> build/lib/fastapi_casbin_auth 2024-11-12T02:51:25,169 copying fastapi_casbin_auth/__init__.py -> build/lib/fastapi_casbin_auth 2024-11-12T02:51:25,171 running egg_info 2024-11-12T02:51:25,200 writing fastapi_casbin_auth.egg-info/PKG-INFO 2024-11-12T02:51:25,204 writing dependency_links to fastapi_casbin_auth.egg-info/dependency_links.txt 2024-11-12T02:51:25,205 writing requirements to fastapi_casbin_auth.egg-info/requires.txt 2024-11-12T02:51:25,206 writing top-level names to fastapi_casbin_auth.egg-info/top_level.txt 2024-11-12T02:51:25,240 reading manifest file 'fastapi_casbin_auth.egg-info/SOURCES.txt' 2024-11-12T02:51:25,242 adding license file 'LICENSE' 2024-11-12T02:51:25,245 writing manifest file 'fastapi_casbin_auth.egg-info/SOURCES.txt' 2024-11-12T02:51:25,275 /usr/local/lib/python3.11/dist-packages/setuptools/_distutils/cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated. 2024-11-12T02:51:25,275 !! 2024-11-12T02:51:25,276 ******************************************************************************** 2024-11-12T02:51:25,277 Please avoid running ``setup.py`` directly. 2024-11-12T02:51:25,278 Instead, use pypa/build, pypa/installer or other 2024-11-12T02:51:25,278 standards-based tools. 2024-11-12T02:51:25,279 See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details. 2024-11-12T02:51:25,280 ******************************************************************************** 2024-11-12T02:51:25,281 !! 2024-11-12T02:51:25,282 self.initialize_options() 2024-11-12T02:51:25,303 installing to build/bdist.linux-armv7l/wheel 2024-11-12T02:51:25,304 running install 2024-11-12T02:51:25,328 running install_lib 2024-11-12T02:51:25,355 creating build/bdist.linux-armv7l/wheel 2024-11-12T02:51:25,357 creating build/bdist.linux-armv7l/wheel/fastapi_casbin_auth 2024-11-12T02:51:25,359 copying build/lib/fastapi_casbin_auth/middleware.py -> build/bdist.linux-armv7l/wheel/./fastapi_casbin_auth 2024-11-12T02:51:25,361 copying build/lib/fastapi_casbin_auth/__init__.py -> build/bdist.linux-armv7l/wheel/./fastapi_casbin_auth 2024-11-12T02:51:25,362 running install_data 2024-11-12T02:51:25,390 creating build/bdist.linux-armv7l/wheel/fastapi_casbin_auth-1.0.0.data/data 2024-11-12T02:51:25,391 warning: install_data: setup script did not provide a directory for 'README.md' -- installing right in 'build/bdist.linux-armv7l/wheel/fastapi_casbin_auth-1.0.0.data/data' 2024-11-12T02:51:25,393 copying README.md -> build/bdist.linux-armv7l/wheel/fastapi_casbin_auth-1.0.0.data/data 2024-11-12T02:51:25,394 warning: install_data: setup script did not provide a directory for 'requirements.txt' -- installing right in 'build/bdist.linux-armv7l/wheel/fastapi_casbin_auth-1.0.0.data/data' 2024-11-12T02:51:25,395 copying requirements.txt -> build/bdist.linux-armv7l/wheel/fastapi_casbin_auth-1.0.0.data/data 2024-11-12T02:51:25,396 running install_egg_info 2024-11-12T02:51:25,430 Copying fastapi_casbin_auth.egg-info to build/bdist.linux-armv7l/wheel/./fastapi_casbin_auth-1.0.0-py3.11.egg-info 2024-11-12T02:51:25,439 running install_scripts 2024-11-12T02:51:25,453 creating build/bdist.linux-armv7l/wheel/fastapi_casbin_auth-1.0.0.dist-info/WHEEL 2024-11-12T02:51:25,455 creating '/tmp/pip-wheel-c47tt9h8/fastapi_casbin_auth-1.0.0-py3-none-any.whl' and adding 'build/bdist.linux-armv7l/wheel' to it 2024-11-12T02:51:25,457 adding 'fastapi_casbin_auth/__init__.py' 2024-11-12T02:51:25,458 adding 'fastapi_casbin_auth/middleware.py' 2024-11-12T02:51:25,461 adding 'fastapi_casbin_auth-1.0.0.data/data/README.md' 2024-11-12T02:51:25,462 adding 'fastapi_casbin_auth-1.0.0.data/data/requirements.txt' 2024-11-12T02:51:25,465 adding 'fastapi_casbin_auth-1.0.0.dist-info/LICENSE' 2024-11-12T02:51:25,467 adding 'fastapi_casbin_auth-1.0.0.dist-info/METADATA' 2024-11-12T02:51:25,468 adding 'fastapi_casbin_auth-1.0.0.dist-info/WHEEL' 2024-11-12T02:51:25,469 adding 'fastapi_casbin_auth-1.0.0.dist-info/top_level.txt' 2024-11-12T02:51:25,470 adding 'fastapi_casbin_auth-1.0.0.dist-info/RECORD' 2024-11-12T02:51:25,471 removing build/bdist.linux-armv7l/wheel 2024-11-12T02:51:25,585 Building wheel for fastapi-casbin-auth (setup.py): finished with status 'done' 2024-11-12T02:51:25,587 Created wheel for fastapi-casbin-auth: filename=fastapi_casbin_auth-1.0.0-py3-none-any.whl size=10941 sha256=c0a0e541e970c1ecb08486a12770fa2a3b24d47784f364a3c1b943ad44d3e743 2024-11-12T02:51:25,588 Stored in directory: /tmp/pip-ephem-wheel-cache-0th1437_/wheels/51/ef/70/fef3d1211331000ab81ec00aa852b5552ff5614a0f7187011d 2024-11-12T02:51:25,599 Successfully built fastapi-casbin-auth 2024-11-12T02:51:25,602 Removed build tracker: '/tmp/pip-build-tracker-hpzr8roj'