@@ -10,6 +10,8 @@ import (
1010 "tinyauth/internal/types"
1111 "tinyauth/internal/utils"
1212
13+ "encoding/base64"
14+
1315 "github.com/gin-gonic/gin"
1416 "github.com/gorilla/sessions"
1517 "github.com/rs/zerolog/log"
@@ -337,20 +339,33 @@ func (auth *Auth) AuthEnabled(c *gin.Context, labels types.TinyauthLabels) (bool
337339}
338340
339341func (auth * Auth ) GetBasicAuth (c * gin.Context ) * types.User {
340- // Get the Authorization header
341- username , password , ok := c .Request .BasicAuth ()
342+ // Get the X-TinyAuth-Authorization header
343+ authHeader := c .Request .Header .Get ("X-TinyAuth-Authorization" )
344+ if authHeader == "" {
345+ return nil
346+ }
342347
343- // If not ok, return an empty user
344- if ! ok {
348+ // Parse Basic Auth from header
349+ parts := strings .SplitN (authHeader , " " , 2 )
350+ if len (parts ) != 2 || parts [0 ] != "Basic" {
345351 return nil
346352 }
347353
348- fmt .Println ("user" , username )
349- fmt .Println ("passwrod" , password )
354+ // Decode base64
355+ payload , err := base64 .StdEncoding .DecodeString (parts [1 ])
356+ if err != nil {
357+ return nil
358+ }
359+
360+ // Split username and password
361+ pair := strings .SplitN (string (payload ), ":" , 2 )
362+ if len (pair ) != 2 {
363+ return nil
364+ }
350365
351366 // Return the user
352367 return & types.User {
353- Username : username ,
354- Password : password ,
368+ Username : pair [ 0 ] ,
369+ Password : pair [ 1 ] ,
355370 }
356371}
0 commit comments