add groups from env
This commit is contained in:
11
main.go
11
main.go
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user