You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This repo is just a working Flask app that shows the usage of flask-authz (see: https://github.com/pycasbin/flask-authz/blob/master/app.py). To use it in your existing Flask app, you need:
22
-
24
+
Module Usage:
23
25
```python
24
-
from authz.middleware import CasbinMiddleware
25
-
import casbin
26
26
from flask import Flask
27
+
from flask_authz import CasbinEnforcer
28
+
from casbin.persist.adapters import FileAdapter
27
29
28
30
app = Flask(__name__)
31
+
# Set up Casbin model config
32
+
app.config['CASBIN_MODEL'] ='casbinmodel.conf'
33
+
# Set headers where owner for enforcement policy should be located
This example file can be found in `tests/casbin_files`
48
71
```csv
49
72
p, alice, /dataset1/*, GET
50
73
p, alice, /dataset1/resource1, POST
@@ -59,24 +82,31 @@ p, anonymous, /, GET
59
82
g, cathy, dataset1_admin
60
83
```
61
84
62
-
It means ``anonymous`` user can only access homepage ``/``. Admin users like alice can access any pages. Currently all accesses are regarded as ``anonymous``. Add your authentication to let a user log in.
63
-
64
-
## How are subject, object, action defined?
65
-
66
-
In ``middleware.py``:
67
-
85
+
Development
86
+
------------
87
+
1. Fork
88
+
2. Install Dev ENV
68
89
```python
69
-
defcheck_permission(self, request):
70
-
# change the user, path, method as you need.
71
-
user = request.remote_user # subject
72
-
if user isNone:
73
-
user ='anonymous'
74
-
path = request.path # object
75
-
method = request.method # action
76
-
returnself.enforcer.enforce(user, path, method)
90
+
# Install Flask-Casbin with Dev packages
91
+
pip install -r dev_requirements.txt
92
+
pip install -r requirements.txt
93
+
pip install -e .
94
+
# Install Pre-commits
95
+
pre-commit install
96
+
# Create feature branch
97
+
git checkout -b feature-more-cool-stuff
98
+
# Code stuff
77
99
```
100
+
Then push your changes and create a PR
78
101
79
-
You may need to copy the ``middleware.py`` code to your project and modify it directly if you have other definitions for subject, object, action.
102
+
#### Manually Bump Version
103
+
```
104
+
bumpversion major # major release
105
+
or
106
+
bumpversion minor # minor release
107
+
or
108
+
bumpversion patch # hotfix release
109
+
```
80
110
81
111
## Documentation
82
112
@@ -95,3 +125,4 @@ For how to write authorization policy and other details, please refer to [the Ca
95
125
## License
96
126
97
127
This project is under Apache 2.0 License. See the [LICENSE](LICENSE) file for the full license text.
0 commit comments