Metadata-Version: 2.1
Name: fastapi-jwt
Version: 0.0.8
Summary: `FastAPI` extension for JTW Auth
Home-page: https://github.com/k4black/fastapi-jwt
Author: Konstantin Chernyshev
Author-email: kdchernyshev@gmail.com
License: UNKNOWN
Platform: UNKNOWN
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Operating System :: OS Independent
Classifier: Topic :: Internet
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development
Classifier: Typing :: Typed
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Requires-Python: <3.10,>=3.7
Description-Content-Type: text/markdown
Requires-Dist: fastapi (<0.80.0,>=0.50.0)
Requires-Dist: python-jose[cryptography] (<4.0.0,>=3.1.0)
Provides-Extra: docs
Requires-Dist: mkdocs (<2.0.0,>=1.2.0) ; extra == 'docs'
Requires-Dist: mkdocs-material (<8.0.0,>=7.1.0) ; extra == 'docs'
Requires-Dist: MkAutoDoc (<1.0.0,>=0.1.0) ; extra == 'docs'
Requires-Dist: lazydocs (<1.0.0,>=0.4.5) ; extra == 'docs'
Requires-Dist: mkdocs-include-markdown-plugin (<4.0.0,>=3.1.0) ; extra == 'docs'
Requires-Dist: mkdocs-awesome-pages-plugin (<3.0.0,>=2.5.0) ; extra == 'docs'
Requires-Dist: mike (<2.0.0,>=1.0.0) ; extra == 'docs'
Provides-Extra: test
Requires-Dist: pytest (<6.0.0,>=5.0.0) ; extra == 'test'
Requires-Dist: pytest-cov (<3.0.0,>=2.0.0) ; extra == 'test'
Requires-Dist: pytest-mock (<4.0.0,>=3.0.0) ; extra == 'test'
Requires-Dist: requests (<3.0.0,>=2.20.0) ; extra == 'test'
Requires-Dist: black (==21.5b2) ; extra == 'test'
Requires-Dist: mypy (>=0.782) ; extra == 'test'
Requires-Dist: flake8 (<4.0.0,>=3.0.0) ; extra == 'test'
Requires-Dist: isort (<6.0.0,>=5.0.6) ; extra == 'test'

# fastapi-jwt

[![Test](https://github.com/k4black/fastapi-jwt/actions/workflows/test.yml/badge.svg)](https://github.com/k4black/fastapi-jwt/actions/workflows/test.yml)
[![Publish](https://github.com/k4black/fastapi-jwt/actions/workflows/publish.yml/badge.svg)](https://github.com/k4black/fastapi-jwt/actions/workflows/publish.yml)
[![codecov](https://codecov.io/gh/k4black/fastapi-jwt/branch/master/graph/badge.svg?token=3F9J850FX2)](https://codecov.io/gh/k4black/fastapi-jwt)
[![pypi](https://img.shields.io/pypi/v/fastapi-jwt)](https://pypi.org/project/fastapi-jwt/)

Native FastAPI extension for JWT auth

---


**Documentation:** https://k4black.github.io/fastapi-jwt/  
**Source Code:** https://github.com/k4black/fastapi-jwt/  


## Installation
```shell
pip install fastapi-jwt
```


## Usage
This library made in fastapi style, so it can be used similarly with standard security features 

```python
app = FastAPI()


access_security = JwtAccessBearer(secret_key="secret_key", auto_error=False)


@app.post("/auth")
def auth():
    subject = {"username": "username", "role": "user"}
    return {"access_token": access_security.create_access_token(subject=subject)}


@app.get("/users/me")
def read_current_user(
    credentials: JwtAuthorizationCredentials = Security(access_security),
):
    return {"username": credentials["username"], "role": credentials["role"]}
```


## Alternatives 

* FastAPI docs suggest [writing it manually](https://fastapi.tiangolo.com/tutorial/security/oauth2-jwt/), but
  * code duplication  
  * opportunity for bugs

* There is nice [fastapi-jwt-auth](https://github.com/IndominusByte/fastapi-jwt-auth/), but
  * poorly supported  
  * not "fastapi-style" (not native functions parameters)

## FastAPI Integration 

There it is open and maintained [Pull Request #3305](https://github.com/tiangolo/fastapi/pull/3305) to the `fastapi` repo. Currently, not considered.

## Requirements 

* `fastapi`
* `python-jose[cryptography]`

