mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-12-01 17:43:15 +00:00
feat: implement session_jwt and enhance auth
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
import uuid
|
||||
|
||||
from jose import jwt
|
||||
|
||||
from application.core.settings import settings
|
||||
|
||||
|
||||
def handle_auth(request, data={}):
|
||||
if settings.AUTH_TYPE == "simple_jwt":
|
||||
if settings.AUTH_TYPE in ["simple_jwt", "session_jwt"]:
|
||||
jwt_token = request.headers.get("Authorization")
|
||||
if not jwt_token:
|
||||
return {"message": "Missing Authorization header"}
|
||||
return None
|
||||
|
||||
jwt_token = jwt_token.replace("Bearer ", "")
|
||||
|
||||
@@ -22,18 +20,9 @@ def handle_auth(request, data={}):
|
||||
)
|
||||
return decoded_token
|
||||
except Exception as e:
|
||||
return {"message": f"Authentication error: {str(e)}"}
|
||||
return {
|
||||
"message": f"Authentication error: {str(e)}",
|
||||
"error": "invalid_token",
|
||||
}
|
||||
else:
|
||||
return {"sub": "local"}
|
||||
|
||||
|
||||
def get_or_create_user_id():
|
||||
try:
|
||||
with open(settings.USER_ID_FILE, "r") as f:
|
||||
user_id = f.read().strip()
|
||||
return user_id
|
||||
except FileNotFoundError:
|
||||
user_id = str(uuid.uuid4())
|
||||
with open(settings.USER_ID_FILE, "w") as f:
|
||||
f.write(user_id)
|
||||
return user_id
|
||||
|
||||
Reference in New Issue
Block a user