{"id":20035813,"url":"https://github.com/officialpycasbin/django-authorization-example","last_synced_at":"2026-01-24T07:33:35.608Z","repository":{"id":262370289,"uuid":"887026492","full_name":"officialpycasbin/django-authorization-example","owner":"officialpycasbin","description":"Example for django-authorization middleware","archived":false,"fork":false,"pushed_at":"2024-11-12T03:20:24.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-20T20:53:17.261Z","etag":null,"topics":["auth","authorization","authz","django","django-framework","django-project","middleware","plugin","py","python","pythonweb"],"latest_commit_sha":null,"homepage":"https://github.com/casbin/pycasbin","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/officialpycasbin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-12T03:19:35.000Z","updated_at":"2024-11-12T03:21:11.000Z","dependencies_parsed_at":"2024-11-12T04:23:04.928Z","dependency_job_id":"8e5d5637-428b-48a5-baad-a0daeead8ebd","html_url":"https://github.com/officialpycasbin/django-authorization-example","commit_stats":null,"previous_names":["officialpycasbin/django-authorization-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/officialpycasbin%2Fdjango-authorization-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/officialpycasbin%2Fdjango-authorization-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/officialpycasbin%2Fdjango-authorization-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/officialpycasbin%2Fdjango-authorization-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/officialpycasbin","download_url":"https://codeload.github.com/officialpycasbin/django-authorization-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241465111,"owners_count":19967243,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auth","authorization","authz","django","django-framework","django-project","middleware","plugin","py","python","pythonweb"],"created_at":"2024-11-13T10:09:21.551Z","updated_at":"2026-01-24T07:33:35.571Z","avatar_url":"https://github.com/officialpycasbin.png","language":"Python","readme":"# Django-Authorization Example\n\n[Django-authorization, or dauthz](https://github.com/pycasbin/django-authorization) is an authorization library for Django framework.\n\n![image](https://user-images.githubusercontent.com/75596353/188881538-a6a99cb1-c88b-4738-bf4f-452be4fb7c2d.png)\n\n\n\n## How To Run the Example\n\n```\npip install -r requirements.txt\npython manage.py makemigrations\npython manage.py migrate\npython manage.py runserver\n```\n\n## Configure of Example: by step\n\n### 1.add the django-orm-adapter and dauthz to INSTALLED_APPS\n\n```python\nINSTALLED_APPS = [\n    ...\n    # STEP1: setup adapter(django-orm-adapter here)\n    'casbin_adapter.apps.CasbinAdapterConfig',\n    # STEP2: setup django-authorization\n    'dauthz.apps.DauthzConfig',\n    # STEP3: setup the app of your app\n    'user_management.apps.UserManagementConfig',\n    ...\n]\n```\n\n### 2.add the middlewares you need to MIDDLEWARES\n\n```python\nMIDDLEWARE = [\n    ...\n    'django.contrib.auth.middleware.AuthenticationMiddleware',\n    # STEP2: setup django-authorization\n    # be aware: should after AuthenticationMiddleware\n    \"dauthz.middlewares.request_middleware.RequestMiddleware\",\n    ...\n]\n```\n\n### 3.add more config of adapter and dauthz\n\n```python\n# STEP1: setup adapter(django-orm-adapter here)\nCASBIN_MODEL = os.path.join(BASE_DIR, 'dauthz_model.conf')\n# STEP2: setup django-authorization\nDAUTHZ = {\n    # DEFAULT Dauthz enforcer\n    \"DEFAULT\": {\n        # Casbin model setting.\n        \"MODEL\": {\n            # Available Settings: \"file\", \"text\"\n            \"CONFIG_TYPE\": \"file\",\n            \"CONFIG_FILE_PATH\": CASBIN_MODEL,\n            \"CONFIG_TEXT\": \"\",\n        },\n        # Casbin adapter.\n        \"ADAPTER\": {\n            \"NAME\": \"casbin_adapter.adapter.Adapter\",\n        },\n        \"LOG\": {\n            # Changes whether Dauthz will log messages to the Logger.\n            \"ENABLED\": False,\n        },\n    },\n}\n```\n\n### 4. Add RBAC model to database(in /user_management/apps.py)\n\n```python\np_rules = [\n        [\"anonymous\", \"/\", \"(GET)|(POST)\"],\n        [\"anonymous\", \"/login\", \"(GET)|(POST)\"],\n        [\"anonymous\", \"/register\", \"(GET)|(POST)\"],\n        [\"normal_user\", \"/logout\", \"(GET)|(POST)\"],\n        [\"admin\", \"/all_users_profile\", \"(GET)|(POST)\"],\n    ]\ng_rules = [\n    [\"normal_user\", \"anonymous\"],\n    [\"admin\", \"normal_user\"]\n]\nenforcer.add_policies(p_rules)\nenforcer.add_grouping_policies(g_rules)\nenforcer.save_policy()\n```\n\n#### Model of Example : \n\n![image](https://user-images.githubusercontent.com/75596353/189869400-d7372ed9-99d1-4302-937a-dbc07e0d6fb4.png)\n\n### 5. Completed.\n\n## License\n\nThis project is licensed under the [Apache 2.0 license](https://github.com/php-casbin/laravel-authz/blob/master/LICENSE).","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fofficialpycasbin%2Fdjango-authorization-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fofficialpycasbin%2Fdjango-authorization-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fofficialpycasbin%2Fdjango-authorization-example/lists"}