Skip to content

Commit

Permalink
whauth: store authed username
Browse files Browse the repository at this point in the history
  • Loading branch information
jtolio committed Jan 25, 2017
1 parent cd8c17f commit 9334fa3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion whauth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ package whauth // import "gopkg.in/webhelp.v1/whauth"
import (
"net/http"

"golang.org/x/net/context"
"gopkg.in/webhelp.v1"
"gopkg.in/webhelp.v1/whcompat"
"gopkg.in/webhelp.v1/wherr"
"gopkg.in/webhelp.v1/whroute"
)

var (
BasicAuthUser = webhelp.GenSym()
)

// RequireBasicAuth ensures that a valid user is provided, calling
// wherr.Handle with wherr.Unauthorized if not.
func RequireBasicAuth(h http.Handler, realm string,
Expand All @@ -30,6 +37,7 @@ func RequireBasicAuth(h http.Handler, realm string,
wherr.Unauthorized.New("invalid username or password"))
return
}
h.ServeHTTP(w, r)
h.ServeHTTP(w, whcompat.WithContext(r, context.WithValue(
whcompat.Context(r), BasicAuthUser, user)))
})
}

0 comments on commit 9334fa3

Please sign in to comment.