Files
upstream-ory-kratos/selfservice/flow/login/strategy_form_hydrator.go
upstream-mirror c60cc7ca75
Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
snapshot of https://github.com/ory/kratos.git (master, 2026-09-15; blobs > 131072B omitted)
2026-09-15 21:19:12 +05:00

74 lines
2.4 KiB
Go

// Copyright © 2024 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package login
import (
stderr "errors"
"net/http"
"github.com/ory/kratos/identity"
"github.com/ory/kratos/session"
)
type UnifiedFormHydrator interface {
ID() identity.CredentialsType
PopulateLoginMethod(r *http.Request, requestedAAL identity.AuthenticatorAssuranceLevel, sr *Flow) error
}
type AAL1FormHydrator interface {
ID() identity.CredentialsType
PopulateLoginMethodFirstFactorRefresh(r *http.Request, sr *Flow, sess *session.Session) error
PopulateLoginMethodFirstFactor(r *http.Request, sr *Flow) error
// PopulateLoginMethodIdentifierFirstCredentials populates the login form with the first factor credentials.
// This method is called when the login flow is set to identifier first. The method will receive information
// about the identity that is being used to log in and the identifier that was used to find the identity.
//
// The method should populate the login form with the credentials of the identity.
//
// If the method can not find any credentials (because the identity does not exist) idfirst.ErrNoCredentialsFound
// must be returned. When returning idfirst.ErrNoCredentialsFound the strategy will appropriately deal with
// account enumeration mitigation.
//
// This method does however need to take appropriate steps to show/hide certain fields depending on the account
// enumeration configuration.
PopulateLoginMethodIdentifierFirstCredentials(r *http.Request, sr *Flow, options ...FormHydratorModifier) error
PopulateLoginMethodIdentifierFirstIdentification(r *http.Request, sr *Flow) error
}
type AAL2FormHydrator interface {
ID() identity.CredentialsType
PopulateLoginMethodSecondFactor(r *http.Request, sr *Flow) error
PopulateLoginMethodSecondFactorRefresh(r *http.Request, sr *Flow) error
}
var ErrBreakLoginPopulate = stderr.New("skip rest of login form population")
type FormHydratorOptions struct {
IdentityHint *identity.Identity
Identifier string
}
type FormHydratorModifier func(o *FormHydratorOptions)
func WithIdentityHint(i *identity.Identity) FormHydratorModifier {
return func(o *FormHydratorOptions) {
o.IdentityHint = i
}
}
func WithIdentifier(i string) FormHydratorModifier {
return func(o *FormHydratorOptions) {
o.Identifier = i
}
}
func NewFormHydratorOptions(modifiers []FormHydratorModifier) *FormHydratorOptions {
o := new(FormHydratorOptions)
for _, m := range modifiers {
m(o)
}
return o
}