mirror of
				https://github.com/steveiliop56/tinyauth.git
				synced 2025-11-04 08:05:42 +00:00 
			
		
		
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			v3.6.2-bet
			...
			feat/app-b
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					1bcae613ca | 
@@ -119,8 +119,12 @@ func (h *Handlers) AuthHandler(c *gin.Context) {
 | 
			
		||||
	if !authEnabled {
 | 
			
		||||
		headersParsed := utils.ParseHeaders(labels.Headers)
 | 
			
		||||
		for key, value := range headersParsed {
 | 
			
		||||
			log.Debug().Str("key", key).Str("value", value).Msg("Setting header")
 | 
			
		||||
			c.Header(key, utils.SanitizeHeader(value))
 | 
			
		||||
			log.Debug().Str("key", key).Msg("Setting header")
 | 
			
		||||
			c.Header(key, value)
 | 
			
		||||
		}
 | 
			
		||||
		if labels.Basic.User != "" && labels.Basic.Password != "" {
 | 
			
		||||
			log.Debug().Str("username", labels.Basic.User).Msg("Setting basic auth headers")
 | 
			
		||||
			c.Header("Authorization", fmt.Sprintf("Basic %s", utils.GetBasicAuth(labels.Basic.User, labels.Basic.Password)))
 | 
			
		||||
		}
 | 
			
		||||
		c.JSON(200, gin.H{
 | 
			
		||||
			"status":  200,
 | 
			
		||||
@@ -242,8 +246,14 @@ func (h *Handlers) AuthHandler(c *gin.Context) {
 | 
			
		||||
		// Set the rest of the headers
 | 
			
		||||
		parsedHeaders := utils.ParseHeaders(labels.Headers)
 | 
			
		||||
		for key, value := range parsedHeaders {
 | 
			
		||||
			log.Debug().Str("key", key).Str("value", value).Msg("Setting header")
 | 
			
		||||
			c.Header(key, utils.SanitizeHeader(value))
 | 
			
		||||
			log.Debug().Str("key", key).Msg("Setting header")
 | 
			
		||||
			c.Header(key, value)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Set basic auth headers if configured
 | 
			
		||||
		if labels.Basic.User != "" && labels.Basic.Password != "" {
 | 
			
		||||
			log.Debug().Str("username", labels.Basic.User).Msg("Setting basic auth headers")
 | 
			
		||||
			c.Header("Authorization", fmt.Sprintf("Basic %s", utils.GetBasicAuth(labels.Basic.User, labels.Basic.Password)))
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// The user is allowed to access the app
 | 
			
		||||
 
 | 
			
		||||
@@ -99,11 +99,18 @@ type OAuthLabels struct {
 | 
			
		||||
	Groups    string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Basic auth labels for a tinyauth protected container
 | 
			
		||||
type BasicLabels struct {
 | 
			
		||||
	User     string
 | 
			
		||||
	Password string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Labels is a struct that contains the labels for a tinyauth protected container
 | 
			
		||||
type Labels struct {
 | 
			
		||||
	Users   string
 | 
			
		||||
	Allowed string
 | 
			
		||||
	Headers []string
 | 
			
		||||
	Domain  string
 | 
			
		||||
	Basic   BasicLabels
 | 
			
		||||
	OAuth   OAuthLabels
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
package utils
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/base64"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"net/url"
 | 
			
		||||
	"os"
 | 
			
		||||
@@ -201,7 +202,7 @@ func GetLabels(labels map[string]string) (types.Labels, error) {
 | 
			
		||||
	var labelsParsed types.Labels
 | 
			
		||||
 | 
			
		||||
	// Decode the labels into the labels struct
 | 
			
		||||
	err := parser.Decode(labels, &labelsParsed, "tinyauth", "tinyauth.users", "tinyauth.allowed", "tinyauth.headers", "tinyauth.domain", "tinyauth.oauth")
 | 
			
		||||
	err := parser.Decode(labels, &labelsParsed, "tinyauth", "tinyauth.users", "tinyauth.allowed", "tinyauth.headers", "tinyauth.domain", "tinyauth.basic", "tinyauth.oauth")
 | 
			
		||||
 | 
			
		||||
	// Check if there was an error
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -358,3 +359,12 @@ func GenerateIdentifier(str string) string {
 | 
			
		||||
	// Convert the UUID to a string
 | 
			
		||||
	return strings.Split(uuidString, "-")[0]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Get a basic auth header from a username and password
 | 
			
		||||
func GetBasicAuth(username string, password string) string {
 | 
			
		||||
	// Create the auth string
 | 
			
		||||
	auth := username + ":" + password
 | 
			
		||||
 | 
			
		||||
	// Encode the auth string to base64
 | 
			
		||||
	return base64.StdEncoding.EncodeToString([]byte(auth))
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user