Skip to content

Feature/reverse proxy web auth - #997

Open
Meganitrospeed wants to merge 26 commits into
patzly:masterfrom
Meganitrospeed:feature/reverse-proxy-web-auth
Open

Feature/reverse proxy web auth#997
Meganitrospeed wants to merge 26 commits into
patzly:masterfrom
Meganitrospeed:feature/reverse-proxy-web-auth

Conversation

@Meganitrospeed

Copy link
Copy Markdown

Summary

This PR adds support for Grocy instances protected by an interactive reverse proxy, such as Authentik.

Currently, when Grocy Android checks /api/system/info, the reverse proxy can return its HTML login page instead of the expected Grocy JSON response. The app then displays “Target is not a Grocy instance.”

My Grocy installation uses the following configuration:

- GROCY_AUTH_CLASS=Grocy\Middleware\ReverseProxyAuthMiddleware
- GROCY_REVERSE_PROXY_AUTH_HEADER=X-Authentik-Username
- GROCY_REVERSE_PROXY_AUTH_USE_ENV=false

Changes

  • Detects when the initial API response appears to be an interactive authentication page.
  • Opens the configured server in an embedded WebView so the user can complete authentication.
  • Makes the resulting session cookies available to Volley/HttpURLConnection.
  • Includes the session cookies in authenticated Glide requests.
  • Retries onboarding after authentication succeeds.
  • Detects authentication pages returned after a proxy session expires and opens the login flow again.
  • Continues using the existing GROCY-API-KEY header for Grocy API authentication.

This does not implement OAuth/OIDC directly. The WebView establishes the reverse proxy’s existing browser session, after which the app continues using the normal Grocy API.

Security considerations

  • The app does not create or send X-Authentik-Username; the trusted reverse proxy remains responsible for injecting that header.
  • Authentication responses are only handled for the configured Grocy origin.
  • Scheme, hostname and effective port are checked before triggering reauthentication.
  • File access, content access and mixed-content loading are disabled in the WebView.
  • The Grocy API key is still sent as before.

Automated tests

Unit tests were added for:

  • HTML and Authentik login-page detection.
  • Avoiding false detection for valid Grocy JSON.
  • Same-origin matching.
  • Scheme, hostname and port mismatches.
  • Authentik outpost and authentication-flow paths.

Testing performed

I tested the implementation with an Authentik-protected Grocy installation using the reverse-proxy middleware configuration shown above.

Additional testing of other identity providers and reverse-proxy configurations would be appreciated.

@Meganitrospeed

Meganitrospeed commented Aug 23, 2026

Copy link
Copy Markdown
Author

Would Fix #829
@patzly if you want an instance to test against I can gladly offer mine

@patzly

patzly commented Aug 23, 2026

Copy link
Copy Markdown
Owner

Thank you very much for your contribution! I think if this works for you I will simply merge it and other users can then request improvements if required.

@Meganitrospeed

Copy link
Copy Markdown
Author
Screenshot_2026-08-23-23-45-02-220_xyz zedler patrick grocy debug H IMG_20260823_234746 I just fixed 3 Edge cases GPT found, nothing too serious, but from the testing I've done I havent seen any issues so far, if a request suddenly presents a proxy/Authentik http It opens the WebView in the pic and asks to be reauthed before continuing the request through the API, tested without issues on the initial onboarding, when consuming, etc on Authentik 2026.5.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants