@@ -11,9 +11,9 @@ import (
11 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/logger"
11 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/logger"
14−func NewBasicAuthSessionLoader(validator basic.Validator, sessionGroups []string) alice.Constructor {
14+func NewBasicAuthSessionLoader(validator basic.Validator, sessionGroups []string, preferEmail bool) alice.Constructor {
15 return func(next http.Handler) http.Handler {
15 return func(next http.Handler) http.Handler {
16− return loadBasicAuthSession(validator, sessionGroups, next)
16+ return loadBasicAuthSession(validator, sessionGroups, preferEmail, next)
@@ -22,7 +22,20 @@ func NewBasicAuthSessionLoader(validator basic.Validator, sessionGroups []string
22// If no authorization header is found, or the header is invalid, no session
22// If no authorization header is found, or the header is invalid, no session
23// will be loaded and the request will be passed to the next handler.
23// will be loaded and the request will be passed to the next handler.
24// If a session was loaded by a previous handler, it will not be replaced.
24// If a session was loaded by a previous handler, it will not be replaced.
25−func loadBasicAuthSession(validator basic.Validator, sessionGroups []string, next http.Handler) http.Handler {
25+func loadBasicAuthSession(validator basic.Validator, sessionGroups []string, preferEmail bool, next http.Handler) http.Handler {
26+ // This is a hack to be backwards compatible with the old PreferEmailToUser option.
27+ // Long term we will have a rich static user configuration option and this will
29+ // TODO(JoelSpeed): Remove this hack once rich static user config is implemented.
30+ getSession := getBasicSession
32+ getSession = func(validator basic.Validator, sessionGroups []string, req *http.Request) (*sessionsapi.SessionState, error) {
33+ session, err := getBasicSession(validator, sessionGroups, req)
34+ session.Email = session.User
26 return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
39 return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
27 scope := middlewareapi.GetRequestScope(req)
40 scope := middlewareapi.GetRequestScope(req)
28 // If scope is nil, this will panic.
41 // If scope is nil, this will panic.
@@ -33,7 +46,7 @@ func loadBasicAuthSession(validator basic.Validator, sessionGroups []string, nex
36− session, err := getBasicSession(validator, sessionGroups, req)
49+ session, err := getSession(validator, sessionGroups, req)
37 if err != nil {
50 if err != nil {
38 logger.Errorf("Error retrieving session from token in Authorization header: %v", err)
51 logger.Errorf("Error retrieving session from token in Authorization header: %v", err)