This commit is contained in:
parent
043eaff5fd
commit
82a506278b
@ -1,15 +1,27 @@
|
||||
"""Community Keycloak SSO user management."""
|
||||
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.responses import HTMLResponse, RedirectResponse
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from starlette.middleware.sessions import SessionMiddleware
|
||||
|
||||
app = FastAPI()
|
||||
app.add_middleware(SessionMiddleware, secret_key="mysecretzkey")
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
|
||||
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
async def home(request: Request):
|
||||
user = request.session.get("user")
|
||||
if user:
|
||||
return templates.TemplateResponse(
|
||||
"index.html", context={"request": request}
|
||||
)
|
||||
return RedirectResponse("/login")
|
||||
|
||||
|
||||
@app.get("/login", response_class=HTMLResponse)
|
||||
async def login(request: Request):
|
||||
return templates.TemplateResponse(
|
||||
"index.html", context={"request": request}
|
||||
"login.html", context={"request": request}
|
||||
)
|
||||
|
14
poetry.lock
generated
14
poetry.lock
generated
@ -121,6 +121,14 @@ pipfile_deprecated_finder = ["pipreqs", "requirementslib"]
|
||||
requirements_deprecated_finder = ["pipreqs", "pip-api"]
|
||||
colors = ["colorama (>=0.4.3,<0.5.0)"]
|
||||
|
||||
[[package]]
|
||||
name = "itsdangerous"
|
||||
version = "2.0.1"
|
||||
description = "Safely pass data to untrusted environments and back."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
|
||||
[[package]]
|
||||
name = "jinja2"
|
||||
version = "3.0.1"
|
||||
@ -324,7 +332,7 @@ python-versions = ">=3.6.1"
|
||||
[metadata]
|
||||
lock-version = "1.1"
|
||||
python-versions = "^3.9"
|
||||
content-hash = "27448995033f96e0639ead7c435ba26b4758706f9e26ecb5ade3d29692959668"
|
||||
content-hash = "a3278c69c36a0390a247780ff0ad55c878d2e1ea028097bd46d8998d1c449ce1"
|
||||
|
||||
[metadata.files]
|
||||
appdirs = [
|
||||
@ -380,6 +388,10 @@ isort = [
|
||||
{file = "isort-5.8.0-py3-none-any.whl", hash = "sha256:2bb1680aad211e3c9944dbce1d4ba09a989f04e238296c87fe2139faa26d655d"},
|
||||
{file = "isort-5.8.0.tar.gz", hash = "sha256:0a943902919f65c5684ac4e0154b1ad4fac6dcaa5d9f3426b732f1c8b5419be6"},
|
||||
]
|
||||
itsdangerous = [
|
||||
{file = "itsdangerous-2.0.1-py3-none-any.whl", hash = "sha256:5174094b9637652bdb841a3029700391451bd092ba3db90600dea710ba28e97c"},
|
||||
{file = "itsdangerous-2.0.1.tar.gz", hash = "sha256:9e724d68fc22902a1435351f84c3fb8623f303fffcc566a4cb952df8c572cff0"},
|
||||
]
|
||||
jinja2 = [
|
||||
{file = "Jinja2-3.0.1-py3-none-any.whl", hash = "sha256:1f06f2da51e7b56b8f238affdd6b4e2c61e39598a378cc49345bc1bd42a978a4"},
|
||||
{file = "Jinja2-3.0.1.tar.gz", hash = "sha256:703f484b47a6af502e743c9122595cc812b0271f661722403114f71a79d0f5a4"},
|
||||
|
@ -10,6 +10,7 @@ python = "^3.9"
|
||||
fastapi = "^0.65.2"
|
||||
uvicorn = {extras = ["standard"], version = "^0.14.0"}
|
||||
Jinja2 = "^3.0.1"
|
||||
itsdangerous = "^2.0.1"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
black = "^21.6b0"
|
||||
|
8
templates/login.html
Normal file
8
templates/login.html
Normal file
@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Login</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Please login</p>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user