Fix username replacement

This commit is contained in:
Bolke de Bruin 2022-08-26 12:05:07 +02:00
parent 184ff320b8
commit 28890a97b6
2 changed files with 8 additions and 3 deletions

View File

@ -48,7 +48,6 @@ func (c *Config) BasicAuth(next http.HandlerFunc) http.HandlerFunc {
log.Printf("User %s is not authenticated for this service", username)
} else {
ctx := context.WithValue(r.Context(), "preferred_username", username)
ctx = context.WithValue(ctx, "access_token", "EMPTY")
next.ServeHTTP(w, r.WithContext(ctx))
return
}

View File

@ -21,13 +21,19 @@ func CheckHost(ctx context.Context, host string) (bool, error) {
// todo get from context?
return false, errors.New("cannot verify host in 'signed' mode as token data is missing")
case "roundrobin", "unsigned":
var username string
log.Printf("Checking host")
s := getSessionInfo(ctx)
if s == nil {
return false, errors.New("no valid session info found in context")
var ok bool
username, ok = ctx.Value("preferred_username").(string)
if !ok {
return false, errors.New("no valid session info or username found in context")
}
}
for _, h := range Hosts {
if s.UserName != "" {
if username != "" {
h = strings.Replace(h, "{{ preferred_username }}", s.UserName, 1)
}
if h == host {