{ "info": { "author": "Dhruv Aggarwal", "author_email": "dhruvaggarwal043@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Environment :: Web Environment", "Framework :: Flask", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Topic :: Software Development :: Build Tools" ], "description": "# flask_rrbac\nRRBAC library for Flask\n\nFlask-RRBAC provides the facility to manage user access based on the assigned\nroles. The accesses are to the level of endpoint and method.\n\nIt will:\n\n- Give you helpers to figure out of a user is authorised to access your route\n or not.\n- Mixins to help ease the implementation of the models required for supporting\nthe library.\n\nHowever, it does not:\n\n- Impose a particular database or other storage method on you.\n- Create the reqiured models for you.\n- Make the required entries for you in the database.\n\n\nInstallation\n============\nInstall the extension with pip::\n\n $ pip install flask-rrbac\n\n\nConfiguring your Application\n============================\nThe most important part of an application that uses Flask-RRBAC is the\n`RoleRouteBasedACL` class. You should create one for your application \nsomewhere in your code, like this::\n\n rrbac = RoleRouteBasedACL()\n\nThe acl manager contains the code that lets your application and Flask-RRBAC\nwork together, such as what all endpoints to check for user auth, the method in\nthe endpoint, etc.\n\nOnce the actual application object has been created, you can configure it for\nacl with::\n\n rrbac.init_app(app)\n\n\nNow, once the rrbac object has been initialised with the app instance, we need\nto decorate the view functions with the following decorator::\n\n @app.route('/some_url', methods=['GET', 'POST'])\n @rrbac._authenticate\n def a_view_func():\n return Response('Blah Blah...')\n\nIn order to quickly decorate all the endpoints, you can simply do the following\nafter the app init::\n\n for module, func in app.view_functions.iteritems():\n app.view_functions[module] = rrbac._authenticate(func)\n\n\nHow `_authenticate` works\n======================\n\nDecorator to perform the checks for whether the user has access to the\nspecific endpoint or not.\n\nIf the user has the access, then he can proceed to the view function.\nOtherwise, the auth_fail_hook is called.\n\nInput::\n\n :param f: Decorated Function\n\nFor actual implementation details, please check the following functions in\n__init__.py::\n\n _check_permission\n _check_permission_against_db\n _check_permission_against_config\n\n\nSetup Requirements\n===================\nYou will need to provide the following callbacks:\n\n `RoleRouteBasedACL.user_loader` callback.\n This callback is used to reload the user object from the user ID stored in the\n session. It should take the `unicode` ID of a user, and return the\n corresponding user object. For example::\n\n @rrbac.set_user_loader\n def load_user(user_id):\n return User.get(user_id)\n\n It should return `None` (**not raise an exception**) if the ID is not valid.\n (Will be treated as an anonymous user)\n\n\n `RoleRouteBasedACL.set_auth_fail_hook` callback.\n This callback is called when the authorization fails. Defaults to abort(403).\n For example::\n\n @rrbac.set_auth_failed_hook\n def permission_denied_hook():\n abort('User is not authorized!', 403)\n\n `RoleRouteBasedACL.as_role_model` decorator.\n This decorator is used to set the model to be used for storing the roles.\n For example::\n\n @rrbac.as_role_model\n class Role(db.Model, ACLRoleMixin):\n __tablename__ = 'roles'\n\n id = db.Column(db.Integer, nullable=False, primary_key=True)\n name = db.Column(db.String(128), nullable=False)\n deleted_at = db.Column(db.DateTime, default=None, nullable=True)\n\n `RoleRouteBasedACL.as_route_model` decorator.\n This decorator is used to set the model to be used for storing the routes.\n For example::\n\n @rrbac.as_route_model\n class Route(db.Model, ACLRouteMixin):\n __tablename__ = 'routes'\n\n id = db.Column(db.Integer, nullable=False, primary_key=True)\n method = db.Column(db.String(10), nullable=False)\n rule = db.Column(db.String(255), nullable=False)\n deleted_at = db.Column(db.DateTime, default=None, nullable=True)\n\n `RoleRouteBasedACL.as_user_model` decorator.\n This decorator is used to set the model to be used for storing the users.\n For example::\n\n @rrbac.as_user_model\n class User(db.Model, ACLUserMixin, UserMixin):\n __tablename__ = 'users'\n\n id = db.Column(db.Integer, nullable=False, primary_key=True)\n name = db.Column(db.String(128), nullable=False)\n deleted_at = db.Column(db.DateTime, default=None, nullable=True)\n\n `RoleRouteBasedACL.as_user_role_map_model` decorator.\n This decorator is used to set the association class\n to be used for storing the user role mappings.\n For example::\n\n @rrbac.as_user_role_map_model\n class UserRoleMap(db.Model, ACLUserRoleMapMixin):\n __tablename__ = 'user_role_map'\n\n id = db.Column(db.Integer, nullable=False, primary_key=True)\n user_id = db.Column(\n db.Integer,\n db.ForeignKey('users.id'),\n nullable=False\n )\n role_id = db.Column(\n db.Integer,\n db.ForeignKey('roles.id'),\n nullable=False\n )\n deleted_at = db.Column(db.DateTime, default=None, nullable=True)\n\n user = db.relationship(\n 'User', backref=db.backref(\n 'user_role_map_entries',\n cascade='all,delete-orphan'\n )\n )\n role = db.relationship(\n 'Role', backref=db.backref(\n 'user_role_map_entries',\n cascade='all,delete-orphan'\n )\n )\n\n `RoleRouteBasedACL.as_role_route_map_model` decorator.\n This decorator is used to set the association class\n to be used for storing the role route mappings.\n For example::\n\n @rrbac.as_role_route_map_model\n class RoleRouteMap(db.Model, ACLRoleRouteMapMixin):\n __tablename__ = 'role_route_map'\n\n id = db.Column(db.Integer, nullable=False, primary_key=True)\n route_id = db.Column(\n db.Integer,\n db.ForeignKey('routes.id'),\n nullable=False\n )\n role_id = db.Column(\n db.Integer,\n db.ForeignKey('roles.id'),\n nullable=False\n )\n deleted_at = db.Column(db.DateTime, default=None, nullable=True)\n\n route = db.relationship(\n 'Route', backref=db.backref(\n 'role_route_map_entries',\n cascade='all,delete-orphan'\n )\n )\n role = db.relationship(\n 'Role', backref=db.backref(\n 'role_route_map_entries',\n cascade='all,delete-orphan'\n )\n )\n\n\nYour User Class\n===============\nThe class that you use to represent users needs to implement these properties\nand methods:\n\n`is_authenticated`\n This method should return `True` if the user is authenticated, i.e. they\n have provided valid credentials. (Only authenticated users will fulfill\n the criteria of `login_required`.)\n\nTo make implementing a user class easier, you can inherit from `UserMixin`,\nwhich provides default implementations for all of these properties and methods.\n(It's not required, though.)\nThis class should also inherit sqlalchemy's Model class (db.Model).\nCheck test.py for example implementation\n\n\nYour Role Class\n===============\nThe class that you use to represent roles needs to implement these properties\nand methods:\n\n`is_deleted`\n This property should return `True` if the role is deleted\n\nYou can inherit from `ACLRoleMixin`, which provides default implementations\nfor all of these properties and methods.\n(It's not required, though.)\nThis class should also inherit sqlalchemy's Model class (db.Model).\nCheck test.py for example implementation\n\n\nYour Route Class\n===============\nThe class that you use to represent routes (paths/rules) needs to implement\nthese properties and methods:\n\n`is_deleted`\n This property should return `True` if the route is deleted\n\n`get_method`\n This property should return the request method for this rule\n\n`get_rule`\n This property should return the url rule for which this route entry was\n created.\n\nYou can inherit from `ACLRouteMixin`, which provides default implementations\nfor all of these properties and methods.\n(It's not required, though.)\nThis class should also inherit sqlalchemy's Model class (db.Model).\nCheck test.py for example implementation\n\n\nYour UserRoleMap Class\n===============\nThe class that you use to represent the mapping between user and role.\nThis is an association class and it needs to implement these properties and methods:\n\n`is_deleted`\n This property should return `True` if the mapping entry is deleted\n\n`get_id`\n This property should return the id for this entry\n\n`role`\n The role attached to this map entry\n\n`user`\n The user attached to this map entry\n\nYou can inherit from `ACLUserRoleMapMixin`, which provides default implementations\nfor all of these properties and methods.\n(It's not required, though.)\nThis class should also inherit sqlalchemy's Model class (db.Model).\nCheck test.py for example implementation\n\n\nYour RoleRouteMap Class\n===============\nThe class that you use to represent the mapping between route and role.\nThis is an association class and it needs to implement these properties and methods:\n\n`is_deleted`\n This property should return `True` if the mapping entry is deleted\n\n`get_id`\n This property should return the id for this entry\n\n`role`\n The role attached to this map entry\n\n`route`\n The route attached to this map entry\n\nYou can inherit from `ACLRoleRouteMapMixin`, which provides default implementations\nfor all of these properties and methods.\n(It's not required, though.)\nThis class should also inherit sqlalchemy's Model class (db.Model).\nCheck test.py for example implementation\n\n\nExamples\n===============\nFor Examples regarding setting up the application, please follow the test\ncases. There, multiple sample apps have been set up to cover all types of\nusages of the library.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/dhruvaggarwal043/flask-rrbac", "keywords": "flask access control acl rbac", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "Flask-RRBAC", "package_url": "https://pypi.org/project/Flask-RRBAC/", "platform": "any", "project_url": "https://pypi.org/project/Flask-RRBAC/", "project_urls": { "Documentation": "https://github.com/dhruv-aggarwal/flask-rrbac/blob/master/README.md", "Homepage": "https://github.com/dhruvaggarwal043/flask-rrbac", "Source": "https://github.com/dhruv-aggarwal/flask-rrbac", "Tracker": "https://github.com/dhruv-aggarwal/flask-rrbac/issues" }, "release_url": "https://pypi.org/project/Flask-RRBAC/0.3.0/", "requires_dist": [ "Flask (>=0.10)" ], "requires_python": "~=2.6", "summary": "Role Route Based Access Control support for Flask", "version": "0.3.0" }, "last_serial": 4124412, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "079e870e8c6030166febf58b9e78b25a", "sha256": "773296a4b5c452c0d17b6e5a3e38a2aa3f4ee99cd56a210f17213dd2a143fc08" }, "downloads": -1, "filename": "Flask_RRBAC-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "079e870e8c6030166febf58b9e78b25a", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 15598, "upload_time": "2018-05-06T17:54:15", "url": "https://files.pythonhosted.org/packages/f6/24/329cfa6bfdbaed709a0ad56c3570765b3f51318b9458e36e1215302f8f7c/Flask_RRBAC-0.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f03d9a356c537147e851546962b3f0da", "sha256": "0a900a537afe60b519671b4c4f21a7ccfcd160258cb72738fb123d3a28849a7f" }, "downloads": -1, "filename": "Flask-RRBAC-0.1.1.tar.gz", "has_sig": false, "md5_digest": "f03d9a356c537147e851546962b3f0da", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9864, "upload_time": "2018-05-06T17:54:17", "url": "https://files.pythonhosted.org/packages/6f/9d/9b0ac811de83b57d5d80667c022ea97f2a9db0f611f36156af8dc02225c8/Flask-RRBAC-0.1.1.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "03a0334064d4844c869e9367ec4ca035", "sha256": "48e9c051a5de94e2d647f35d2a67cf5f7ce395636f1ad7d70a8bbff7e0db1f35" }, "downloads": -1, "filename": "Flask_RRBAC-0.2.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "03a0334064d4844c869e9367ec4ca035", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 15966, "upload_time": "2018-05-06T21:46:35", "url": "https://files.pythonhosted.org/packages/bb/69/12b16777e7e80b8e42e491991aced00ce984014a66f95bf407f9ffab3307/Flask_RRBAC-0.2.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2cdce5a887920d7b172f139386af0cd4", "sha256": "faf44441612fd55d4188fde3fd4d45e44371838978b918f5e8ef5d3990cb21b7" }, "downloads": -1, "filename": "Flask-RRBAC-0.2.0.tar.gz", "has_sig": false, "md5_digest": "2cdce5a887920d7b172f139386af0cd4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10216, "upload_time": "2018-05-06T21:47:03", "url": "https://files.pythonhosted.org/packages/dc/e3/60e8540b0fcbacacf26662019423500978e923aa75ec7d8ea10bf535ae67/Flask-RRBAC-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "6faed74a8dbee9384cf7892596d642c3", "sha256": "92fda7cb4b308d49675c1c1052d373f91985c21fb4cac69a1310273d9deaf137" }, "downloads": -1, "filename": "Flask_RRBAC-0.3.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "6faed74a8dbee9384cf7892596d642c3", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": "~=2.6", "size": 13601, "upload_time": "2018-08-01T11:59:03", "url": "https://files.pythonhosted.org/packages/7f/bb/3c05b848530ad9f6942bc55cb722dd0b57d94320fbbba0cb3c3191af4e66/Flask_RRBAC-0.3.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "db7fb5f6f213fff14a9a9c2a32bba2eb", "sha256": "fb6b3c9e9306beb69ba4babb95fbe54e7842f33725a9720df79e4131be502f4c" }, "downloads": -1, "filename": "Flask-RRBAC-0.3.0.tar.gz", "has_sig": false, "md5_digest": "db7fb5f6f213fff14a9a9c2a32bba2eb", "packagetype": "sdist", "python_version": "source", "requires_python": "~=2.6", "size": 10757, "upload_time": "2018-08-01T11:59:05", "url": "https://files.pythonhosted.org/packages/48/7a/094c65d143db6c689221932a5c48677cd570c572bf7108d3f995f7c34473/Flask-RRBAC-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6faed74a8dbee9384cf7892596d642c3", "sha256": "92fda7cb4b308d49675c1c1052d373f91985c21fb4cac69a1310273d9deaf137" }, "downloads": -1, "filename": "Flask_RRBAC-0.3.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "6faed74a8dbee9384cf7892596d642c3", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": "~=2.6", "size": 13601, "upload_time": "2018-08-01T11:59:03", "url": "https://files.pythonhosted.org/packages/7f/bb/3c05b848530ad9f6942bc55cb722dd0b57d94320fbbba0cb3c3191af4e66/Flask_RRBAC-0.3.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "db7fb5f6f213fff14a9a9c2a32bba2eb", "sha256": "fb6b3c9e9306beb69ba4babb95fbe54e7842f33725a9720df79e4131be502f4c" }, "downloads": -1, "filename": "Flask-RRBAC-0.3.0.tar.gz", "has_sig": false, "md5_digest": "db7fb5f6f213fff14a9a9c2a32bba2eb", "packagetype": "sdist", "python_version": "source", "requires_python": "~=2.6", "size": 10757, "upload_time": "2018-08-01T11:59:05", "url": "https://files.pythonhosted.org/packages/48/7a/094c65d143db6c689221932a5c48677cd570c572bf7108d3f995f7c34473/Flask-RRBAC-0.3.0.tar.gz" } ] }