authclient: auto-detect https for a bare AUTHGUARD_URL host, extend Java client to full surface

AUTHGUARD_URL only needs to name a host/IP now - all four language
clients (Go/Node/Python/Java) assume https:// when no scheme is given,
so a bare value like 192.168.1.50:8080 works instead of failing
outright; an explicit http://scheme is still left alone for local/LAN
deployments.

Java's AuthClient was validate-only; it now mirrors the Go/Node/Python
clients' full surface (register/login/logout/me/totp*/passwordReset*/
managedUsers*/setupStatus) using Jackson for the request/response JSON
this larger surface has to build and parse, since MegaBasterd (this
package's only verified consumer) already depends on Jackson.
This commit is contained in:
Gabriel20xx committed 2026-09-02 20:49:29 +02:00
1 parent f164e0d0d2
commit de9b599232
9 files changed
+697 -44

No files matched your search

@@ -61,6 +61,15 @@ DEFAULT_TIMEOUT = 5.0
_BEARER_PREFIX = "Bearer "
def _normalize_base_url(base_url: str) -> str:
trimmed = str(base_url or "").strip().rstrip("/")
if not trimmed:
return trimmed
if trimmed.lower().startswith(("http://", "https://")):
return trimmed
return f"https://{trimmed}"
class InvalidSessionError(Exception):
"""Raised by validate() / resolve_user() when AuthGuard reports the
token/cookie as not currently valid (expired, unknown, or missing)."""
@@ -170,11 +179,15 @@ class AuthClient:
timeout: float = DEFAULT_TIMEOUT,
) -> None:
"""base_url is AuthGuard's base URL, e.g. "https://auth.example.com"
(no trailing slash required). cookie_name is the cookie
(no trailing slash required). May be given without a scheme (e.g.
"auth.example.com" or "192.168.1.50:8080") -- "https://" is assumed
in that case, so a deployment only needs to name the host, not repeat
the scheme; an explicit "http://" (for a plain-HTTP local/LAN
AuthGuard) is left as-is. cookie_name is the cookie
token_from_request looks for when there is no Authorization header;
it must match AuthGuard's SessionCookieName. timeout is the request
timeout in seconds for the underlying blocking HTTP call."""
self.base_url = str(base_url or "").strip().rstrip("/")
self.base_url = _normalize_base_url(base_url)
self.cookie_name = cookie_name
self.timeout = timeout