diff --git a/pkg/api/login.go b/pkg/api/login.go index 4edc1f81400..921368fc114 100644 --- a/pkg/api/login.go +++ b/pkg/api/login.go @@ -129,7 +129,9 @@ func (hs *HTTPServer) LoginView(c *contextmodel.ReqContext) { if c.IsSignedIn { // Assign login token to auth proxy users if enable_login_token = true - if hs.Cfg.AuthProxyEnabled && hs.Cfg.AuthProxyEnableLoginToken { + if hs.Cfg.AuthProxyEnabled && + hs.Cfg.AuthProxyEnableLoginToken && + c.SignedInUser.AuthenticatedBy == loginservice.AuthProxyAuthModule { user := &user.User{ID: c.SignedInUser.UserID, Email: c.SignedInUser.Email, Login: c.SignedInUser.Login} err := hs.loginUserWithUser(user, c) if err != nil { diff --git a/pkg/api/login_test.go b/pkg/api/login_test.go index de63dfdbe28..7b6e76023d3 100644 --- a/pkg/api/login_test.go +++ b/pkg/api/login_test.go @@ -29,6 +29,7 @@ import ( "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/hooks" "github.com/grafana/grafana/pkg/services/licensing" + loginservice "github.com/grafana/grafana/pkg/services/login" "github.com/grafana/grafana/pkg/services/navtree" "github.com/grafana/grafana/pkg/services/secrets" "github.com/grafana/grafana/pkg/services/secrets/fakes" @@ -587,7 +588,8 @@ func TestAuthProxyLoginWithEnableLoginTokenAndEnabledOauthAutoLogin(t *testing.T sc.defaultHandler = routing.Wrap(func(c *contextmodel.ReqContext) response.Response { c.IsSignedIn = true c.SignedInUser = &user.SignedInUser{ - UserID: 10, + UserID: 10, + AuthenticatedBy: loginservice.AuthProxyAuthModule, } hs.LoginView(c) return response.Empty(http.StatusOK) @@ -626,7 +628,8 @@ func setupAuthProxyLoginTest(t *testing.T, enableLoginToken bool) *scenarioConte sc.defaultHandler = routing.Wrap(func(c *contextmodel.ReqContext) response.Response { c.IsSignedIn = true c.SignedInUser = &user.SignedInUser{ - UserID: 10, + UserID: 10, + AuthenticatedBy: loginservice.AuthProxyAuthModule, } hs.LoginView(c) return response.Empty(http.StatusOK) diff --git a/pkg/services/authn/clients/proxy.go b/pkg/services/authn/clients/proxy.go index a5631efe1eb..06abe1d64b9 100644 --- a/pkg/services/authn/clients/proxy.go +++ b/pkg/services/authn/clients/proxy.go @@ -114,6 +114,7 @@ func (c *Proxy) Authenticate(ctx context.Context, r *authn.Request) (*authn.Iden identity, clientErr = proxyClient.AuthenticateProxy(ctx, r, username, additional) if identity != nil { identity.ClientParams.CacheAuthProxyKey = cacheKey + identity.AuthenticatedBy = login.AuthProxyAuthModule return identity, nil } }