Skip to content

Commit 6576796

Browse files
authored
feat: always allow OPTIONS (#16)
* feat: always allow OPTIONS Signed-off-by: Zxilly <zhouxinyu1001@gmail.com> * build: update dependency Signed-off-by: Zxilly <zhouxinyu1001@gmail.com>
1 parent 31b0edb commit 6576796

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

dev-requirements.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fastapi
2-
casbin
2+
casbin >= 1.0.0
33
pytest
44
pip-tools
55
pytest-cov

dev-requirements.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
atomicwrites==1.4.0
22
attrs==20.3.0
33
bleach==3.3.0
4+
bracex==2.2.1
45
build==0.3.0
56
bump2version==1.0.1
67
bumpversion==0.6.0
7-
casbin==0.18.1
8+
casbin==1.12.0
89
certifi==2020.12.5
910
chardet==4.0.0
1011
click==7.1.2
@@ -32,7 +33,7 @@ readme-renderer==29.0
3233
requests-toolbelt==0.9.1
3334
requests==2.25.1
3435
rfc3986==1.4.0
35-
simpleeval==0.9.10
36+
simpleeval==0.9.11
3637
six==1.15.0
3738
starlette-auth-toolkit==0.5.0
3839
starlette==0.13.6
@@ -41,4 +42,9 @@ tqdm==4.58.0
4142
twine==3.3.0
4243
urllib3==1.26.3
4344
uvicorn==0.13.4
45+
wcmatch==8.3
4446
webencodings==0.5.1
47+
48+
# The following packages are considered to be unsafe in a requirements file:
49+
# pip
50+
# setuptools

fastapi_authz/middleware.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
3030
await self.app(scope, receive, send)
3131
return
3232

33-
if self._enforce(scope, receive):
33+
if self._enforce(scope, receive) or scope["method"] == "OPTIONS":
3434
await self.app(scope, receive, send)
3535
return
3636
else:
@@ -62,6 +62,4 @@ def _enforce(self, scope: Scope, receive: Receive) -> bool:
6262

6363
user = request.user.display_name if request.user.is_authenticated else 'anonymous'
6464

65-
print(user, path, method)
66-
6765
return self.enforcer.enforce(user, path, method)

setup.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from setuptools import setup, find_packages
22
from os import path
33

4-
__version__ = "0.0.5"
54
desc_file = "README.md"
65

76
here = path.abspath(path.dirname(__file__))
@@ -23,14 +22,12 @@
2322

2423
setup(
2524
name="fastapi-authz",
26-
version=__version__,
2725
description="An authorization middleware for FastAPI that supports ACL, RBAC, ABAC, based on PyCasbin",
2826
long_description=long_description,
2927
long_description_content_type="text/markdown",
3028
author="Zxilly",
3129
author_email="zhouxinyu1001@gmail.com",
3230
url="https://github.com/pycasbin/fastapi-authz",
33-
download_url="https://github.com/pycasbin/fastapi-authz/tarball/" + __version__,
3431
license="Apache 2.0",
3532
python_requires=">=3.6",
3633
classifiers=[

tests/test_middleware.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"test_server_path, test_client_path, method, status_code, user, response_body", [
77
('/dataset1/resource2', '/dataset1/resource2', 'GET', 200, 'alice', 'ok'),
88
('/dataset1/resource2', '/dataset1/resource2', 'GET', 403, 'notalice', 'Forbidden'),
9+
('/dataset1/resource2', '/dataset1/resource2', 'OPTIONS', 200, 'notalice', 'ok'),
910
('/dataset1/resource1', '/dataset1/resource1', 'POST', 200, 'alice', 'ok'),
1011
]
1112
)

0 commit comments

Comments
 (0)