Skip to content

Commit fcc80ea

Browse files
authored
Merge pull request #2 from maposia/dev
debug Request.BasicAuth
2 parents ff884cc + 7774f0c commit fcc80ea

3 files changed

Lines changed: 26 additions & 112 deletions

File tree

internal/auth/auth.go

Whitespace-only changes.

internal/service/auth_service.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package service
22

33
import (
44
"context"
5+
"encoding/base64"
56
"errors"
67
"fmt"
78
"regexp"
@@ -360,14 +361,34 @@ func (auth *AuthService) IsAuthEnabled(uri string, path config.AppPath) (bool, e
360361
}
361362

362363
func (auth *AuthService) GetBasicAuth(c *gin.Context) *config.User {
363-
username, password, ok := c.Request.BasicAuth()
364-
if !ok {
365-
log.Debug().Msg("No basic auth provided")
364+
365+
for k, v := range c.Request.Header {
366+
log.Info().Msgf("HEADER %s = %v", k, v)
367+
}
368+
369+
authHeader := c.Request.Header.Get("X-Api-Key")
370+
if authHeader == "" {
371+
return nil
372+
}
373+
374+
parts := strings.SplitN(authHeader, " ", 2)
375+
if len(parts) != 2 || parts[0] != "Basic" {
376+
return nil
377+
}
378+
379+
payload, err := base64.StdEncoding.DecodeString(parts[1])
380+
if err != nil {
366381
return nil
367382
}
383+
384+
pair := strings.SplitN(string(payload), ":", 2)
385+
if len(pair) != 2 {
386+
return nil
387+
}
388+
368389
return &config.User{
369-
Username: username,
370-
Password: password,
390+
Username: pair[0],
391+
Password: pair[1],
371392
}
372393
}
373394

internal/utils/security_utils.go

Lines changed: 0 additions & 107 deletions
This file was deleted.

0 commit comments

Comments
 (0)