Skip to content

Commit

Permalink
feat: change method=profile:back to screen=previous (#4119)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
aeneasr committed Sep 25, 2024
1 parent aa48c6b commit 2cd8483
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"screen": {
"type": "string",
"enum": [
"credential-selection"
"credential-selection",
"previous"
]
},
"method": {
Expand Down
3 changes: 3 additions & 0 deletions selfservice/strategy/profile/.schema/settings.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"csrf_token": {
"type": "string"
},
"action": {
"type": "string"
},
"transient_payload": {
"type": "object",
"additionalProperties": true
Expand Down
32 changes: 22 additions & 10 deletions selfservice/strategy/profile/two_step_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
//
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()))
Expand Down
9 changes: 7 additions & 2 deletions spec/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
9 changes: 7 additions & 2 deletions spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down

0 comments on commit 2cd8483

Please sign in to comment.