update
This commit is contained in:
36
main.go
36
main.go
@@ -85,16 +85,6 @@ func authMiddleware(allowedGroups []string) gin.HandlerFunc {
|
||||
tokenString := c.GetHeader("Authorization")
|
||||
if tokenString != "" {
|
||||
tokenString = strings.TrimPrefix(tokenString, "Bearer ")
|
||||
} else {
|
||||
tokenString = c.GetHeader("X-authentik-jwt")
|
||||
}
|
||||
|
||||
if tokenString == "" {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "No Token in header",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
@@ -162,6 +152,32 @@ func authMiddleware(allowedGroups []string) gin.HandlerFunc {
|
||||
groups = append(groups, groupName)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
groupsHeader := c.GetHeader("X-Authentik-Groups")
|
||||
|
||||
if groupsHeader == "" {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "No token or groups detected",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
requestHeaders := c.Request.Header
|
||||
for key, values := range requestHeaders {
|
||||
for _, value := range values {
|
||||
println(key + ": " + value)
|
||||
}
|
||||
}
|
||||
|
||||
// Dump response headers
|
||||
responseHeaders := c.Writer.Header()
|
||||
for key, values := range responseHeaders {
|
||||
for _, value := range values {
|
||||
println(key + ": " + value)
|
||||
}
|
||||
}
|
||||
groups = strings.Split(groupsHeader, "|")
|
||||
}
|
||||
|
||||
isAllowed := false
|
||||
for _, allowedGroup := range allowedGroups {
|
||||
|
||||
Reference in New Issue
Block a user