{"id":13725177,"url":"https://github.com/aogier/starlette-authlib","last_synced_at":"2025-05-07T19:33:07.208Z","repository":{"id":37958890,"uuid":"241943467","full_name":"aogier/starlette-authlib","owner":"aogier","description":"A drop-in replacement for Starlette session middleware, using Authlib's jwt","archived":false,"fork":false,"pushed_at":"2024-10-15T20:42:58.000Z","size":499,"stargazers_count":61,"open_issues_count":7,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-17T07:15:35.395Z","etag":null,"topics":["asgi","authlib","jwt","jwt-middleware","starlette","starlette-middleware"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aogier.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2020-02-20T17:13:42.000Z","updated_at":"2024-10-15T20:41:17.000Z","dependencies_parsed_at":"2022-09-26T21:21:01.253Z","dependency_job_id":"218971bb-059a-479c-acd5-f777d3ab4e33","html_url":"https://github.com/aogier/starlette-authlib","commit_stats":{"total_commits":139,"total_committers":6,"mean_commits":"23.166666666666668","dds":"0.48920863309352514","last_synced_commit":"fedc5b09421b84969276c498afa41d78b78db7ef"},"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aogier%2Fstarlette-authlib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aogier%2Fstarlette-authlib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aogier%2Fstarlette-authlib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aogier%2Fstarlette-authlib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aogier","download_url":"https://codeload.github.com/aogier/starlette-authlib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224645244,"owners_count":17346106,"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":["asgi","authlib","jwt","jwt-middleware","starlette","starlette-middleware"],"created_at":"2024-08-03T01:02:15.054Z","updated_at":"2024-11-14T15:30:52.050Z","avatar_url":"https://github.com/aogier.png","language":"Python","readme":"# Starlette Authlib Middleware\n\n[![codecov](https://codecov.io/gh/aogier/starlette-authlib/branch/master/graph/badge.svg)](https://codecov.io/gh/aogier/starlette-authlib)\n[![Package version](https://badge.fury.io/py/starlette-authlib.svg)](https://pypi.org/project/starlette-authlib)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/starlette-authlib)\n\n## Introduction\n\nA drop-in replacement for Starlette session middleware, using [authlib's jwt](https://docs.authlib.org/en/latest/jose/jwt.html).\n\n## Rationale\n\nIt is sometimes necessary to integrate a Starlette-based application into more\ncomplex scenarios where other actors need to make decisions based on session\ndata. This middleware makes this possible by using a standard JWT token instead\nof the Starlette-encrypted one, thus simplifying interaction with third-party\ncomponents.\n\n## Requirements\n\n* Python 3.7+\n* Starlette 0.9+\n\n## Installation\n\n```console\npip install starlette-authlib\n```\n\n## Usage\n\nA complete example where we drop-in replace standard session middleware:\n\n```python\nfrom starlette.applications import Starlette\n\nfrom starlette_authlib.middleware import AuthlibMiddleware as SessionMiddleware\n\n\napp = Starlette()\n\napp.add_middleware(SessionMiddleware, secret_key='secret')\n```\n\nOther things you can configure either via environment variables or `.env` file:\n\n* `DOMAIN` - declare cookie domain. App must be under this domain. If empty,\n  the cookie is restricted to the subdomain of the app (this is useful when you\n  write eg. SSO portals)\n* `JWT_ALG` - one of authlib JWT [supported algorithms](https://docs.authlib.org/en/latest/specs/rfc7518.html#specs-rfc7518)\n* `JWT_SECRET` - jwt secret. Only useful for HS* algorithms, see the\n  `sample_app` folder for middleware usage w/ crypto keys.\n\n## See it in action: sample application\n\nA sample application is included, and you can run it with either Starlette-based session middleware or this one, just by setting a variable:\n\n```\n# run with vanilla Starlette-based session middleware\nVANILLA=1 uvicorn sample_app.app:app\n\n# run with this drop-in replacement\nuvicorn sample_app.app:app\n```\n\nAs you can notice in code [here](sample_app/app.py), the only difference is an\nimport name, based on this `VANILLA` env var.\n\n## Contributing\n\nThis project is absolutely open to contributions so if you have a nice idea,\ncreate an issue to let the community discuss it.\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faogier%2Fstarlette-authlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faogier%2Fstarlette-authlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faogier%2Fstarlette-authlib/lists"}