fastapi icon indicating copy to clipboard operation
fastapi copied to clipboard

[feature] Add CookieToAuth2 middleware to convert cookies to Authorization header

Open LainezDev opened this issue 1 month ago • 0 comments

Allows developers to use cookies and authorization headers without changing authentication settings. OAuth2PasswordBearer is designed to look for the token in the authorization header of the request. The middleware that converts the token cookie into an Authorization header ensuring that when OAuth2PasswordBearer inspects the request, it finds the necessary header in the correct format. It is a simple proposal to several discussions about the use of cookies for authorization of web pages with FastAPI.

I'm looking forward to your feedback

from fastapi import FastAPI
from fastapi.middleware.cookietoauth2 import CookieToAuth2Middleware

app = FastAPI()

app.add_middleware(CookieToAuth2Middleware, cookie_name="cookie_name")

LainezDev avatar Jun 05 '24 05:06 LainezDev