Revert "Attempt to rework url_for"
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This reverts commit 3ad0cef90f
.
This commit is contained in:
parent
3ad0cef90f
commit
9d83b7191d
@ -30,13 +30,6 @@ oauth.register(
|
||||
)
|
||||
|
||||
|
||||
def _url_for(request, uri):
|
||||
_uri = request.url_for(uri)
|
||||
if "X-Forwarded-Proto" in request.headers:
|
||||
return _uri.replace("http:", request.headers["X-Forwarded-Proto"] + ":")
|
||||
return _uri
|
||||
|
||||
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
async def home(request: Request):
|
||||
user = request.session.get("user")
|
||||
@ -44,12 +37,12 @@ async def home(request: Request):
|
||||
return templates.TemplateResponse(
|
||||
"index.html", context={"request": request, "user": user}
|
||||
)
|
||||
return RedirectResponse(_url_for(request, "login_keycloak"))
|
||||
return RedirectResponse(request.url_for("login_keycloak"))
|
||||
|
||||
|
||||
@app.get("/login/keycloak")
|
||||
async def login_keycloak(request: Request):
|
||||
redirect_uri = _url_for(request, "auth_keycloak")
|
||||
redirect_uri = request.url_for("auth_keycloak")
|
||||
return await oauth.keycloak.authorize_redirect(request, redirect_uri)
|
||||
|
||||
|
||||
@ -59,7 +52,7 @@ async def auth_keycloak(request: Request):
|
||||
token = await oauth.keycloak.authorize_access_token(request)
|
||||
user = await oauth.keycloak.parse_id_token(request, token)
|
||||
request.session["user"] = dict(user)
|
||||
return RedirectResponse(_url_for(request, "home"))
|
||||
return RedirectResponse(request.url_for("home"))
|
||||
except Exception as exception:
|
||||
return HTMLResponse(f"<h1>{str(exception)}</h1>")
|
||||
|
||||
@ -67,4 +60,4 @@ async def auth_keycloak(request: Request):
|
||||
@app.route("/logout")
|
||||
async def logout(request: Request):
|
||||
request.session.pop("user", None)
|
||||
return RedirectResponse(_url_for(request, "home"))
|
||||
return RedirectResponse(request.url_for("home"))
|
||||
|
Loading…
Reference in New Issue
Block a user