{"id":22009698,"url":"https://github.com/zitadel/example-python-django-oauth","last_synced_at":"2025-05-06T18:15:40.606Z","repository":{"id":220542484,"uuid":"746585670","full_name":"zitadel/example-python-django-oauth","owner":"zitadel","description":"Example Python Django OAuth API","archived":false,"fork":false,"pushed_at":"2025-03-07T15:30:49.000Z","size":45,"stargazers_count":7,"open_issues_count":1,"forks_count":2,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-31T01:41:18.028Z","etag":null,"topics":["django","examples","oauth","python","python3","zitadel"],"latest_commit_sha":null,"homepage":"https://zitadel.com","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/zitadel.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-01-22T09:58:28.000Z","updated_at":"2025-03-07T15:30:51.000Z","dependencies_parsed_at":"2024-02-02T17:25:32.453Z","dependency_job_id":"ee7de465-4d1c-4a72-9955-e3472ecb2db8","html_url":"https://github.com/zitadel/example-python-django-oauth","commit_stats":null,"previous_names":["zitadel/example-python-django-oauth"],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zitadel%2Fexample-python-django-oauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zitadel%2Fexample-python-django-oauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zitadel%2Fexample-python-django-oauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zitadel%2Fexample-python-django-oauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zitadel","download_url":"https://codeload.github.com/zitadel/example-python-django-oauth/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252741475,"owners_count":21797027,"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":["django","examples","oauth","python","python3","zitadel"],"created_at":"2024-11-30T02:10:29.372Z","updated_at":"2025-05-06T18:15:40.583Z","avatar_url":"https://github.com/zitadel.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Example Python Django with external OAUTH Provider for an API\n\nThis repository provides a Django example for ZITADEL using OAuth to provide the API with security through permission from an external system.\nThis example is provided as companion to our [guide](https://zitadel.com/docs/examples/secure-api/django),\nwhich should produce this application when followed.\n\n## Features\n\n- OAuth integration trought introspection calls\n- Permission checks on user roles on API calls\n- Public page at `/public`\n- Authorized `/private` page for all users.\n- Authorized `/private-scoped` page for all users with `read:messages` role\n\n## Getting started\n\nIf you want to run this example directly you can fork and clone it to your system.\nBe sure to [configure ZITADEL](https://zitadel.com/docs/examples/secure-api/django#zitadel-setup) to accept requests from this API.\n\n### Prerequisites\n\nYou have to install Python as described in [their documentation](https://wiki.python.org/moin/BeginnersGuide/Download) and then download all dependencies through:\n\n```bash\npython -m pip install -r requirements.txt\n```\n\nAlternatively if you have a system with Docker and an IDE capable of running [Development Container](https://containers.dev/),\ndefinitions are provided with a complete Python environment, configuration and tools required for Django development.\nUse your IDE to build and launch the development environment or use GitHub code spaces from your browser.\n\n### Django\n\nFill in the `.env`-file in your directory with the following information:\n\n```bash\nZITADEL_INTROSPECTION_URL = 'URL to the introspection endpoint to verify the provided token'\nZITADEL_DOMAIN = 'Domain used as audience in the token verification'\nAPI_PRIVATE_KEY_FILE_PATH = 'Path to the key.json created in ZITADEL'\n```\n\nIt should look something like this:\n\n```bash\nZITADEL_INTROSPECTION_URL = 'https://example.zitadel.cloud/oauth/v2/introspect'\nZITADEL_DOMAIN = 'https://example.zitadel.cloud'\nAPI_PRIVATE_KEY_FILE_PATH = '/tmp/example/250719519163548112.json'\n```\n\nRun database migrations:\n\n```bash\npython manage.py migrate\n```\n\nAnd run the server:\n\n```bash\npython manage.py runserver\n```\n\nVisit [http://localhost:8000/api/public](http://localhost:8000/api/public) to see if the server is running correctly.\nThen you can call [http://localhost:8000/api/private](http://localhost:8000/api/private) for example with CURL:\n\n```bash\nexport TOKEN='eyJhbGciOiJSUzI1NiIsImtpZCI6IjI1MD...'\ncurl -H \"Authorization: Bearer $TOKEN\" -X GET http://localhost:8000/api/private\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzitadel%2Fexample-python-django-oauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzitadel%2Fexample-python-django-oauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzitadel%2Fexample-python-django-oauth/lists"}