{"id":24093205,"url":"https://github.com/umd-lib/requests-jwtauth","last_synced_at":"2025-06-28T18:36:45.156Z","repository":{"id":166540467,"uuid":"642004158","full_name":"umd-lib/requests-jwtauth","owner":"umd-lib","description":"Authenticator plugins for Requests that support JWT bearer tokens","archived":false,"fork":false,"pushed_at":"2024-01-04T19:57:46.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-05-29T22:46:54.118Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/umd-lib.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":"2023-05-17T15:57:53.000Z","updated_at":"2023-05-17T15:58:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"efbbeb28-4144-42d0-9332-366487bf4eb5","html_url":"https://github.com/umd-lib/requests-jwtauth","commit_stats":null,"previous_names":["umd-lib/requests-jwtauth"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/umd-lib/requests-jwtauth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umd-lib%2Frequests-jwtauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umd-lib%2Frequests-jwtauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umd-lib%2Frequests-jwtauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umd-lib%2Frequests-jwtauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/umd-lib","download_url":"https://codeload.github.com/umd-lib/requests-jwtauth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umd-lib%2Frequests-jwtauth/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262477635,"owners_count":23317527,"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":"2025-01-10T09:26:00.350Z","updated_at":"2025-06-28T18:36:45.151Z","avatar_url":"https://github.com/umd-lib.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# requests-jwtauth\n\nAuthenticator plugins for [Requests] that support JWT bearer tokens.\n\n## Description\n\nThis package contains two classes, `HTTPBearerAuth` and `JWTSecretAuth`,\nthat implement the [AuthBase] interface from the [Requests] package. The\n`HTTPBearerAuth` class takes a single bearer token value at initialization,\nand adds that to an `Authorization: Bearer` header. The\n`JWTSecretAuth` class takes a shared secret, and uses that to generate and\nsign short-lived [JWT] tokens to be added to an `Authorization: Bearer`\nrequest header. By default, these tokens are valid for 1 hour (3600\nseconds), and may contain arbitrary [JWT claims] in their payload.\n\n## Dependencies\n\n* Python 3.8+\n* [Requests]\n* [JWCrypto]\n\n## Installation\n\n```bash\npip install requests-jwtauth\n```\n\n## Usage\n\n### HTTPBearerAuth\n\n```python\nimport requests\nfrom requests_jwtauth import HTTPBearerAuth\n\n# send a request with a pre-obtained bearer token\nmy_token = '...'\nr = requests.get('http://example.com', auth=HTTPBearerAuth(my_token))\n```\n\n### JWTSecretAuth\n\n```python\nimport requests\nfrom requests_jwtauth import JWTSecretAuth\n\n# use a shared secret to generate (and automatically regenerate)\n# short-lived JWT bearer tokens\n\nsecret_auth = JWTSecretAuth(\n    # shared secret with the service that requires authentication\n    secret='...',\n    # JWT claims to place in the token payload\n    # this class takes care of providing the 'exp' (expiration time) key\n    claims={\n        'sub': '...'\n    },\n    # Time-To-Live, in seconds; default is 3600 (i.e., 1 hour)\n    ttl=3600,\n    # instead of waiting for it to actually expire,\n    # renew the token whenever the remaining time-to-live is\n    # less than this number of seconds; default is 60\n    expiration_buffer=60,\n    # signing algorithm to use; defaults to H256\n    signing_algorithm='H256'\n)\n\nr = requests.get('http://example.com', auth=secret_auth)\n```\n\n## Development Setup\n\n```bash\ngit clone git@github.com:umd-lib/requests-jwtauth.git\ncd requests-jwtauth\npyenv install $(cat .python-version) --skip-existing\npython -m venv .venv --prompt \"requests-jwtauth-py$(cat .python-version)\"\nsource .venv/bin/activate\npip install -e .[test]\n```\n\n### Testing\n\nUsing [pytest]:\n\n```bash\npytest\n```\n\nWith [test coverage] information:\n\n```bash\npytest --cov-report=term-missing --cov src\n```\n\n[Requests]: https://pypi.org/project/requests/\n[AuthBase]: https://docs.python-requests.org/en/latest/user/authentication/#new-forms-of-authentication\n[JWCrypto]: https://pypi.org/project/jwcrypto/\n[JWT]: https://datatracker.ietf.org/doc/html/rfc7519\n[JWT claims]: https://datatracker.ietf.org/doc/html/rfc7519#section-4\n[pytest]: https://docs.pytest.org/en/latest/\n[test coverage]: https://pytest-cov.readthedocs.io/en/latest/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumd-lib%2Frequests-jwtauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fumd-lib%2Frequests-jwtauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumd-lib%2Frequests-jwtauth/lists"}