Abhishek Thakur commited on
Commit
3b4df92
·
1 Parent(s): 4046997

fix redirect uri

Browse files
Files changed (1) hide show
  1. competitions/oauth.py +5 -6
competitions/oauth.py CHANGED
@@ -32,12 +32,7 @@ def attach_oauth(app: fastapi.FastAPI):
32
  session_secret = (OAUTH_CLIENT_SECRET or "") + "-v4"
33
  # ^ if we change the session cookie format in the future, we can bump the version of the session secret to make
34
  # sure cookies are invalidated. Otherwise some users with an old cookie format might get a HTTP 500 error.
35
- app.add_middleware(
36
- SessionMiddleware,
37
- secret_key=hashlib.sha256(session_secret.encode()).hexdigest(),
38
- same_site="none",
39
- https_only=True,
40
- )
41
 
42
 
43
  def _add_oauth_routes(app: fastapi.FastAPI) -> None:
@@ -73,6 +68,10 @@ def _add_oauth_routes(app: fastapi.FastAPI) -> None:
73
  # Define target (where to redirect after login)
74
  # redirect_uri = _generate_redirect_uri(request)
75
  redirect_uri = request.url_for("auth")
 
 
 
 
76
  return await oauth.huggingface.authorize_redirect(request, redirect_uri) # type: ignore
77
 
78
  @app.get("/auth")
 
32
  session_secret = (OAUTH_CLIENT_SECRET or "") + "-v4"
33
  # ^ if we change the session cookie format in the future, we can bump the version of the session secret to make
34
  # sure cookies are invalidated. Otherwise some users with an old cookie format might get a HTTP 500 error.
35
+ app.add_middleware(SessionMiddleware, secret_key=hashlib.sha256(session_secret.encode()).hexdigest())
 
 
 
 
 
36
 
37
 
38
  def _add_oauth_routes(app: fastapi.FastAPI) -> None:
 
68
  # Define target (where to redirect after login)
69
  # redirect_uri = _generate_redirect_uri(request)
70
  redirect_uri = request.url_for("auth")
71
+ redirect_uri_as_str = str(redirect_uri)
72
+ if redirect_uri.netloc.endswith(".hf.space"):
73
+ # In Space, FastAPI redirect as http but we want https
74
+ redirect_uri_as_str = redirect_uri_as_str.replace("http://", "https://")
75
  return await oauth.huggingface.authorize_redirect(request, redirect_uri) # type: ignore
76
 
77
  @app.get("/auth")