package httpapi import ( "net/http" "github.com/mitbringsl/backend/internal/config" ) // ConfigHandler exposes the public server configuration that the Android app // needs before logging in (e.g. which auth methods are available). type ConfigHandler struct { cfg *config.Config } // NewConfigHandler creates a ConfigHandler. func NewConfigHandler(cfg *config.Config) *ConfigHandler { return &ConfigHandler{cfg: cfg} } // serverConfigResponse is the public config payload returned to the app. type serverConfigResponse struct { Auth authConfig `json:"auth"` } // authConfig describes which login methods the server offers. type authConfig struct { PasswordEnabled bool `json:"password_enabled"` OIDC oidcProvidersDTO `json:"oidc"` } type oidcProvidersDTO struct { Google oidcProviderDTO `json:"google"` Generic oidcProviderDTO `json:"generic"` } type oidcProviderDTO struct { Enabled bool `json:"enabled"` Issuer string `json:"issuer,omitempty"` DisplayName string `json:"display_name,omitempty"` } // Config returns the public server configuration. // GET /api/config (public, no auth required) func (h *ConfigHandler) Config(w http.ResponseWriter, r *http.Request) { renderJSON(w, http.StatusOK, serverConfigResponse{ Auth: authConfig{ PasswordEnabled: h.cfg.AuthPasswordEnabled, OIDC: oidcProvidersDTO{ Google: oidcProviderDTO{ Enabled: h.cfg.GoogleOIDC.Enabled, Issuer: h.cfg.GoogleOIDC.Issuer, DisplayName: "Google", }, Generic: oidcProviderDTO{ Enabled: h.cfg.GenericOIDC.Enabled, Issuer: h.cfg.GenericOIDC.Issuer, DisplayName: h.cfg.GenericOIDC.DisplayName, }, }, }, }) }