From eab2cb996365e8c2d7842834e16da004a8f4deed Mon Sep 17 00:00:00 2001 From: DeveloperDurp Date: Thu, 25 May 2023 20:50:35 -0500 Subject: [PATCH] add groups from env --- main.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index d24c297..e3be2eb 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "net/http" + "os" "strings" "github.com/gin-gonic/gin" @@ -65,12 +66,20 @@ func main() { } func authMiddleware(allowedGroups []string) gin.HandlerFunc { - return func(c *gin.Context) { - // Get the user groups from the request headers - groupsHeader := c.GetHeader("X-authentik-groups") - // Split the groups header value into individual groups - groups := strings.Split(groupsHeader, "|") + return func(c *gin.Context) { + + var groups []string + groupsenv := os.Getenv("groups") + if groupsenv != "" { + groups = strings.Split(groupsenv, ",") + } else { + // Get the user groups from the request headers + groupsHeader := c.GetHeader("X-authentik-groups") + + // Split the groups header value into individual groups + groups = strings.Split(groupsHeader, "|") + } // Check if the user belongs to any of the allowed groups isAllowed := false