Skip to content

Commit

Permalink
feat: identifier first login for all first factor login methods
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Jul 11, 2024
1 parent 5d8e327 commit 638b274
Show file tree
Hide file tree
Showing 241 changed files with 36,676 additions and 380 deletions.
4 changes: 2 additions & 2 deletions .schema/openapi/patches/selfservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
- "$ref": "#/components/schemas/updateLoginFlowWithLookupSecretMethod"
- "$ref": "#/components/schemas/updateLoginFlowWithCodeMethod"
- "$ref": "#/components/schemas/updateLoginFlowWithPasskeyMethod"
- "$ref": "#/components/schemas/updateLoginFlowWithTwoStepMethod"
- "$ref": "#/components/schemas/updateLoginFlowWithIdentifierFirstMethod"
- op: add
path: /components/schemas/updateLoginFlowBody/discriminator
value:
Expand All @@ -65,7 +65,7 @@
lookup_secret: "#/components/schemas/updateLoginFlowWithLookupSecretMethod"
code: "#/components/schemas/updateLoginFlowWithCodeMethod"
passkey: "#/components/schemas/updateLoginFlowWithPasskeyMethod"
two_step: "#/components/schemas/updateLoginFlowWithIdentifierFirstMethod"
identifier_first: "#/components/schemas/updateLoginFlowWithIdentifierFirstMethod"
- op: add
path: /components/schemas/loginFlowState/enum
value:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ migrations-sync: .bin/ory
ory dev pop migration sync persistence/sql/migrations/templates persistence/sql/migratest/testdata
script/add-down-migrations.sh

.PHONY: test-update-snapshots
test-update-snapshots:
.PHONY: test-refresh
test-refresh:
UPDATE_SNAPSHOTS=true go test -tags sqlite,json1,refresh -short ./...

.PHONY: post-release
Expand Down
2 changes: 1 addition & 1 deletion cmd/cliclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

"github.com/spf13/pflag"

kratos "github.com/ory/client-go"
kratos "github.com/ory/kratos/internal/httpclient"
)

