Skip to content

Commit 6eae034

Browse files
committed
Add custom Google authentication handler with landing page
1 parent 882f5d8 commit 6eae034

File tree

5 files changed

+32
-44
lines changed

5 files changed

+32
-44
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ CMD ["panel", "serve", "panel/app.py", \
6969
"--allow-websocket-origin", "www.simdec.io", \
7070
"--allow-websocket-origin", "simdec-panel-h6musew72q-lz.a.run.app", \
7171
"--cookie-secret", "panel_cookie_secret_oauth", \
72+
"--basic-login-template", "panel/login.html", \
7273
"--logout-template", "panel/logout.html", \
73-
"--oauth-provider", "google", \
74+
"--oauth-provider", "custom_google", \
7475
"--static-dirs", "_static=_static", \
7576
"--reuse-sessions", "--warm", \
7677
"--global-loading-spinner"]

Makefile

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,13 @@ serve-dev: ## Serve Panel dashboard - Dev mode
4343
--static-dirs _static=docs/_static \
4444
--reuse-sessions --warm
4545

46-
serve: ## Serve Panel dashboard - Prod mode with basic auth. Needs: PANEL_TOKEN
47-
panel serve panel/app.py \
48-
--show \
49-
--cookie-secret panel_cookie_secret_oauth \
50-
--basic-login-template panel/login.html \
51-
--logout-template panel/logout.html \
52-
--static-dirs _static=docs/_static \
53-
--reuse-sessions --warm
54-
5546
serve-oauth: ## Serve Panel dashboard - Prod mode with OAuth2. Needs: PANEL_OAUTH_REDIRECT_URI, PANEL_OAUTH_KEY, PANEL_OAUTH_SECRET, PANEL_OAUTH_ENCRYPTION
5647
PANEL_OAUTH_SCOPE=email panel serve panel/app.py \
5748
--show \
5849
--cookie-secret panel_cookie_secret_oauth \
5950
--basic-login-template panel/login.html \
6051
--logout-template panel/logout.html \
61-
--oauth-provider google \
52+
--oauth-provider custom_google \
6253
--static-dirs _static=docs/_static \
6354
--reuse-sessions --warm
6455

panel/login.html

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta charset="utf-8">
66
<meta content="width=device-width, initial-scale=1.0" name="viewport">
77
<meta content="en" name="docsearch:language">
8-
<title>Panel App | Login</title>
8+
<title>SimDec App | Login</title>
99
<link rel="icon" type="image/x-icon" href="_static/icon.png">
1010
<style>
1111
* {
@@ -40,64 +40,40 @@
4040
padding: 2em;
4141
width: 350px;
4242
}
43-
.form-input {
44-
background: #fafafa;
45-
border: 1px solid #eeeeee;
46-
padding: 12px;
47-
width: 100%;
48-
}
49-
.form-group {
43+
.group {
5044
margin-bottom: 1em;
5145
}
52-
.form-button {
46+
.button {
5347
background: #107bba;
5448
border: 1px solid #ddd;
5549
color: #ffffff;
5650
padding: 10px;
5751
text-transform: uppercase;
5852
width: 100%;
5953
}
60-
.form-button:hover {
54+
.button:hover {
6155
background: #0072b5;
6256
}
63-
.form-header {
64-
text-align: center;
65-
}
66-
.form-footer {
57+
.header {
6758
text-align: center;
6859
}
6960
#logo {
7061
margin-top: 2em;
7162
}
72-
#error-message {
73-
text-align: center;
74-
margin-bottom: 0em;
75-
}
7663
</style>
7764
</head>
7865
<body>
7966
<div class="wrap">
8067
<form class="login-form" action="./login" method="post">
81-
<div class="form-header">
68+
<div class="header">
8269
<h3><img id="logo" src="_static/logo.gif" width="150" height="150"></h3>
8370
<br>
84-
<p> Login to access your application</p>
85-
</div>
86-
<div id="error-message" class="form-group">
87-
<p style="color:rgb(255, 0, 0);font-weight:bold" class="errormessage">{{errormessage}}</p>
71+
<p> Login to access SimDec App.</p>
8872
</div>
8973
<p></p>
90-
<!--Email Input-->
91-
<div class="form-group">
92-
<input name="username" type="text" class="form-input" autocapitalize="off" autocorrect="off" placeholder="username">
93-
</div>
94-
<!--Password Input-->
95-
<div class="form-group">
96-
<input name="password" type="password" class="form-input" placeholder="password">
97-
</div>
9874
<!--Login Button-->
99-
<div class="form-group">
100-
<button class="form-button" type="submit">Login</button>
75+
<div class="group">
76+
<button class="button" type="submit">Login</button>
10177
</div>
10278
<div><small></small></div>
10379
</form>

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ build.targets.sdist.exclude = [
7777
"Dockerfile",
7878
]
7979

80+
[project.entry-points."panel.auth"]
81+
custom_google = "simdec.auth:CustomGoogleLoginHandler"
82+
8083
[tool.pytest.ini_options]
8184
addopts = "--durations 10"
8285
testpaths = [

src/simdec/auth.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from panel.auth import GoogleLoginHandler
2+
from panel.io.resources import CDN_DIST
3+
4+
5+
class CustomGoogleLoginHandler(GoogleLoginHandler):
6+
def _simple_get(self):
7+
html = self._login_template.render(errormessage="", PANEL_CDN=CDN_DIST)
8+
self.write(html)
9+
10+
async def get(self):
11+
if "login" in self.request.uri and "state" not in self.request.uri:
12+
self._simple_get()
13+
else:
14+
await super().get()
15+
16+
async def post(self):
17+
await super().get()

0 commit comments

Comments
 (0)