Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes Make OSM login mandatory for project creation #1738 #1836

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/backend/app/auth/osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import time

import jwt
from fastapi import Header, HTTPException, Request
from fastapi import Depends, Header, HTTPException, Request
from fastapi.responses import JSONResponse
from loguru import logger as log
from osm_login_python.core import Auth
Expand Down Expand Up @@ -76,6 +76,18 @@ async def login_required(
return AuthUser(**token_data)


async def osm_login_required(
request: Request, auth_user: AuthUser = Depends(login_required)
) -> AuthUser:
cookie_name = settings.FMTM_DOMAIN.replace(".", "_")
osm_cookie_name = f"{cookie_name}_osm"

if osm_cookie_name not in request.cookies:
raise HTTPException(status_code=401, detail="OSM login required")

return auth_user


def extract_token_from_cookie(request: Request) -> str:
"""Extract access token from cookies."""
cookie_name = settings.FMTM_DOMAIN.replace(".", "_")
Expand Down
3 changes: 2 additions & 1 deletion src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from sqlalchemy.sql import text

from app.auth.auth_schemas import AuthUser, OrgUserDict, ProjectUserDict
from app.auth.osm import login_required
from app.auth.osm import login_required, osm_login_required
from app.auth.roles import mapper, org_admin, project_manager
from app.central import central_crud, central_deps, central_schemas
from app.db import database, db_models
Expand Down Expand Up @@ -450,6 +450,7 @@ async def create_project(
project_info: project_schemas.ProjectUpload,
org_user_dict: OrgUserDict = Depends(org_admin),
db: Session = Depends(database.get_db),
user_data: AuthUser = Depends(osm_login_required),
):
"""Create a project in ODK Central and the local database.

Expand Down