const (
Expand Down
2 changes: 2 additions & 0 deletions cmd/clidoc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ func init() {
"NewErrorValidationAddressUnknown": text.NewErrorValidationAddressUnknown(),
"NewInfoSelfServiceLoginCodeMFA": text.NewInfoSelfServiceLoginCodeMFA(),
"NewInfoSelfServiceLoginCodeMFAHint": text.NewInfoSelfServiceLoginCodeMFAHint("{maskedIdentifier}"),
"NewInfoLoginPassword": text.NewInfoLoginPassword(),
"NewErrorValidationAccountNotFound": text.NewErrorValidationAccountNotFound(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/identities/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package identities
import (
"strings"

kratos "github.com/ory/client-go"
kratos "github.com/ory/kratos/internal/httpclient"

"github.com/ory/x/cmdx"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/identities/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package identities
import (
"fmt"

kratos "github.com/ory/client-go"
kratos "github.com/ory/kratos/internal/httpclient"
"github.com/ory/kratos/x"
"github.com/ory/x/cmdx"
"github.com/ory/x/stringsx"
Expand Down
2 changes: 1 addition & 1 deletion cmd/identities/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"encoding/json"
"fmt"

kratos "github.com/ory/client-go"
kratos "github.com/ory/kratos/internal/httpclient"

"github.com/ory/x/cmdx"

Expand Down
2 changes: 1 addition & 1 deletion cmd/identities/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"

kratos "github.com/ory/client-go"
"github.com/ory/kratos/driver/config"
kratos "github.com/ory/kratos/internal/httpclient"
)

func TestImportCmd(t *testing.T) {
Expand Down
19 changes: 11 additions & 8 deletions driver/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const (
ViperKeySelfServiceRegistrationAfter = "selfservice.flows.registration.after"
ViperKeySelfServiceRegistrationBeforeHooks = "selfservice.flows.registration.before.hooks"
ViperKeySelfServiceLoginUI = "selfservice.flows.login.ui_url"
ViperKeySelfServiceLoginFlowTwoStepEnabled = "selfservice.flows.login.two_step.enabled"
ViperKeySelfServiceLoginFlowStyle = "selfservice.flows.login.style"
ViperKeySecurityAccountEnumerationMitigate = "security.account_enumeration.mitigate"
ViperKeySelfServiceLoginRequestLifespan = "selfservice.flows.login.lifespan"
ViperKeySelfServiceLoginAfter = "selfservice.flows.login.after"
Expand Down Expand Up @@ -776,20 +776,18 @@ func (p *Config) SelfServiceStrategy(ctx context.Context, strategy string) *Self
var err error
config, err = json.Marshal(pp.GetF(basePath+".config", config))
if err != nil {
p.l.WithError(err).Warn("Unable to marshal self service strategy configuration.")
p.l.WithError(err).Warn("Unable to marshal self-service strategy configuration.")
config = json.RawMessage("{}")
}

// The default value can easily be overwritten by setting e.g. `{"selfservice": "null"}` which means that
// we need to forcibly set these values here:
defaultEnabled := false
switch strategy {
case "identity_discovery":
defaultEnabled = p.SelfServiceLoginFlowTwoStepEnabled(ctx)
break
case "identifier_first":
defaultEnabled = p.SelfServiceLoginFlowIdentifierFirstEnabled(ctx)
case "code", "password", "profile":
defaultEnabled = true
break
}

// Backwards compatibility for the old "passwordless_enabled" key
Expand Down Expand Up @@ -1619,8 +1617,13 @@ func (p *Config) PasswordMigrationHook(ctx context.Context) (hook *PasswordMigra
return hook
}

func (p *Config) SelfServiceLoginFlowTwoStepEnabled(ctx context.Context) bool {
return p.GetProvider(ctx).Bool(ViperKeySelfServiceLoginFlowTwoStepEnabled)
func (p *Config) SelfServiceLoginFlowIdentifierFirstEnabled(ctx context.Context) bool {
switch p.GetProvider(ctx).String(ViperKeySelfServiceLoginFlowStyle) {
case "identifier_first":
return true
default:
return false
}
}

func (p *Config) SecurityAccountEnumerationMitigate(ctx context.Context) bool {
Expand Down
6 changes: 4 additions & 2 deletions driver/registry_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ package driver
import (
"context"
"crypto/sha256"
"github.com/ory/kratos/selfservice/strategy/multistep"
"net/http"
"strings"
"sync"
"testing"
"time"

"github.com/ory/kratos/selfservice/strategy/idfirst"

"github.com/cenkalti/backoff"
"github.com/dgraph-io/ristretto"
"github.com/gobuffalo/pop/v6"
Expand Down Expand Up @@ -325,7 +326,7 @@ func (m *RegistryDefault) selfServiceStrategies() []any {
passkey.NewStrategy(m),
webauthn.NewStrategy(m),
lookup.NewStrategy(m),
multistep.NewStrategy(m),
idfirst.NewStrategy(m),
}
}
}
Expand Down Expand Up @@ -381,6 +382,7 @@ nextStrategy:
continue nextStrategy
}
}

if m.strategyLoginEnabled(ctx, s.ID().String()) {
loginStrategies = append(loginStrategies, s)
}
Expand Down
2 changes: 1 addition & 1 deletion driver/registry_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ func TestDefaultRegistry_AllStrategies(t *testing.T) {
_, reg := internal.NewVeryFastRegistryWithoutDB(t)

t.Run("case=all login strategies", func(t *testing.T) {
expects := []string{"password", "oidc", "code", "totp", "passkey", "webauthn", "lookup_secret"}
expects := []string{"password", "oidc", "code", "totp", "passkey", "webauthn", "lookup_secret", "identifier_first"}
s := reg.AllLoginStrategies()
require.Len(t, s, len(expects))
for k, e := range expects {
Expand Down
6 changes: 2 additions & 4 deletions examples/go/pkg/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import (
"os"
"testing"

"github.com/ory/kratos/x"

"github.com/ory/kratos/internal/testhelpers"

ory "github.com/ory/client-go"
"github.com/ory/kratos/internal/testhelpers"
"github.com/ory/kratos/x"
)

func PrintJSONPretty(v interface{}) {
Expand Down
2 changes: 1 addition & 1 deletion examples/go/selfservice/recovery/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

ory "github.com/ory/client-go"
"github.com/ory/kratos/examples/go/pkg"
ory "github.com/ory/kratos/internal/httpclient"
"github.com/ory/kratos/internal/testhelpers"
)

Expand Down
2 changes: 1 addition & 1 deletion examples/go/selfservice/settings/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main
import (
"testing"

ory "github.com/ory/client-go"
ory "github.com/ory/kratos/internal/httpclient"

"github.com/stretchr/testify/assert"

Expand Down
2 changes: 1 addition & 1 deletion examples/go/selfservice/verification/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

ory "github.com/ory/client-go"
"github.com/ory/kratos/examples/go/pkg"
ory "github.com/ory/kratos/internal/httpclient"
"github.com/ory/kratos/internal/testhelpers"
)

Expand Down
2 changes: 0 additions & 2 deletions identity/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ const (
CredentialsTypeCodeAuth CredentialsType = "code"
CredentialsTypePasskey CredentialsType = "passkey"
CredentialsTypeProfile CredentialsType = "profile"

TwoStep CredentialsType = "identity_discovery" // TODO move this somewhere else
)

func (c CredentialsType) String() string {
Expand Down
2 changes: 2 additions & 0 deletions internal/client-go/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ docs/UiText.md
docs/UpdateIdentityBody.md
docs/UpdateLoginFlowBody.md
docs/UpdateLoginFlowWithCodeMethod.md
docs/UpdateLoginFlowWithIdentifierFirstMethod.md
docs/UpdateLoginFlowWithLookupSecretMethod.md
docs/UpdateLoginFlowWithOidcMethod.md
docs/UpdateLoginFlowWithPasskeyMethod.md
Expand Down Expand Up @@ -221,6 +222,7 @@ model_ui_text.go
model_update_identity_body.go
model_update_login_flow_body.go
model_update_login_flow_with_code_method.go
model_update_login_flow_with_identifier_first_method.go
model_update_login_flow_with_lookup_secret_method.go
model_update_login_flow_with_oidc_method.go
model_update_login_flow_with_passkey_method.go
Expand Down
1 change: 1 addition & 0 deletions internal/client-go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ Class | Method | HTTP request | Description
- [UpdateIdentityBody](docs/UpdateIdentityBody.md)
- [UpdateLoginFlowBody](docs/UpdateLoginFlowBody.md)
- [UpdateLoginFlowWithCodeMethod](docs/UpdateLoginFlowWithCodeMethod.md)
- [UpdateLoginFlowWithIdentifierFirstMethod](docs/UpdateLoginFlowWithIdentifierFirstMethod.md)
- [UpdateLoginFlowWithLookupSecretMethod](docs/UpdateLoginFlowWithLookupSecretMethod.md)
- [UpdateLoginFlowWithOidcMethod](docs/UpdateLoginFlowWithOidcMethod.md)
- [UpdateLoginFlowWithPasskeyMethod](docs/UpdateLoginFlowWithPasskeyMethod.md)
Expand Down
2 changes: 1 addition & 1 deletion internal/client-go/model_identity_credentials.go

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

2 changes: 1 addition & 1 deletion internal/client-go/model_login_flow.go

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

2 changes: 1 addition & 1 deletion internal/client-go/model_registration_flow.go

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

2 changes: 1 addition & 1 deletion internal/client-go/model_ui_node.go

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

54 changes: 47 additions & 7 deletions internal/client-go/model_update_login_flow_body.go

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

Loading

0 comments on commit 638b274

Please sign in to comment.