{ "info": { "author": "Yang Luo", "author_email": "hsluoyz@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# flask-authz\n\n[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/casbin/lobby)\n\nflask-authz is an authorization middleware for [Flask](http://flask.pocoo.org/), it's based on [PyCasbin](https://github.com/casbin/pycasbin).\n\n## Installation\n\n```\npip install flask-authz\n```\n\n## Simple Example\n\nThis repo is just a working Flask app that shows the usage of flask-authz. To use it in your existing Flask app, you need:\n\n```python\nfrom authz.middleware import CasbinMiddleware\nimport casbin\nfrom flask import Flask\n\napp = Flask(__name__)\n\n# Initialize the Casbin enforcer, load the casbin model and policy from files.\n# Change the 2nd arg to use a database.\nenforcer = casbin.Enforcer(\"authz_model.conf\", \"authz_policy.csv\")\n\napp.wsgi_app = CasbinMiddleware(app.wsgi_app, enforcer)\n\n\n@app.route(\"/\")\ndef hello_world():\n return \"Hello World!\"\n\n\nif __name__ == '__main__':\n app.run()\n```\n\n- The default policy ``authz_policy.csv`` is:\n\n```csv\np, anonymous, /, GET\np, admin, *, *\ng, alice, admin\n```\n\nIt 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.\n\n## How are subject, object, action defined?\n\nIn ``middleware.py``:\n\n```python\ndef check_permission(self, request):\n # change the user, path, method as you need.\n user = request.remote_user # subject\n if user is None:\n user = 'anonymous'\n path = request.path # object\n method = request.method # action\n return self.enforcer.enforce(user, path, method)\n```\n\nYou may need to copy the ``middleware.py`` code to your project and modify it directly if you have other definitions for subject, object, action.\n\n## Documentation\n\nThe authorization determines a request based on ``{subject, object, action}``, which means what ``subject`` can perform what ``action`` on what ``object``. In this plugin, the meanings are:\n\n1. ``subject``: the logged-in user name\n2. ``object``: the URL path for the web resource like \"dataset1/item1\"\n3. ``action``: HTTP method like GET, POST, PUT, DELETE, or the high-level actions you defined like \"read-file\", \"write-blog\"\n\nFor how to write authorization policy and other details, please refer to [the Casbin's documentation](https://casbin.org).\n\n## Getting Help\n\n- [Casbin](https://casbin.org)\n\n## License\n\nThis project is under Apache 2.0 License. See the [LICENSE](LICENSE) file for the full license text.\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/pycasbin/flask-authz", "keywords": "flask,casbin,auth,authz,acl,rbac,abac,access control,authorization,permission", "license": "Apache 2.0", "maintainer": "", "maintainer_email": "", "name": "flask-authz", "package_url": "https://pypi.org/project/flask-authz/", "platform": "", "project_url": "https://pypi.org/project/flask-authz/", "project_urls": { "Homepage": "https://github.com/pycasbin/flask-authz" }, "release_url": "https://pypi.org/project/flask-authz/0.0.1/", "requires_dist": [ "casbin", "flask", "werkzeug" ], "requires_python": ">=3.3", "summary": "An authorization middleware for Flask that supports ACL, RBAC, ABAC, based on Casbin", "version": "0.0.1" }, "last_serial": 5436730, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "9f2e7d3e0a99f1bff098c041fb108788", "sha256": "d6d39d165cdfe81009c148250f9bde110850ddf86a6dc00a14e791028d4899c4" }, "downloads": -1, "filename": "flask_authz-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "9f2e7d3e0a99f1bff098c041fb108788", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.3", "size": 10011, "upload_time": "2019-06-23T08:32:49", "url": "https://files.pythonhosted.org/packages/34/d8/f9364a03b99467ef0f1b6b7f86da3d2ab001326bf1598669038bba8842f7/flask_authz-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "10dba3526ce0adba566070f027900a83", "sha256": "0f181060e7214dad0db96d91ba19985c7a6d9f1e513b5de8c644d11ed0f4a0f0" }, "downloads": -1, "filename": "flask-authz-0.0.1.tar.gz", "has_sig": false, "md5_digest": "10dba3526ce0adba566070f027900a83", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.3", "size": 3458, "upload_time": "2019-06-23T08:32:51", "url": "https://files.pythonhosted.org/packages/98/9c/57713744cbc6f5d9bda04356bc841780b9bb9325140b279595339cd2b92e/flask-authz-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "9f2e7d3e0a99f1bff098c041fb108788", "sha256": "d6d39d165cdfe81009c148250f9bde110850ddf86a6dc00a14e791028d4899c4" }, "downloads": -1, "filename": "flask_authz-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "9f2e7d3e0a99f1bff098c041fb108788", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.3", "size": 10011, "upload_time": "2019-06-23T08:32:49", "url": "https://files.pythonhosted.org/packages/34/d8/f9364a03b99467ef0f1b6b7f86da3d2ab001326bf1598669038bba8842f7/flask_authz-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "10dba3526ce0adba566070f027900a83", "sha256": "0f181060e7214dad0db96d91ba19985c7a6d9f1e513b5de8c644d11ed0f4a0f0" }, "downloads": -1, "filename": "flask-authz-0.0.1.tar.gz", "has_sig": false, "md5_digest": "10dba3526ce0adba566070f027900a83", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.3", "size": 3458, "upload_time": "2019-06-23T08:32:51", "url": "https://files.pythonhosted.org/packages/98/9c/57713744cbc6f5d9bda04356bc841780b9bb9325140b279595339cd2b92e/flask-authz-0.0.1.tar.gz" } ] }