verification

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RouteInitBrowserFlow = "/self-service/verification/browser"
	RouteInitAPIFlow     = "/self-service/verification/api"
	RouteGetFlow         = "/self-service/verification/flows"

	RouteSubmitFlow = "/self-service/verification"
)

Variables

View Source
var ErrHookAbortFlow = errors.New("aborted verification hook execution")

Functions

func PostHookVerificationExecutorNames

func PostHookVerificationExecutorNames(e []PostHookExecutor) []string

Types

type AdminHandler

type AdminHandler interface {
	RegisterAdminVerificationRoutes(admin *x.RouterAdmin)
}

type ErrorHandler

type ErrorHandler struct {
	// contains filtered or unexported fields
}

func NewErrorHandler

func NewErrorHandler(d errorHandlerDependencies) *ErrorHandler

func (*ErrorHandler) WriteFlowError

func (s *ErrorHandler) WriteFlowError(
	w http.ResponseWriter,
	r *http.Request,
	f *Flow,
	group node.UiNodeGroup,
	err error,
)

type ErrorHandlerProvider

type ErrorHandlerProvider interface {
	VerificationFlowErrorHandler() *ErrorHandler
}

type FakeStrategy added in v1.1.0

type FakeStrategy struct{}

func (FakeStrategy) NodeGroup added in v1.1.0

func (f FakeStrategy) NodeGroup() node.UiNodeGroup

func (FakeStrategy) PopulateVerificationMethod added in v1.1.0

func (f FakeStrategy) PopulateVerificationMethod(*http.Request, *Flow) error

func (FakeStrategy) SendVerificationEmail added in v1.1.0

func (FakeStrategy) VerificationNodeGroup added in v1.1.0

func (f FakeStrategy) VerificationNodeGroup() node.UiNodeGroup

func (FakeStrategy) VerificationStrategyID added in v1.1.0

func (f FakeStrategy) VerificationStrategyID() string

func (FakeStrategy) Verify added in v1.1.0

func (f FakeStrategy) Verify(_ http.ResponseWriter, _ *http.Request, _ *Flow) (err error)

type Flow

type Flow struct {
	// ID represents the request's unique ID. When performing the verification flow, this
	// represents the id in the verify ui's query parameter: http://<selfservice.flows.verification.ui_url>?request=<id>
	//
	// type: string
	// format: uuid
	// required: true
	ID uuid.UUID `json:"id" db:"id" faker:"-"`

	// Type represents the flow's type which can be either "api" or "browser", depending on the flow interaction.
	//
	// required: true
	Type flow.Type `json:"type" db:"type" faker:"flow_type"`

	// ExpiresAt is the time (UTC) when the request expires. If the user still wishes to verify the address,
	// a new request has to be initiated.
	ExpiresAt time.Time `json:"expires_at" faker:"time_type" db:"expires_at"`

	// IssuedAt is the time (UTC) when the request occurred.
	IssuedAt time.Time `json:"issued_at" faker:"time_type" db:"issued_at"`

	// RequestURL is the initial URL that was requested from Ory Kratos. It can be used
	// to forward information contained in the URL's path or query for example.
	RequestURL string `json:"request_url" db:"request_url"`

	// ReturnTo contains the requested return_to URL.
	ReturnTo string `json:"return_to,omitempty" db:"-"`

	// Active, if set, contains the registration method that is being used. It is initially
	// not set.
	Active sqlxx.NullString `json:"active,omitempty" faker:"-" db:"active_method"`

	// UI contains data which must be shown in the user interface.
	//
	// required: true
	UI *container.Container `json:"ui" db:"ui"`

	// State represents the state of this request:
	//
	// - choose_method: ask the user to choose a method (e.g. verify your email)
	// - sent_email: the email has been sent to the user
	// - passed_challenge: the request was successful and the verification challenge was passed.
	//
	// required: true
	State State `json:"state" faker:"-" db:"state"`

	// OAuth2LoginChallenge holds the login challenge originally set during the registration flow.
	OAuth2LoginChallenge sqlxx.NullString `json:"-" db:"oauth2_login_challenge"`
	OAuth2LoginChallengeParams

	// CSRFToken contains the anti-csrf token associated with this request.
	CSRFToken string `json:"-" db:"csrf_token"`

	// CreatedAt is a helper struct field for gobuffalo.pop.
	CreatedAt time.Time `json:"-" faker:"-" db:"created_at"`
	// UpdatedAt is a helper struct field for gobuffalo.pop.
	UpdatedAt time.Time `json:"-" faker:"-" db:"updated_at"`
	NID       uuid.UUID `json:"-"  faker:"-" db:"nid"`

	// TransientPayload is used to pass data from the verification flow to hooks and email templates
	//
	// required: false
	TransientPayload json.RawMessage `json:"transient_payload,omitempty" faker:"-" db:"-"`
}

