Authn: Only resolve org id once (#78811)

This commit is contained in:
Karl Persson 2023-11-29 15:55:39 +01:00 committed by GitHub
parent 21f94c5b78
commit 687ffb4a0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -191,6 +191,8 @@ func (s *Service) Authenticate(ctx context.Context, r *authn.Request) (*authn.Id
ctx, span := s.tracer.Start(ctx, "authn.Authenticate")
defer span.End()
r.OrgID = orgIDFromRequest(r)
var authErr error
for _, item := range s.clientQueue.items {
if item.v.Test(ctx, r) {
@ -223,7 +225,6 @@ func (s *Service) Authenticate(ctx context.Context, r *authn.Request) (*authn.Id
}
func (s *Service) authenticate(ctx context.Context, c authn.Client, r *authn.Request) (*authn.Identity, error) {
r.OrgID = orgIDFromRequest(r)
identity, err := c.Authenticate(ctx, r)
if err != nil {
s.errorLogFunc(ctx, err)("Failed to authenticate request", "client", c.Name(), "error", err)
@ -268,6 +269,8 @@ func (s *Service) Login(ctx context.Context, client string, r *authn.Request) (i
))
defer span.End()
r.OrgID = orgIDFromRequest(r)
defer func() {
for _, hook := range s.postLoginHooks.items {
hook.v(ctx, identity, r, err)