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

+18 -2
View File
@@ -75,10 +75,14 @@ func WithCookieName(name string) Option {
return func(c *Client) { c.cookieName = name }
}
// New creates a Client for the AuthServer instance at baseURL.
// New creates a Client for the AuthServer instance at baseURL. baseURL 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 AuthServer) is left as-is.
func New(baseURL string, opts ...Option) *Client {
c := &Client{
baseURL: strings.TrimRight(strings.TrimSpace(baseURL), "/"),
baseURL: normalizeBaseURL(baseURL),
httpClient: &http.Client{Timeout: 5 * time.Second},
cookieName: DefaultCookieName,
}
@@ -88,6 +92,18 @@ func New(baseURL string, opts ...Option) *Client {
return c
}
func normalizeBaseURL(baseURL string) string {
trimmed := strings.TrimRight(strings.TrimSpace(baseURL), "/")
if trimmed == "" {
return trimmed
}
lower := strings.ToLower(trimmed)
if strings.HasPrefix(lower, "http://") || strings.HasPrefix(lower, "https://") {
return trimmed
}
return "https://" + trimmed
}
// Validate calls AuthServer's GET /api/session/validate with token as a
// Bearer credential and returns the resolved user. It returns
// ErrInvalidSession (wrapped) when AuthServer reports the session as not