AuthN: Fix signout redirect url (#87631)

* Add missing return

* Use sign out redirect url from auth config if configured

* remove option from auth.jwt that is not used
This commit is contained in:
Karl Persson
2024-05-12 19:53:19 +02:00
committed by GitHub
parent 3dab7e44ec
commit 0f3080ecb8
4 changed files with 22 additions and 8 deletions
+7 -6
View File
@@ -17,7 +17,6 @@ import (
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/infra/usagestats"
"github.com/grafana/grafana/pkg/services/auth"
"github.com/grafana/grafana/pkg/services/auth/identity"
"github.com/grafana/grafana/pkg/services/authn"
"github.com/grafana/grafana/pkg/services/authn/clients"
"github.com/grafana/grafana/pkg/services/user"
@@ -265,15 +264,17 @@ func (s *Service) Logout(ctx context.Context, user authn.Requester, sessionToken
defer span.End()
redirect := &authn.Redirect{URL: s.cfg.AppSubURL + "/login"}
if s.cfg.SignoutRedirectUrl != "" {
redirect.URL = s.cfg.SignoutRedirectUrl
}
namespace, id := user.GetNamespacedID()
if namespace != authn.NamespaceUser {
if !user.GetID().IsNamespace(authn.NamespaceUser) {
return redirect, nil
}
userID, err := identity.IntIdentifier(namespace, id)
id, err := user.GetID().ParseInt()
if err != nil {
s.log.FromContext(ctx).Debug("Invalid user id", "id", userID, "err", err)
s.log.FromContext(ctx).Debug("Invalid user id", "id", id, "err", err)
return redirect, nil
}
@@ -301,7 +302,7 @@ func (s *Service) Logout(ctx context.Context, user authn.Requester, sessionToken
}
Default:
if err = s.sessionService.RevokeToken(ctx, sessionToken, false); err != nil {
if err = s.sessionService.RevokeToken(ctx, sessionToken, false); err != nil && !errors.Is(err, auth.ErrUserTokenNotFound) {
return nil, err
}