A Verification Flow

Used to verify an out-of-band communication channel such as an email address or a phone number.

For more information head over to: https://www.ory.sh/docs/kratos/self-service/flows/verify-email-account-activation

swagger:model verificationFlow

func FromOldFlow

func FromOldFlow(conf *config.Config, exp time.Duration, csrf string, r *http.Request, strategy Strategy, of *Flow) (*Flow, error)

func NewFlow

func NewFlow(conf *config.Config, exp time.Duration, csrf string, r *http.Request, strategy Strategy, ft flow.Type) (*Flow, error)

func NewPostHookFlow

func NewPostHookFlow(conf *config.Config, exp time.Duration, csrf string, r *http.Request, strategy Strategy, original flow.Flow) (*Flow, error)

func (*Flow) AfterFind

func (f *Flow) AfterFind(*pop.Connection) error

func (*Flow) AfterSave

func (f *Flow) AfterSave(*pop.Connection) error

func (*Flow) AppendTo

func (f *Flow) AppendTo(src *url.URL) *url.URL

func (*Flow) ContinueURL added in v0.13.0

func (f *Flow) ContinueURL(ctx context.Context, config *config.Config) *url.URL

ContinueURL generates the URL to show on the continue screen after succesful verification

It follows the following precedence:

  1. If a `return_to` parameter has been passed to the flow's creation, is a valid URL and it's in the `selfservice.allowed_return_urls` that URL is returned
  2. If `selfservice.flows.verification.after` is set, that URL is returned
  3. As a fallback, the `selfservice.default_browser_return_url` URL is returned

func (*Flow) GetFlowName added in v1.1.0

func (f *Flow) GetFlowName() flow.FlowName

func (Flow) GetID

func (f Flow) GetID() uuid.UUID

func (Flow) GetNID

func (f Flow) GetNID() uuid.UUID

func (*Flow) GetRequestURL

func (f *Flow) GetRequestURL() string

func (*Flow) GetState added in v1.1.0

func (f *Flow) GetState() State

func (*Flow) GetTransientPayload added in v1.2.0

func (t *Flow) GetTransientPayload() json.RawMessage

func (*Flow) GetType

func (f *Flow) GetType() flow.Type

func (*Flow) GetUI added in v0.11.0

func (f *Flow) GetUI() *container.Container

func (Flow) MarshalJSON

func (f Flow) MarshalJSON() ([]byte, error)

func (*Flow) SetCSRFToken

func (f *Flow) SetCSRFToken(token string)

func (*Flow) SetReturnTo

func (f *Flow) SetReturnTo()

func (*Flow) SetState added in v1.1.0

func (f *Flow) SetState(state State)

func (Flow) TableName

func (f Flow) TableName(context.Context) string

func (*Flow) ToLoggerField added in v1.3.0

func (f *Flow) ToLoggerField() map[string]interface{}

func (*Flow) Valid

func (f *Flow) Valid() error

type FlowOption added in v0.11.0

type FlowOption func(f *Flow)

func WithFlowReturnTo added in v0.11.0

func WithFlowReturnTo(returnTo string) FlowOption

type FlowPersistenceProvider

type FlowPersistenceProvider interface {
	VerificationFlowPersister() FlowPersister
}

type FlowPersister

