@@ -11,9 +11,9 @@ import (
1111 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/logger"
1212)
1313
14−func NewBasicAuthSessionLoader(validator basic.Validator) alice.Constructor {
14+func NewBasicAuthSessionLoader(validator basic.Validator, sessionGroups []string) alice.Constructor {
1515 return func(next http.Handler) http.Handler {
16− return loadBasicAuthSession(validator, next)
16+ return loadBasicAuthSession(validator, sessionGroups, next)
1717 }
1818}
1919
@@ -22,7 +22,7 @@ func NewBasicAuthSessionLoader(validator basic.Validator) alice.Constructor {
2222// If no authorization header is found, or the header is invalid, no session
2323// will be loaded and the request will be passed to the next handler.
2424// If a session was loaded by a previous handler, it will not be replaced.
25−func loadBasicAuthSession(validator basic.Validator, next http.Handler) http.Handler {
25+func loadBasicAuthSession(validator basic.Validator, sessionGroups []string, next http.Handler) http.Handler {
2626 return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
2727 scope := middlewareapi.GetRequestScope(req)
2828 // If scope is nil, this will panic.
@@ -33,7 +33,7 @@ func loadBasicAuthSession(validator basic.Validator, next http.Handler) http.Han
3333 return
3434 }
3535
36− session, err := getBasicSession(validator, req)
36+ session, err := getBasicSession(validator, sessionGroups, req)
3737 if err != nil {
3838 logger.Errorf("Error retrieving session from token in Authorization header: %v", err)
3939 }
@@ -47,7 +47,7 @@ func loadBasicAuthSession(validator basic.Validator, next http.Handler) http.Han
4747// getBasicSession attempts to load a basic session from the request.
4848// If the credentials in the request exist within the htpasswdMap,
4949// a new session will be created.
50−func getBasicSession(validator basic.Validator, req *http.Request) (*sessionsapi.SessionState, error) {
50+func getBasicSession(validator basic.Validator, sessionGroups []string, req *http.Request) (*sessionsapi.SessionState, error) {
5151 auth := req.Header.Get("Authorization")
5252 if auth == "" {
5353 // No auth header provided, so don't attempt to load a session
@@ -61,7 +61,8 @@ func getBasicSession(validator basic.Validator, req *http.Request) (*sessionsapi
6161
6262 if validator.Validate(user, password) {
6363 logger.PrintAuthf(user, req, logger.AuthSuccess, "Authenticated via basic auth and HTpasswd File")
64− return &sessionsapi.SessionState{User: user}, nil
64+
65+ return &sessionsapi.SessionState{User: user, Groups: sessionGroups}, nil
6566 }
6667
6768 logger.PrintAuthf(user, req, logger.AuthFailure, "Invalid authentication via basic auth: not in Htpasswd File")