fix for strava auth
This commit is contained in:
@@ -48,6 +48,7 @@ data_dir: Path | None = None
|
||||
site_dir: Path | None = None # for post-write rebuild trigger
|
||||
strava_client_id: str = ""
|
||||
strava_client_secret: str = ""
|
||||
public_url: str = "" # e.g. "https://yourdomain.com" — used for OAuth redirect URIs
|
||||
_db = None # sqlite3.Connection, opened lazily
|
||||
|
||||
|
||||
@@ -674,7 +675,10 @@ async def strava_auth_url(request: Request, bincio_session: Optional[str] = Cook
|
||||
raise HTTPException(400, "Strava client ID not configured on this server")
|
||||
state = secrets.token_urlsafe(16)
|
||||
_strava_oauth_states.add(state)
|
||||
redirect_uri = str(request.url_for("strava_callback"))
|
||||
if public_url:
|
||||
redirect_uri = public_url.rstrip("/") + "/api/strava/callback"
|
||||
else:
|
||||
redirect_uri = str(request.url_for("strava_callback"))
|
||||
from bincio.extract.strava_api import auth_url
|
||||
return JSONResponse({"url": auth_url(strava_client_id, redirect_uri, state=state)})
|
||||
|
||||
@@ -687,7 +691,7 @@ async def strava_callback(
|
||||
state: str = "",
|
||||
bincio_session: Optional[str] = Cookie(default=None),
|
||||
) -> RedirectResponse:
|
||||
site_origin = str(request.base_url).rstrip("/")
|
||||
site_origin = public_url.rstrip("/") if public_url else str(request.base_url).rstrip("/")
|
||||
if error or not code:
|
||||
return RedirectResponse(f"{site_origin}/?strava=error")
|
||||
if state not in _strava_oauth_states:
|
||||
|
||||
Reference in New Issue
Block a user