add groups from env

This commit is contained in:
2023-05-25 20:50:35 -05:00
parent 3f7c7c98ed
commit eab2cb9963

11
main.go
View File

@@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"os"
"strings" "strings"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@@ -65,12 +66,20 @@ func main() {
} }
func authMiddleware(allowedGroups []string) gin.HandlerFunc { func authMiddleware(allowedGroups []string) gin.HandlerFunc {
return func(c *gin.Context) { 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 // Get the user groups from the request headers
groupsHeader := c.GetHeader("X-authentik-groups") groupsHeader := c.GetHeader("X-authentik-groups")
// Split the groups header value into individual groups // Split the groups header value into individual groups
groups := strings.Split(groupsHeader, "|") groups = strings.Split(groupsHeader, "|")
}
// Check if the user belongs to any of the allowed groups // Check if the user belongs to any of the allowed groups
isAllowed := false isAllowed := false