Remove obsolete endpoints (#89)
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s

Remove endpoints api/login/token and api/login/profile

---------

Co-authored-by: Thomas Peetz <thomas.peetz@cimt-ag.de>
Reviewed-on: #89
This commit was merged in pull request #89.
This commit is contained in:
2026-05-19 17:52:30 +00:00
parent f9f4a70a79
commit 6077f685e0
40 changed files with 589 additions and 152 deletions
+18 -16
View File
@@ -1,12 +1,15 @@
import logging
from datetime import datetime, timedelta, timezone
from typing import Annotated, Dict, List, Optional
from typing import Annotated, List, Optional
import bcrypt
from fastapi import Depends, HTTPException, Request, Security, status
from fastapi.openapi.models import OAuthFlows as OAuthFlowsModel
from fastapi.security import OAuth2, OAuth2PasswordBearer, SecurityScopes
from fastapi.security.utils import get_authorization_scheme_param
from fastapi import Depends, HTTPException, Security, status
#from fastapi.openapi.models import OAuthFlows as OAuthFlowsModel
from fastapi.security import (
#OAuth2,
OAuth2PasswordBearer,
SecurityScopes
)
#from fastapi.security.utils import get_authorization_scheme_param
from jose import JWTError, jwt
from pydantic import ValidationError
@@ -19,7 +22,8 @@ from src.db.repository.admin import (
is_database_empty,
)
from src.db.session import SessionLocal
from src.schema.admin import ProfileModel, TokenData
from src.schema.admin.token import TokenData
from src.schema.user.profile import ProfileModel, to_model
oauth2_scheme = OAuth2PasswordBearer(
tokenUrl="/token",
@@ -161,13 +165,7 @@ async def get_current_active_user(
) -> ProfileModel:
if not current_user.enabled:
raise HTTPException(status_code=400, detail="Inactive user")
user_model = ProfileModel(
username=current_user.user_name,
email=current_user.email, # type: ignore
first_name=current_user.first_name,
last_name=current_user.last_name, # type: ignore
active=current_user.enabled,
) # type: ignore
user_model = to_model(current_user)
return user_model
@@ -181,7 +179,7 @@ def get_current_user_from_token(token: str = Depends(oauth2_scheme)):
payload = jwt.decode(
token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM]
)
username: str = payload.get("sub") # type: ignore
username: Optional[str] = payload.get("sub")
logger.info("username/email extracted is %s", username)
if username is None:
raise credentials_exception
@@ -190,8 +188,12 @@ def get_current_user_from_token(token: str = Depends(oauth2_scheme)):
with SessionLocal() as db:
user = get_profile_by_email(email=username, db=db)
if user is None:
raise credentials_exception
user = get_profile_by_username(username=username, db=db)
if user is None:
raise credentials_exception
return user
UserDep = Annotated[Profile, Depends(get_current_user_from_token)]
CurrentUser = Annotated[Profile, Depends(get_current_active_user)]