Tags, error blocks, and the two ways to build your own login page
Was this useful?
0 unique visitors
Two mechanisms are easy to confuse here: a small set of tags available on almost any HTML page, and the OIDC-specific login page. Both let you own the look of your login entirely. This post covers them side by side.
Four tags
{{ username }}
{{ csrf_token }}
{{ proxyauth_version }}
{{ proxyauth_id }}
| Tag | Filled with | When unavailable |
|---|---|---|
{{ username }} | the signed-in visitor, checked even on a route without required_login | left as literal text |
{{ csrf_token }} | a fresh signed CSRF token, the one /auth checks | left untouched — never filled with a token nobody will verify |
{{ proxyauth_version }} | the running build’s version | always resolves |
{{ proxyauth_id }} | the running build’s instance ID | always resolves |
Spaced and unspaced forms ({{username}}) both work.
A tag with nothing to fill stays literal on purpose. A blank space where a name should be looks like a rendering bug; the literal tag says what is true: nothing available.
{{ csrf_token }} additionally requires CSRF to resolve to enabled for
the vhost (csrf_token globally, tag_csrf_token per vhost).
Turning them on
routes:
- prefix: "/"
target: "http://127.0.0.1:3000"
tag_proxyauth: true
cache: false
tag_proxyauth is off by default and, unlike most settings, is not
inherited-then-enabled anywhere. Substitution reads the whole body as
text on every matching request, so it is enabled per route, only where
it is used. Only text/html responses are scanned.
It works on static files and proxied responses alike: a backend can
write {{ username }} into its own HTML and ProxyAuth fills it on the
way out.
Two consequences:
- Pair it with
cache: false. The output is per visitor.cache: falsesendsno-store, no-cache, must-revalidate, max-age=0andPragma: no-cache, so nobody receives someone else’s render or CSRF token. - It forces buffering. A route with
tag_proxyauthbuffers even withstreaming: true, and a startup warning names it.
Path one: a static login page posting to /auth
This is the normal way to own the login screen on a non-OIDC vhost. The page is a file you write; ProxyAuth serves it and fills the tags.
vhosts:
- vhost: ["app.example.com"]
session_cookie: true
login_redirect_url: "/app"
logout_redirect_url: "/"
routes:
- prefix: "/"
static: "/var/www/app/public/"
static_index: "login.html"
tag_proxyauth: true
cache: false
- prefix: "/app"
target: "http://127.0.0.1:8000"
required_login: true
<!DOCTYPE html>
<html>
<body>
<p class="hello">{{ username }}</p>
<!-- BEGIN_BLOCK_ERROR -->
<!--
<div id="error_display" class="error">{{ error }}</div>
-->
<!-- END_BLOCK_ERROR -->
<form method="POST" action="/auth">
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
<input type="text" name="username" autocomplete="username">
<input type="password" name="password" autocomplete="current-password">
<button type="submit">Sign in</button>
</form>
<footer>ProxyAuth v{{ proxyauth_version }}</footer>
</body>
</html>
For a first-time visitor, {{ username }} stays literal (style it
hidden, or leave it out), the CSRF field is filled so the form works,
and the version always resolves. Forget tag_proxyauth: true and the
form still renders — but every submission fails CSRF, because the field
contains the literal tag.
Everything around it is yours: CSS, scripts, images served from the same static directory.
The error block
On a login failure, ProxyAuth looks for this block in the page and reveals it:
<!-- BEGIN_BLOCK_ERROR -->
<!--
<div id="error_display">{{ error }}</div>
-->
<!-- END_BLOCK_ERROR -->
It strips the inner comment markers and substitutes {{ error }}. With
no error, the block stays commented out and renders as nothing — no
empty container, no CSS to hide it. The page’s markup decides what an
error looks like.
This applies when session_cookie is on. The page that gets annotated
is resolved through logout_redirect_url, vhost-aware — which matters
on a multi-vhost instance where several vhosts have their own page at
the same path. Set logout_redirect_url on each vhost that has a login
page.
Path two: the OIDC login_page
On a vhost with oidc:, /auth proxies to the backend and the login
step happens at /oidc/authorize. There, login_page replaces the
built-in form:
oidc:
client_id: "grafana"
# ...
login_page: "/etc/proxyauth/pages/login.html"
with three extra tags:
{{ form }}— a complete working form: submit target, CSRF field if enabled, username, password, TOTP if required, button.{{ auth_action }}— just the submit target, for a hand-built form.{{ form_totp }}— just the TOTP input, or an empty string if TOTP is off.
<form method="POST" action="{{ auth_action }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
<input type="text" name="username">
<input type="password" name="password">
<button type="button" onclick="showTotp()">Next</button>
<div id="totp-step" hidden>
{{ form_totp }}
<button type="submit">Sign in</button>
</div>
</form>
<script>
function showTotp() { document.getElementById('totp-step').hidden = false; }
</script>
The two-step look is presentation only: server-side, username, password
and TOTP are still verified together in one POST. If login_page
cannot be read, the built-in form is used and the error logged.
Which path to use
| You want | Use |
|---|---|
| a branded login in front of an app with no auth of its own | static page + tag_proxyauth + /auth |
| a login for an app that speaks OIDC and manages its own users | oidc.login_page |
| to greet a logged-in user inside your backend’s pages | tag_proxyauth on the proxied route |
| to hide one element for some users | hidden_blocks (also needs tag_proxyauth) |
Four tags on any HTML route that opts in, an error block that only
speaks when there is something to say, and two real ways to own the
login screen — a static page posting to /auth, or an OIDC login_page.
Remember cache: false wherever a page is rendered per visitor.