Skip to content

Commit

Permalink
fix: distinguish credential types properly when collecting identifiers (
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik committed Nov 8, 2022
1 parent 5c140ce commit 705f7b1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fullstorydev/grpcurl v1.8.1 // indirect
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
github.com/go-bindata/go-bindata v3.1.2+incompatible // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,6 @@ github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49P
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE=
github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w=
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
Expand Down Expand Up @@ -1141,8 +1139,6 @@ github.com/ory/sessions v1.2.2-0.20220110165800-b09c17334dc2 h1:zm6sDvHy/U9XrGpi
github.com/ory/sessions v1.2.2-0.20220110165800-b09c17334dc2/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/ory/viper v1.7.5 h1:+xVdq7SU3e1vNaCsk/ixsfxE4zylk1TJUiJrY647jUE=
github.com/ory/viper v1.7.5/go.mod h1:ypOuyJmEUb3oENywQZRgeAMwqgOyDqwboO1tj3DjTaM=
github.com/ory/x v0.0.506 h1:kqkGwRuhZsyLf2zgjIyOkuY1nRfbWu2aPOQTk03j6ZQ=
github.com/ory/x v0.0.506/go.mod h1:xUtRpoiRARyJNPVk/fcCNKzyp25Foxt9GPlj8pd7egY=
github.com/ory/x v0.0.510 h1:DksQNoq7ssdR76mhcNxzaGPKmzaQEKWg2kannGsD8+w=
github.com/ory/x v0.0.510/go.mod h1:xUtRpoiRARyJNPVk/fcCNKzyp25Foxt9GPlj8pd7egY=
github.com/ory/x v0.0.511-0.20221108105728-3fed9bc99daf h1:sPEIGYHzmEu4tPiRUYgKfXPOAqneNuB1aaKvrT6aBXE=
Expand Down
10 changes: 6 additions & 4 deletions identity/extension_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

type SchemaExtensionCredentials struct {
i *Identity
v []string
v map[CredentialsType][]string
l sync.Mutex
}

Expand All @@ -31,11 +31,13 @@ func (r *SchemaExtensionCredentials) setIdentifier(ct CredentialsType, value int
Config: sqlxx.JSONRawMessage{},
}
}
if r.v == nil {
r.v = make(map[CredentialsType][]string)
}

r.v = stringslice.Unique(append(r.v, strings.ToLower(fmt.Sprintf("%s", value))))
cred.Identifiers = r.v
r.v[ct] = stringslice.Unique(append(r.v[ct], strings.ToLower(fmt.Sprintf("%s", value))))
cred.Identifiers = r.v[ct]
r.i.SetCredentials(ct, *cred)

}

func (r *SchemaExtensionCredentials) Run(_ jsonschema.ValidationContext, s schema.ExtensionConfig, value interface{}) error {
Expand Down
6 changes: 6 additions & 0 deletions identity/extension_credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ func TestSchemaExtensionCredentials(t *testing.T) {
expect: []string{"foo@ory.sh", "bar@ory.sh", "foobar"},
ct: identity.CredentialsTypePassword,
},
{
doc: `{"emails":["foo@ory.sh","foo@ory.sh","bar@ory.sh"], "username": "foobar"}`,
schema: "file://./stub/extension/credentials/multi.schema.json",
expect: []string{"foo@ory.sh", "bar@ory.sh"},
ct: identity.CredentialsTypeWebAuthn,
},
{
doc: `{"emails":["FOO@ory.sh","bar@ory.sh"], "username": "foobar"}`,
schema: "file://./stub/extension/credentials/multi.schema.json",
Expand Down
3 changes: 3 additions & 0 deletions identity/stub/extension/credentials/multi.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"credentials": {
"password": {
"identifier": true
},
"webauthn": {
"identifier": true
}
}
}
Expand Down

0 comments on commit 705f7b1

Please sign in to comment.