semvec/pypi-packages huggingface dataset:
jtekt-starlette-auth-middleware 0.1
An authentication middleware for FastAPI/ Starlette usage

# Introduction
This auth middleware is to be used with FastAPI.  
If the authorization passes, the request.state.user will be populated with the user information.

**Currently, the middleware uses the Authentication System developed by Maxime as a basis to run logics behind it. Therefore, please refer to the Authentication Microservice Developer (in development) guideline for more information**

To use this middleware, add `auth.py` to your filesystem and import `CustomAuthMiddleware` from it.

After that, add it to FastAPI using `app.add_middleware(...)`

Within the middleware, you can declare options. There are currently two options you can use:

|Options|Default|Input Type|Explanation|
|-|-|-|-|
|url|None|String|The URL of the authentication service you have setup.|
|strict|True|Enum(Bool)|Decides whether authentication is necessary, where True will block all failed authentication and False will assign request.state.user to None|

```python
from auth import CustomAuthMiddleware
from fastapi import FastAPI, Request

app = FastAPI()

app.add_middleware(CustomerAuthMiddleware, options={"url": url, "strict": True})

@app.get('/hi')
async def hi(request: Request):
    return {
        "message": f"hi there, {request.state.user.get('properties').get('name_kanji')}
    }
```