You can add any fields you want to a JWT payload. I’ve seen tokens that have several dozen fields and are around 4kb in size - I think that’s a bit overdoing it :) It’s not a problem from the JWT spec/browsers/servers - just adds more IO to each request.
Thanks @wshayes, my first thought is to find a viable solution to receive authorization claims/roles from an external authentication system and spend it over a microservices architecture based on FastAPI
starlette.responses.JSONResponse
) looks like this: class JSONResponse(Response):
media_type = "application/json"
def render(self, content: typing.Any) -> bytes:
return json.dumps(
content,
ensure_ascii=False,
allow_nan=False,
indent=None,
separators=(",", ":"),
).encode("utf-8")
indent=4
and separators=(", ", ": ")
in json.dumps
I think it will render closer to the "pretty" way
import json
import typing
from starlette.responses import Response
class PrettyJSONResponse(Response):
media_type = "application/json"
def render(self, content: typing.Any) -> bytes:
return json.dumps(
content,
ensure_ascii=False,
allow_nan=False,
indent=4,
separators=(", ", ": "),
).encode("utf-8")
@app.get("/", response_class=PrettyJSONResponse)
async def get_some_json():
...
var code="@app.get("/long_task", status_code=202) # 202=Accepted
async def long_task():
from backend.workers import tasks
mytask = tasks.long_task.apply_async(kwargs={'num':30})
return {'task_id': mytask.task_id}
@app.get("/long_task/status/{task_id}", status_code=200) # 200=OK
async def long_task_status(task_id: str):
from backend.workers import tasks
result = tasks.long_task.AsyncResult(task_id)
return {'status': result.status}
"
``` @app.get("/long_task", status_code=202) # 202=Accepted
async def long_task():
from backend.workers import tasks
mytask = tasks.long_task.apply_async(kwargs={'num':30})
return {'task_id': mytask.task_id}
@app.get("/long_task/status/{task_id}", status_code=200) # 200=OK
async def long_task_status(task_id: str):
from backend.workers import tasks
result = tasks.long_task.AsyncResult(task_id)
return {'status': result.status}
```
```var code="@app.get("/long_task", status_code=202) # 202=Accepted
async def long_task():
from backend.workers import tasks
mytask = tasks.long_task.apply_async(kwargs={'num':30})
return {'task_id': mytask.task_id}
@app.get("/long_task/status/{task_id}", status_code=200) # 200=OK
async def long_task_status(task_id: str):
from backend.workers import tasks
result = tasks.long_task.AsyncResult(task_id)
return {'status': result.status}";```
var code="@app.get("/long_task", status_code=202) # 202=Accepted
async def long_task():
from backend.workers import tasks
mytask = tasks.long_task.apply_async(kwargs={'num':30})
return {'task_id': mytask.task_id}
@app.get("/long_task/status/{task_id}", status_code=200) # 200=OK
async def long_task_status(task_id: str):
from backend.workers import tasks
result = tasks.long_task.AsyncResult(task_id)
return {'status': result.status}"