type FlowPersister interface {
	CreateVerificationFlow(context.Context, *Flow) error
	GetVerificationFlow(ctx context.Context, id uuid.UUID) (*Flow, error)
	UpdateVerificationFlow(context.Context, *Flow) error
	DeleteExpiredVerificationFlows(context.Context, time.Time, int) error
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(d handlerDependencies) *Handler

func (*Handler) NewVerificationFlow added in v0.11.0

func (h *Handler) NewVerificationFlow(w http.ResponseWriter, r *http.Request, ft flow.Type, opts ...FlowOption) (*Flow, error)

func (*Handler) RegisterAdminRoutes

func (h *Handler) RegisterAdminRoutes(admin *x.RouterAdmin)

func (*Handler) RegisterPublicRoutes

func (h *Handler) RegisterPublicRoutes(public *x.RouterPublic)

type HandlerProvider

type HandlerProvider interface {
	VerificationHandler() *Handler
}

type HookExecutor

type HookExecutor struct {
	// contains filtered or unexported fields
}

func NewHookExecutor

func NewHookExecutor(d executorDependencies) *HookExecutor

func (*HookExecutor) PostVerificationHook

func (e *HookExecutor) PostVerificationHook(w http.ResponseWriter, r *http.Request, a *Flow, i *identity.Identity) error

func (*HookExecutor) PreVerificationHook added in v0.11.0

func (e *HookExecutor) PreVerificationHook(w http.ResponseWriter, r *http.Request, a *Flow) error

type HookExecutorProvider

type HookExecutorProvider interface {
	VerificationExecutor() *HookExecutor
}

type HooksProvider

type HooksProvider interface {
	PostVerificationHooks(ctx context.Context) []PostHookExecutor
	PreVerificationHooks(ctx context.Context) []PreHookExecutor
}

type OAuth2LoginChallengeParams added in v1.1.0

type OAuth2LoginChallengeParams struct {
	// SessionID holds the session id if set from a registraton hook.
	SessionID uuid.NullUUID `json:"-" faker:"-" db:"session_id"`

	// IdentityID holds the identity id if set from a registraton hook.
	IdentityID uuid.NullUUID `json:"-" faker:"-" db:"identity_id"`

	// AMR contains a list of authentication methods that were used to verify the
	// session if set from a registration hook.
	AMR session.AuthenticationMethods `db:"authentication_methods" json:"-"`
}

type PostHookExecutor

type PostHookExecutor interface {
	ExecutePostVerificationHook(w http.ResponseWriter, r *http.Request, a *Flow, i *identity.Identity) error
}

type PostHookExecutorFunc

type PostHookExecutorFunc func(w http.ResponseWriter, r *http.Request, a *Flow, i *identity.Identity) error

func (PostHookExecutorFunc) ExecutePostVerificationHook

func (f PostHookExecutorFunc) ExecutePostVerificationHook(w http.ResponseWriter, r *http.Request, a *Flow, i *identity.Identity) error

type PreHookExecutor added in v0.11.0

type PreHookExecutor interface {
	ExecuteVerificationPreHook(w http.ResponseWriter, r *http.Request, a *Flow) error
}

type PreHookExecutorFunc added in v0.11.0

type PreHookExecutorFunc func(w http.ResponseWriter, r *http.Request, a *Flow) error

func (PreHookExecutorFunc) ExecuteVerificationPreHook added in v0.11.0

func (f PreHookExecutorFunc) ExecuteVerificationPreHook(w http.ResponseWriter, r *http.Request, a *Flow) error

type PublicHandler

type PublicHandler interface {
	RegisterPublicVerificationRoutes(public *x.RouterPublic)
}

type State

type State = flow.State

Verification Flow State

The state represents the state of the verification flow.

- choose_method: ask the user to choose a method (e.g. recover account via email) - sent_email: the email has been sent to the user - passed_challenge: the request was successful and the recovery challenge was passed.

swagger:model verificationFlowState

type Strategies

type Strategies []Strategy

func (Strategies) MustStrategy

func (s Strategies) MustStrategy(id string) Strategy

func (Strategies) RegisterAdminRoutes

func (s Strategies) RegisterAdminRoutes(r *x.RouterAdmin)

func (Strategies) RegisterPublicRoutes

func (s Strategies) RegisterPublicRoutes(r *x.RouterPublic)

func (Strategies) Strategy

func (s Strategies) Strategy(id string) (Strategy, error)

type Strategy

type Strategy interface {
	VerificationStrategyID() string
	NodeGroup() node.UiNodeGroup
	PopulateVerificationMethod(*http.Request, *Flow) error
	Verify(w http.ResponseWriter, r *http.Request, f *Flow) (err error)
	SendVerificationEmail(context.Context, *Flow, *identity.Identity, *identity.VerifiableAddress) error
}

type StrategyProvider

type StrategyProvider interface {
	VerificationStrategies(ctx context.Context) Strategies
	AllVerificationStrategies() Strategies
	GetActiveVerificationStrategy(context.Context) (Strategy, error)
}

type VerificationStrategy added in v0.13.0

type VerificationStrategy string
const (
	VerificationStrategyLink VerificationStrategy = "link"
	VerificationStrategyCode VerificationStrategy = "code"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL