From 2cd8483e809170d0524fe6a5d13837108d29fa54 Mon Sep 17 00:00:00 2001 From: hackerman <3372410+aeneasr@users.noreply.github.com> Date: Wed, 25 Sep 2024 14:26:09 +0200 Subject: [PATCH] feat: change `method=profile:back` to `screen=previous` (#4119) BREAKING CHANGE: When using two-step registration, it was previously possible to send `method=profile:back` to get to the previous screen. This feature was not documented in the SDK API yet. Going forward, please instead use `screen=previous`. --- Makefile | 4 +-- go.mod | 2 +- go.sum | 4 +-- ...e_registration_flow_with_profile_method.go | 2 +- ...e_registration_flow_with_profile_method.go | 2 +- .../profile/.schema/registration.schema.json | 3 +- .../profile/.schema/settings.schema.json | 3 ++ .../strategy/profile/two_step_registration.go | 32 +++++++++++++------ spec/api.json | 9 ++++-- spec/swagger.json | 9 ++++-- .../two-steps/registration/password.spec.ts | 2 +- 11 files changed, 49 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 4924072c8111..05c9c0de9760 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ docs/swagger: npx @redocly/openapi-cli preview-docs spec/swagger.json .bin/golangci-lint: Makefile - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -d -b .bin v1.59.1 + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -d -b .bin v1.61.0 .bin/hydra: Makefile bash <(curl https://raw.githubusercontent.com/ory/meta/master/install.sh) -d -b .bin hydra v2.2.0-rc.3 @@ -60,7 +60,7 @@ docs/swagger: .bin/buf: Makefile curl -sSL \ "https://github.com/bufbuild/buf/releases/download/v1.39.0/buf-$(shell uname -s)-$(shell uname -m).tar.gz" | \ - tar -xvzf - -C ".bin/" --strip-components=2 buf/bin/buf buf/bin/protoc-gen-buf-breaking buf/bin/protoc-gen-buf-lint + tar -xvzf - -C ".bin/" --strip-components=2 buf/bin/buf buf/bin/protoc-gen-buf-breaking buf/bin/protoc-gen-buf-lint touch -a -m .bin/buf .PHONY: lint diff --git a/go.mod b/go.mod index fe40535547ea..043213cc7acc 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.655 + github.com/ory/x v0.0.656-0.20240924084701-ce6822d48829 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 f95bea93a9a7..60c01f878cb6 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.655 h1:P+uwq8GE2YoB9sEyo/8nxuPwdHzBvXE/Xnkyujl7HeQ= -github.com/ory/x v0.0.655/go.mod h1:M+0EAXo7DT7Z2/Yrzvh4mgxOoV1fGI1jOKyAJ72d4Qs= +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/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/internal/client-go/model_update_registration_flow_with_profile_method.go b/internal/client-go/model_update_registration_flow_with_profile_method.go index 221e5ea82ada..eb9572c1f431 100644 --- a/internal/client-go/model_update_registration_flow_with_profile_method.go +++ b/internal/client-go/model_update_registration_flow_with_profile_method.go @@ -21,7 +21,7 @@ type UpdateRegistrationFlowWithProfileMethod struct { CsrfToken *string `json:"csrf_token,omitempty"` // Method Should be set to profile when trying to update a profile. Method string `json:"method"` - // Screen requests navigation to a previous screen. This must be set to credential-selection to go back to the credential selection screen. + // Screen requests navigation to a previous screen. This must be set to credential-selection to go back to the credential selection screen. credential-selection RegistrationScreenCredentialSelection previous RegistrationScreenPrevious Screen *string `json:"screen,omitempty"` // Traits The identity's traits. Traits map[string]interface{} `json:"traits"` diff --git a/internal/httpclient/model_update_registration_flow_with_profile_method.go b/internal/httpclient/model_update_registration_flow_with_profile_method.go index 221e5ea82ada..eb9572c1f431 100644 --- a/internal/httpclient/model_update_registration_flow_with_profile_method.go +++ b/internal/httpclient/model_update_registration_flow_with_profile_method.go @@ -21,7 +21,7 @@ type UpdateRegistrationFlowWithProfileMethod struct { CsrfToken *string `json:"csrf_token,omitempty"` // Method Should be set to profile when trying to update a profile. Method string `json:"method"` - // Screen requests navigation to a previous screen. This must be set to credential-selection to go back to the credential selection screen. + // Screen requests navigation to a previous screen. This must be set to credential-selection to go back to the credential selection screen. credential-selection RegistrationScreenCredentialSelection previous RegistrationScreenPrevious Screen *string `json:"screen,omitempty"` // Traits The identity's traits. Traits map[string]interface{} `json:"traits"` diff --git a/selfservice/strategy/profile/.schema/registration.schema.json b/selfservice/strategy/profile/.schema/registration.schema.json index 4a4d5dba16c4..727b8f86c7d5 100644 --- a/selfservice/strategy/profile/.schema/registration.schema.json +++ b/selfservice/strategy/profile/.schema/registration.schema.json @@ -12,7 +12,8 @@ "screen": { "type": "string", "enum": [ - "credential-selection" + "credential-selection", + "previous" ] }, "method": { diff --git a/selfservice/strategy/profile/.schema/settings.schema.json b/selfservice/strategy/profile/.schema/settings.schema.json index 5ae4ad70d94a..90246cbde523 100644 --- a/selfservice/strategy/profile/.schema/settings.schema.json +++ b/selfservice/strategy/profile/.schema/settings.schema.json @@ -13,6 +13,9 @@ "csrf_token": { "type": "string" }, + "action": { + "type": "string" + }, "transient_payload": { "type": "object", "additionalProperties": true diff --git a/selfservice/strategy/profile/two_step_registration.go b/selfservice/strategy/profile/two_step_registration.go index 800d04c1c40f..d6f037a54a92 100644 --- a/selfservice/strategy/profile/two_step_registration.go +++ b/selfservice/strategy/profile/two_step_registration.go @@ -9,6 +9,8 @@ import ( "encoding/json" "net/http" + "github.com/ory/x/otelx/semconv" + "go.opentelemetry.io/otel/attribute" "github.com/ory/x/otelx" @@ -65,6 +67,16 @@ func (s *Strategy) PopulateRegistrationMethod(r *http.Request, f *registration.F return nil } +// The RegistrationScreen +// swagger:enum RegistrationScreen +type RegistrationScreen string + +const ( + //nolint:gosec // not a credential + RegistrationScreenCredentialSelection RegistrationScreen = "credential-selection" + RegistrationScreenPrevious RegistrationScreen = "previous" +) + // Update Registration Flow with Profile Method // // swagger:model updateRegistrationFlowWithProfileMethod @@ -92,7 +104,7 @@ type updateRegistrationFlowWithProfileMethod struct { // selection screen. // // required: false - Screen string `json:"screen" form:"screen"` + Screen RegistrationScreen `json:"screen" form:"screen"` // FlowIDRequestID is the flow ID. // @@ -129,16 +141,16 @@ func (s *Strategy) Register(w http.ResponseWriter, r *http.Request, regFlow *reg return s.handleRegistrationError(r, regFlow, params, err) } - if params.Screen == "credential-selection" { - params.Method = "profile" - } - - switch params.Method { - case "profile": + if params.Method == "profile" || params.Screen == RegistrationScreenCredentialSelection { return s.displayStepTwoNodes(ctx, w, r, regFlow, i, params) - case "profile:back": + } else if params.Method == "profile:back" { + // "profile:back" is kept for backwards compatibility. + span.AddEvent(semconv.NewDeprecatedFeatureUsedEvent(ctx, "profile:back")) + return s.displayStepOneNodes(ctx, w, r, regFlow, params) + } else if params.Screen == RegistrationScreenPrevious { return s.displayStepOneNodes(ctx, w, r, regFlow, params) } + // Default case span.SetAttributes(attribute.String("not_responsible_reason", "method mismatch")) return flow.ErrStrategyNotResponsible @@ -194,8 +206,8 @@ func (s *Strategy) displayStepTwoNodes(ctx context.Context, w http.ResponseWrite regFlow.UI.Messages.Add(text.NewInfoSelfServiceChooseCredentials()) regFlow.UI.Nodes.Append(node.NewInputField( - "method", - "profile:back", + "screen", + "previous", node.ProfileGroup, node.InputAttributeTypeSubmit, ).WithMetaLabel(text.NewInfoRegistrationBack())) diff --git a/spec/api.json b/spec/api.json index f0331bee92e5..2c03f420226f 100644 --- a/spec/api.json +++ b/spec/api.json @@ -3244,8 +3244,13 @@ "type": "string" }, "screen": { - "description": "Screen requests navigation to a previous screen.\n\nThis must be set to credential-selection to go back to the credential\nselection screen.", - "type": "string" + "description": "Screen requests navigation to a previous screen.\n\nThis must be set to credential-selection to go back to the credential\nselection screen.\ncredential-selection RegistrationScreenCredentialSelection\nprevious RegistrationScreenPrevious", + "enum": [ + "credential-selection", + "previous" + ], + "type": "string", + "x-go-enum-desc": "credential-selection RegistrationScreenCredentialSelection\nprevious RegistrationScreenPrevious" }, "traits": { "description": "Traits\n\nThe identity's traits.", diff --git a/spec/swagger.json b/spec/swagger.json index 12ba5f44a9e6..3085b3a054c4 100755 --- a/spec/swagger.json +++ b/spec/swagger.json @@ -6228,8 +6228,13 @@ "type": "string" }, "screen": { - "description": "Screen requests navigation to a previous screen.\n\nThis must be set to credential-selection to go back to the credential\nselection screen.", - "type": "string" + "description": "Screen requests navigation to a previous screen.\n\nThis must be set to credential-selection to go back to the credential\nselection screen.\ncredential-selection RegistrationScreenCredentialSelection\nprevious RegistrationScreenPrevious", + "type": "string", + "enum": [ + "credential-selection", + "previous" + ], + "x-go-enum-desc": "credential-selection RegistrationScreenCredentialSelection\nprevious RegistrationScreenPrevious" }, "traits": { "description": "Traits\n\nThe identity's traits.", diff --git a/test/e2e/cypress/integration/profiles/two-steps/registration/password.spec.ts b/test/e2e/cypress/integration/profiles/two-steps/registration/password.spec.ts index 975306f8c857..8621b7a69483 100644 --- a/test/e2e/cypress/integration/profiles/two-steps/registration/password.spec.ts +++ b/test/e2e/cypress/integration/profiles/two-steps/registration/password.spec.ts @@ -46,7 +46,7 @@ context("Registration success with two-step signup", () => { cy.get('[name="method"][value="profile"]').click() // navigate back, fill traits again - cy.get('[name="method"][value="profile:back"]').click() + cy.get('[name="screen"][value="previous"]').click() cy.get('input[name="traits.email"]').type( "{selectall}{backspace}" + email, )