Skip to content

Commit

Permalink
feat: propagate password policy to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
mmeller-wikia committed Feb 26, 2024
1 parent 6a52949 commit de382c2
Show file tree
Hide file tree
Showing 36 changed files with 79 additions and 4 deletions.
4 changes: 4 additions & 0 deletions internal/client-go/model_ui_node_input_attributes.go

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

4 changes: 4 additions & 0 deletions internal/httpclient/model_ui_node_input_attributes.go

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 @@ -60,6 +60,8 @@
{
"attributes": {
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"name": "password",
"node_type": "input",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
{
"attributes": {
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"name": "password",
"node_type": "input",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
{
"attributes": {
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"name": "password",
"node_type": "input",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
{
"attributes": {
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"name": "password",
"node_type": "input",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
{
"attributes": {
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"name": "password",
"node_type": "input",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
{
"attributes": {
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"name": "password",
"node_type": "input",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
"type": "password",
"required": true,
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"node_type": "input"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
{
"attributes": {
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"name": "password",
"node_type": "input",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
"type": "password",
"required": true,
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"node_type": "input"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
"type": "password",
"required": true,
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"node_type": "input"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
{
"attributes": {
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"name": "password",
"node_type": "input",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
"type": "password",
"required": true,
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"node_type": "input"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
{
"attributes": {
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"name": "password",
"node_type": "input",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
"type": "password",
"required": true,
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"node_type": "input"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
{
"attributes": {
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"name": "password",
"node_type": "input",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
"type": "password",
"required": true,
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"node_type": "input"
},
Expand Down
2 changes: 1 addition & 1 deletion selfservice/strategy/password/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (s *Strategy) PopulateLoginMethod(r *http.Request, requestedAAL identity.Au
}

sr.UI.SetCSRF(s.d.GenerateCSRFToken(r))
sr.UI.SetNode(NewPasswordNode("password", node.InputAttributeAutocompleteCurrentPassword))
sr.UI.SetNode(NewPasswordNode("password", node.InputAttributeAutocompleteCurrentPassword, s.d.Config().PasswordPolicyConfig(r.Context())))
sr.UI.GetNodes().Append(node.NewInputField("method", "password", node.PasswordGroup, node.InputAttributeTypeSubmit).WithMetaLabel(text.NewInfoLogin()))

return nil
Expand Down
5 changes: 4 additions & 1 deletion selfservice/strategy/password/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
package password

import (
"github.com/ory/kratos/driver/config"
"github.com/ory/kratos/text"
"github.com/ory/kratos/ui/node"
)

func NewPasswordNode(name string, autocomplete node.UiNodeInputAttributeAutocomplete) *node.Node {
func NewPasswordNode(name string, autocomplete node.UiNodeInputAttributeAutocomplete, passwordPolicy *config.PasswordPolicy) *node.Node {
return node.NewInputField(name, nil, node.PasswordGroup,
node.InputAttributeTypePassword,
node.WithRequiredInputAttribute,
node.WithInputAttributes(func(a *node.InputAttributes) {
a.MinLength = passwordPolicy.MinPasswordLength
a.MaxLength = passwordPolicy.MaxPasswordLength
a.Autocomplete = autocomplete
})).
WithMetaLabel(text.NewInfoNodeInputPassword())
Expand Down
2 changes: 1 addition & 1 deletion selfservice/strategy/password/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (s *Strategy) PopulateRegistrationMethod(r *http.Request, f *registration.F
}

f.UI.SetCSRF(s.d.GenerateCSRFToken(r))
f.UI.Nodes.Upsert(NewPasswordNode("password", node.InputAttributeAutocompleteNewPassword))
f.UI.Nodes.Upsert(NewPasswordNode("password", node.InputAttributeAutocompleteNewPassword, s.d.Config().PasswordPolicyConfig(r.Context())))
f.UI.Nodes.Append(node.NewInputField("method", "password", node.PasswordGroup, node.InputAttributeTypeSubmit).WithMetaLabel(text.NewInfoRegistration()))

return nil
Expand Down
2 changes: 1 addition & 1 deletion selfservice/strategy/password/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (s *Strategy) continueSettingsFlow(

func (s *Strategy) PopulateSettingsMethod(r *http.Request, _ *identity.Identity, f *settings.Flow) error {
f.UI.SetCSRF(s.d.GenerateCSRFToken(r))
f.UI.Nodes.Upsert(NewPasswordNode("password", node.InputAttributeAutocompleteNewPassword).WithMetaLabel(text.NewInfoNodeInputPassword()))
f.UI.Nodes.Upsert(NewPasswordNode("password", node.InputAttributeAutocompleteNewPassword, s.d.Config().PasswordPolicyConfig(r.Context())).WithMetaLabel(text.NewInfoNodeInputPassword()))
f.UI.Nodes.Append(node.NewInputField("method", "password", node.PasswordGroup, node.InputAttributeTypeSubmit).WithMetaLabel(text.NewInfoNodeLabelSave()))

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
{
"attributes": {
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"name": "password",
"node_type": "input",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
{
"attributes": {
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"name": "password",
"node_type": "input",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
{
"attributes": {
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"name": "password",
"node_type": "input",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
{
"attributes": {
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"name": "password",
"node_type": "input",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
{
"attributes": {
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"name": "password",
"node_type": "input",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
{
"attributes": {
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"name": "password",
"node_type": "input",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
{
"attributes": {
"autocomplete": "new-password",
"minlength": 8,
"maxlength": 1024,
"disabled": false,
"name": "password",
"node_type": "input",
Expand Down
6 changes: 6 additions & 0 deletions ui/node/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ type InputAttributes struct {
// The autocomplete attribute for the input.
Autocomplete UiNodeInputAttributeAutocomplete `json:"autocomplete,omitempty"`

// The minlength attribute for the input.
MinLength uint `json:"minlength,omitempty"`

// The maxlength attribute for the input.
MaxLength uint `json:"maxlength,omitempty"`

// The input's label text.
Label *text.Message `json:"label,omitempty"`

Expand Down
2 changes: 2 additions & 0 deletions ui/node/fixtures/sort/expected/1.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
"attributes": {
"name": "password",
"type": "password",
"minlength": 8,
"maxlength": 1024,
"required": true,
"disabled": false,
"node_type": "input"
Expand Down
2 changes: 2 additions & 0 deletions ui/node/fixtures/sort/expected/2.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
"attributes": {
"name": "password",
"type": "password",
"minlength": 8,
"maxlength": 1024,
"required": true,
"disabled": false,
"node_type": "input"
Expand Down
2 changes: 2 additions & 0 deletions ui/node/fixtures/sort/expected/4.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
"attributes": {
"name": "password",
"type": "password",
"minlength": 8,
"maxlength": 1024,
"required": true,
"disabled": false,
"node_type": "input"
Expand Down
2 changes: 2 additions & 0 deletions ui/node/fixtures/sort/input/1.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
"attributes": {
"name": "password",
"type": "password",
"minlength": 8,
"maxlength": 1024,
"required": true,
"disabled": false
},
Expand Down
2 changes: 2 additions & 0 deletions ui/node/fixtures/sort/input/2.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"attributes": {
"name": "password",
"type": "password",
"minlength": 8,
"maxlength": 1024,
"required": true,
"disabled": false
},
Expand Down
2 changes: 2 additions & 0 deletions ui/node/fixtures/sort/input/4.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"attributes": {
"disabled": false,
"name": "password",
"minlength": 8,
"maxlength": 1024,
"required": true,
"type": "password"
},
Expand Down

0 comments on commit de382c2

Please sign in to comment.