Skip to content
Snippets Groups Projects
Commit 28890a97 authored by Bolke de Bruin's avatar Bolke de Bruin
Browse files

Fix username replacement

parent 184ff320
No related branches found
No related tags found
No related merge requests found
...@@ -48,7 +48,6 @@ func (c *Config) BasicAuth(next http.HandlerFunc) http.HandlerFunc { ...@@ -48,7 +48,6 @@ func (c *Config) BasicAuth(next http.HandlerFunc) http.HandlerFunc {
log.Printf("User %s is not authenticated for this service", username) log.Printf("User %s is not authenticated for this service", username)
} else { } else {
ctx := context.WithValue(r.Context(), "preferred_username", username) ctx := context.WithValue(r.Context(), "preferred_username", username)
ctx = context.WithValue(ctx, "access_token", "EMPTY")
next.ServeHTTP(w, r.WithContext(ctx)) next.ServeHTTP(w, r.WithContext(ctx))
return return
} }
......
...@@ -21,13 +21,19 @@ func CheckHost(ctx context.Context, host string) (bool, error) { ...@@ -21,13 +21,19 @@ func CheckHost(ctx context.Context, host string) (bool, error) {
// todo get from context? // todo get from context?
return false, errors.New("cannot verify host in 'signed' mode as token data is missing") return false, errors.New("cannot verify host in 'signed' mode as token data is missing")
case "roundrobin", "unsigned": case "roundrobin", "unsigned":
var username string
log.Printf("Checking host") log.Printf("Checking host")
s := getSessionInfo(ctx) s := getSessionInfo(ctx)
if s == nil { 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 { for _, h := range Hosts {
if s.UserName != "" { if username != "" {
h = strings.Replace(h, "{{ preferred_username }}", s.UserName, 1) h = strings.Replace(h, "{{ preferred_username }}", s.UserName, 1)
} }
if h == host { if h == host {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment