Skip to content

Commit

Permalink
fix(backend): helper routes for fmtm and raw-data-api svc tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed May 20, 2024
1 parent 7bed23d commit bb6e450
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/backend/app/helpers/helper_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
UploadFile,
)
from fastapi.exceptions import HTTPException
from fastapi.responses import FileResponse, JSONResponse, Response
from fastapi.responses import FileResponse, JSONResponse, RedirectResponse, Response
from osm_fieldwork.xlsforms import xlsforms_path
from requests import get

from app.auth.osm import AuthUser, login_required
from app.central import central_deps
Expand Down Expand Up @@ -228,12 +229,37 @@ async def convert_odk_submission_json_to_geojson_wrapper(
return Response(submission_geojson.getvalue(), headers=headers)


@router.get("/view-auth-token")
@router.get("/view-raw-data-api-token")
async def get_raw_data_api_osm_token(
request: Request,
current_user: AuthUser = Depends(login_required),
):
"""Get the OSM OAuth token for a service account for raw-data-api.
The token returned by this endpoint should be used for the
RAW_DATA_API_AUTH_TOKEN environment variable.
"""
response = get(f"{settings.RAW_DATA_API_URL}/auth/login")
if not response.ok:
raise HTTPException(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
detail="Could not login to raw-data-api",
)

raw_api_login_url = response.json().get("login_url")
return RedirectResponse(raw_api_login_url)


@router.get("/view-fmtm-api-token")
async def view_user_oauth_token(
request: Request,
current_user: AuthUser = Depends(login_required),
):
"""Get the OSM OAuth token for a logged in user."""
"""Get the FMTM OSM (OAuth) token for a logged in user.
The token is encrypted with a secret key and only usable via
this FMTM instance and the osm-login-python module.
"""
cookie_name = settings.FMTM_DOMAIN.replace(".", "_")
return JSONResponse(
status_code=HTTPStatus.OK,
Expand Down

0 comments on commit bb6e450

Please sign in to comment.