forked from open-webui/open-webui
feat(auth): add auth middleware
- refactored chat routes to use request.user instead of doing authentication in every route
This commit is contained in:
parent
8370465796
commit
a01b112f7f
5 changed files with 63 additions and 89 deletions
|
@ -55,13 +55,13 @@ def extract_token_from_auth_header(auth_header: str):
|
|||
|
||||
def verify_token(request):
|
||||
try:
|
||||
bearer = request.headers["authorization"]
|
||||
if bearer:
|
||||
token = bearer[len("Bearer ") :]
|
||||
decoded = jwt.decode(
|
||||
authorization = request.headers["authorization"]
|
||||
if authorization:
|
||||
_, token = authorization.split()
|
||||
decoded_token = jwt.decode(
|
||||
token, JWT_SECRET_KEY, options={"verify_signature": False}
|
||||
)
|
||||
return decoded
|
||||
return decoded_token
|
||||
else:
|
||||
return None
|
||||
except Exception as e:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue