From ad1acd51d8dd7582b05a3078b92f73970e1e2715 Mon Sep 17 00:00:00 2001 From: Arne Luenser Date: Wed, 25 Sep 2024 19:26:39 +0200 Subject: [PATCH] fix: passthrough correct organization ID to CompletedLoginForWithProvider (#4124) --- go.mod | 2 +- go.sum | 4 ++-- selfservice/flow/registration/handler.go | 2 +- selfservice/flow/registration/hook.go | 6 ++---- selfservice/flow/registration/hook_test.go | 2 +- selfservice/strategy/oidc/strategy_registration.go | 2 +- 6 files changed, 8 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 043213cc7acc..ac36ab25892a 100644 --- a/go.mod +++ b/go.mod @@ -70,7 +70,7 @@ require ( github.com/ory/jsonschema/v3 v3.0.8 github.com/ory/mail/v3 v3.0.0 github.com/ory/nosurf v1.2.7 - github.com/ory/x v0.0.656-0.20240924084701-ce6822d48829 + github.com/ory/x v0.0.660 github.com/peterhellberg/link v1.2.0 github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 60c01f878cb6..e33a12499ae0 100644 --- a/go.sum +++ b/go.sum @@ -645,8 +645,8 @@ github.com/ory/pop/v6 v6.2.0 h1:hRFOGAOEHw91kUHQ32k5NHqCkcHrRou/romvrJP1w0E= github.com/ory/pop/v6 v6.2.0/go.mod h1:okVAYKGtgunD/wbW3NGhZTndJCS+6FqO+cA89rQ4doc= github.com/ory/sessions v1.2.2-0.20220110165800-b09c17334dc2 h1:zm6sDvHy/U9XrGpixwHiuAwpp0Ock6khSVHkrv6lQQU= github.com/ory/sessions v1.2.2-0.20220110165800-b09c17334dc2/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= -github.com/ory/x v0.0.656-0.20240924084701-ce6822d48829 h1:y9BraWW+kjp/yYeuRLKBu951WVaLe2Z7lTqb4mPMlFk= -github.com/ory/x v0.0.656-0.20240924084701-ce6822d48829/go.mod h1:M+0EAXo7DT7Z2/Yrzvh4mgxOoV1fGI1jOKyAJ72d4Qs= +github.com/ory/x v0.0.660 h1:mEZjmVtPY5grN3bmuSPkJBTK7xSNepzy0bCmVOCLZxU= +github.com/ory/x v0.0.660/go.mod h1:tS0FyZXpVeKd1lCcFgV/Rb1GlccI/Xq8DraFS+lmIt8= github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= diff --git a/selfservice/flow/registration/handler.go b/selfservice/flow/registration/handler.go index 8cfe59e4d6d9..ee3e23ba144f 100644 --- a/selfservice/flow/registration/handler.go +++ b/selfservice/flow/registration/handler.go @@ -663,7 +663,7 @@ func (h *Handler) updateRegistrationFlow(w http.ResponseWriter, r *http.Request, return } - if err := h.d.RegistrationExecutor().PostRegistrationHook(w, r, s.ID(), "", f, i); err != nil { + if err := h.d.RegistrationExecutor().PostRegistrationHook(w, r, s.ID(), "", "", f, i); err != nil { h.d.RegistrationFlowErrorHandler().WriteFlowError(w, r, f, s.NodeGroup(), err) return } diff --git a/selfservice/flow/registration/hook.go b/selfservice/flow/registration/hook.go index c1c7b7ed4b2c..01ca1847d5d5 100644 --- a/selfservice/flow/registration/hook.go +++ b/selfservice/flow/registration/hook.go @@ -9,7 +9,6 @@ import ( "net/http" "time" - "github.com/julienschmidt/httprouter" "github.com/pkg/errors" "go.opentelemetry.io/otel/attribute" @@ -101,7 +100,7 @@ func NewHookExecutor(d executorDependencies) *HookExecutor { return &HookExecutor{d: d} } -func (e *HookExecutor) PostRegistrationHook(w http.ResponseWriter, r *http.Request, ct identity.CredentialsType, provider string, registrationFlow *Flow, i *identity.Identity) (err error) { +func (e *HookExecutor) PostRegistrationHook(w http.ResponseWriter, r *http.Request, ct identity.CredentialsType, provider, organizationID string, registrationFlow *Flow, i *identity.Identity) (err error) { ctx := r.Context() ctx, span := e.d.Tracer(ctx).Tracer().Start(ctx, "HookExecutor.PostRegistrationHook") r = r.WithContext(ctx) @@ -212,8 +211,7 @@ func (e *HookExecutor) PostRegistrationHook(w http.ResponseWriter, r *http.Reque s := session.NewInactiveSession() - s.CompletedLoginForWithProvider(ct, identity.AuthenticatorAssuranceLevel1, provider, - httprouter.ParamsFromContext(r.Context()).ByName("organization")) + s.CompletedLoginForWithProvider(ct, identity.AuthenticatorAssuranceLevel1, provider, organizationID) if err := e.d.SessionManager().ActivateSession(r, s, i, time.Now().UTC()); err != nil { return err } diff --git a/selfservice/flow/registration/hook_test.go b/selfservice/flow/registration/hook_test.go index 9e60b33f1f52..9a65b05a0eeb 100644 --- a/selfservice/flow/registration/hook_test.go +++ b/selfservice/flow/registration/hook_test.go @@ -65,7 +65,7 @@ func TestRegistrationExecutor(t *testing.T) { for _, callback := range flowCallbacks { callback(regFlow) } - _ = handleErr(t, w, r, reg.RegistrationHookExecutor().PostRegistrationHook(w, r, identity.CredentialsType(strategy), "", regFlow, i)) + _ = handleErr(t, w, r, reg.RegistrationHookExecutor().PostRegistrationHook(w, r, identity.CredentialsType(strategy), "", "", regFlow, i)) }) ts := httptest.NewServer(router) diff --git a/selfservice/strategy/oidc/strategy_registration.go b/selfservice/strategy/oidc/strategy_registration.go index 50567452aa9d..4edab83a351e 100644 --- a/selfservice/strategy/oidc/strategy_registration.go +++ b/selfservice/strategy/oidc/strategy_registration.go @@ -346,7 +346,7 @@ func (s *Strategy) processRegistration(ctx context.Context, w http.ResponseWrite } i.SetCredentials(s.ID(), *creds) - if err := s.d.RegistrationExecutor().PostRegistrationHook(w, r, identity.CredentialsTypeOIDC, provider.Config().ID, rf, i); err != nil { + if err := s.d.RegistrationExecutor().PostRegistrationHook(w, r, identity.CredentialsTypeOIDC, provider.Config().ID, provider.Config().OrganizationID, rf, i); err != nil { return nil, s.handleError(ctx, w, r, rf, provider.Config().ID, i.Traits, err) }