{"id":18715129,"url":"https://github.com/cerbos/python-stytch-cerbos","last_synced_at":"2025-11-10T05:30:15.244Z","repository":{"id":103109576,"uuid":"563792465","full_name":"cerbos/python-stytch-cerbos","owner":"cerbos","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-30T03:14:38.000Z","size":55,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-16T20:32:43.170Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cerbos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-11-09T10:51:07.000Z","updated_at":"2024-12-30T03:14:41.000Z","dependencies_parsed_at":"2024-12-28T09:51:36.082Z","dependency_job_id":null,"html_url":"https://github.com/cerbos/python-stytch-cerbos","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cerbos%2Fpython-stytch-cerbos","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cerbos%2Fpython-stytch-cerbos/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cerbos%2Fpython-stytch-cerbos/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cerbos%2Fpython-stytch-cerbos/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cerbos","download_url":"https://codeload.github.com/cerbos/python-stytch-cerbos/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239576750,"owners_count":19662115,"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":[],"created_at":"2024-11-07T13:07:40.216Z","updated_at":"2025-11-10T05:30:15.197Z","avatar_url":"https://github.com/cerbos.png","language":"Python","readme":"# python-stytch-cerbos\n\nAn example application of integrating [Cerbos](https://cerbos.dev) with a [FastAPI](https://fastapi.tiangolo.com/) server using [Stytch Magic Links](https://stytch.com/docs/magic-links) for authentication.\n\n### Dependencies\n\n- Docker for running the [Cerbos Policy Decision Point (PDP)](https://docs.cerbos.dev/cerbos/latest/installation/container.html) and the FastAPI server.\n- A configured [Stytch Project](https://stytch.com/dashboard).\n\n### Set up\n\n1. Retrieve the project ID and secret from [here](https://stytch.com/dashboard/api-keys). Set the values to these env vars accordingly:\n   ```sh\n   STYTCH_PROJECT_ID\n   STYTCH_SECRET\n   ```\n\n1. Create `Login` and `Sign-up` redirect URLs as `http://localhost:3000/callback`, in the [Redirect URLs page](https://stytch.com/dashboard/redirect-urls).\n\n1. Run `docker-compose up -d` to fire up the Cerbos PDP instance and the FastAPI server.\n\n1. Navigate to `http://localhost:3000`.\n\n### Run through\n\nWhen loading up the app, you'll be greeted by the login page. You can specify a \"role\" there; either `user` or `admin`. This ultimately sends a followup request (after login/creation) to Stytch to update the `trusted_metadata` field of the `user`, via [this API](https://stytch.com/docs/api/update-user). This is retrieved on subsequent authentication checks to retrieve the user roles when verifying identity via [this API](https://stytch.com/docs/api/session-auth).\n\n**Note:** In production, you would handle the attribution of roles through some proper mechanism - the above is purely for demonstrative purposes.\n\n### Policies\n\nThis example has a simple CRUD policy in place for a resource kind of `contact` - like a CRM system would have. The policy file can be found in the `cerbos/policies` folder [here](https://github.com/cerbos/python-cognito-cerbos/blob/main/cerbos/policies/contact.yaml).\n\nShould you wish to experiment with this policy, you can \u003ca href=\"https://play.cerbos.dev/p/g561543292ospj7w0zOrFx7H5DzhmLu2\" target=\"_blank\"\u003etry it in the Cerbos Playground\u003c/a\u003e.\n\nThe policy expects one of two roles to be set on the principal - `admin` and `user`. These roles are authorized as follows:\n\n| Action | User     | Admin |\n| ------ | -------- | ----- |\n| list   | Y        | Y     |\n| read   | Y        | Y     |\n| create | Y        | Y     |\n| update | If owner | Y     |\n| delete | If owner | Y     |\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcerbos%2Fpython-stytch-cerbos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcerbos%2Fpython-stytch-cerbos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcerbos%2Fpython-stytch-cerbos/lists"}