Compare commits

..

16 Commits

Author SHA1 Message Date
Stavros
0a7e259d02 fix: review comments 2025-12-22 22:11:17 +02:00
Stavros
7c5fa117fb chore: go mod tidy 2025-12-22 22:08:39 +02:00
Stavros
d8b8be0100 Merge branch 'main' of https://github.com/steveiliop56/tinyauth into feat/unified-config 2025-12-22 22:08:24 +02:00
Stavros
db4ed949e1 chore: resolve go mod and sum conflicts 2025-12-22 22:03:40 +02:00
Stavros
5cfe2babc4 chore: add quotes to all env variables 2025-12-22 22:01:09 +02:00
Stavros
ed28e7a218 refactor: move tinyauth to separate package 2025-12-21 17:37:34 +02:00
Stavros
7db81121e1 fix: review comments 2025-12-21 17:25:04 +02:00
Stavros
195b70b4d7 chore: mod tidy 2025-12-21 11:23:00 +02:00
Stavros
c4529be557 feat: add experimental config file support 2025-12-21 11:21:11 +02:00
Stavros
0374370b0c fix: fix translations not loading 2025-12-17 23:36:01 +02:00
Stavros
7857dba57a chore: remove unused code 2025-12-17 23:31:24 +02:00
Stavros
3e12721844 refactor: update build 2025-12-17 23:21:15 +02:00
Stavros
9c7a4af295 chore: update example env 2025-12-17 19:42:26 +02:00
Stavros
dba5580a7c refactor: remove dependency on traefik 2025-12-17 18:30:43 +02:00
Stavros
e4e99f4805 feat: add initial implementation of a traefik like cli 2025-12-17 16:40:54 +02:00
Stavros
3555569a97 chore: add yaml config ref 2025-12-17 15:17:55 +02:00
2 changed files with 2 additions and 33 deletions

View File

@@ -3,7 +3,6 @@ package controller
import (
"fmt"
"net/http"
"slices"
"strings"
"tinyauth/internal/config"
"tinyauth/internal/service"
@@ -14,8 +13,6 @@ import (
"github.com/rs/zerolog/log"
)
var SupportedProxies = []string{"nginx", "traefik", "caddy", "envoy"}
type Proxy struct {
Proxy string `uri:"proxy" binding:"required"`
}
@@ -42,7 +39,7 @@ func NewProxyController(config ProxyControllerConfig, router *gin.RouterGroup, a
func (controller *ProxyController) SetupRoutes() {
proxyGroup := controller.router.Group("/auth")
proxyGroup.Any("/:proxy", controller.proxyHandler)
proxyGroup.GET("/:proxy", controller.proxyHandler)
}
func (controller *ProxyController) proxyHandler(c *gin.Context) {
@@ -58,7 +55,7 @@ func (controller *ProxyController) proxyHandler(c *gin.Context) {
return
}
if !slices.Contains(SupportedProxies, req.Proxy) {
if req.Proxy != "nginx" && req.Proxy != "traefik" && req.Proxy != "caddy" {
log.Warn().Str("proxy", req.Proxy).Msg("Invalid proxy")
c.JSON(400, gin.H{
"status": 400,
@@ -67,15 +64,6 @@ func (controller *ProxyController) proxyHandler(c *gin.Context) {
return
}
if req.Proxy != "envoy" && c.Request.Method != http.MethodGet {
log.Warn().Str("method", c.Request.Method).Msg("Invalid method for proxy")
c.JSON(405, gin.H{
"status": 405,
"message": "Method Not Allowed",
})
return
}
isBrowser := strings.Contains(c.Request.Header.Get("Accept"), "text/html")
if isBrowser {

View File

@@ -80,13 +80,6 @@ func TestProxyHandler(t *testing.T) {
assert.Equal(t, 400, recorder.Code)
// Test invalid method
recorder = httptest.NewRecorder()
req = httptest.NewRequest("POST", "/api/auth/traefik", nil)
router.ServeHTTP(recorder, req)
assert.Equal(t, 405, recorder.Code)
// Test logged out user (traefik/caddy)
recorder = httptest.NewRecorder()
req = httptest.NewRequest("GET", "/api/auth/traefik", nil)
@@ -99,18 +92,6 @@ func TestProxyHandler(t *testing.T) {
assert.Equal(t, 307, recorder.Code)
assert.Equal(t, "http://localhost:8080/login?redirect_uri=https%3A%2F%2Fexample.com%2Fsomepath", recorder.Header().Get("Location"))
// Test logged out user (envoy)
recorder = httptest.NewRecorder()
req = httptest.NewRequest("POST", "/api/auth/envoy", nil)
req.Header.Set("X-Forwarded-Proto", "https")
req.Header.Set("X-Forwarded-Host", "example.com")
req.Header.Set("X-Forwarded-Uri", "/somepath")
req.Header.Set("Accept", "text/html")
router.ServeHTTP(recorder, req)
assert.Equal(t, 307, recorder.Code)
assert.Equal(t, "http://localhost:8080/login?redirect_uri=https%3A%2F%2Fexample.com%2Fsomepath", recorder.Header().Get("Location"))
// Test logged out user (nginx)
recorder = httptest.NewRecorder()
req = httptest.NewRequest("GET", "/api/auth/nginx", nil)