registration

package
v1.3.0-pre.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	RouteInitBrowserFlow = "/self-service/registration/browser"
	RouteInitAPIFlow     = "/self-service/registration/api"

	RouteGetFlow = "/self-service/registration/flows"

	RouteSubmitFlow = "/self-service/registration"
)

Variables

View Source
var (
	ErrHookAbortFlow        = errors.New("aborted registration hook execution")
	ErrAlreadyLoggedIn      = herodot.ErrBadRequest.WithID(text.ErrIDAlreadyLoggedIn).WithError("you are already logged in").WithReason("A valid session was detected and thus registration is not possible.")
	ErrRegistrationDisabled = herodot.ErrBadRequest.WithID(text.ErrIDSelfServiceFlowDisabled).WithError("registration flow disabled").WithReason("Registration is not allowed because it was disabled.")
)

Functions

func DecodeBody

func DecodeBody(p interface{}, r *http.Request, dec *decoderx.HTTP, conf *config.Config, schema []byte) error

func ExecutorNames added in v0.13.0

func ExecutorNames[T any](e []T) []string

func SortNodes

func SortNodes(ctx context.Context, n node.Nodes, schemaRef string) error

Types

type APIFlowResponse

type APIFlowResponse struct {
	// The Session Token
	//
	// This field is only set when the session hook is configured as a post-registration hook.
	//
	// A session token is equivalent to a session cookie, but it can be sent in the HTTP Authorization
	// Header:
	//
	// 		Authorization: bearer ${session-token}
	//
	// The session token is only issued for API flows, not for Browser flows!
	Token string `json:"session_token,omitempty"`

	// The Session
	//
	// This field is only set when the session hook is configured as a post-registration hook.
	//
	// The session contains information about the user, the session device, and so on.
	// This is only available for API flows, not for Browser flows!
	Session *session.Session `json:"session,omitempty"`

	// The Identity
	//
	// The identity that just signed up.
	//
	// required: true
	Identity *identity.Identity `json:"identity"`

	// Contains a list of actions, that could follow this flow
	//
	// It can, for example, this will contain a reference to the verification flow, created as part of the user's
	// registration or the token of the session.
	//
	// required: false
	ContinueWith []flow.ContinueWith `json:"continue_with"`
}

The Response for Registration Flows via API

swagger:model successfulNativeRegistration

type ErrorHandler

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

func NewErrorHandler

func NewErrorHandler(d errorHandlerDependencies) *ErrorHandler

func (*ErrorHandler) PrepareReplacementForExpiredFlow

func (s *ErrorHandler) PrepareReplacementForExpiredFlow(w http.ResponseWriter, r *http.Request, f *Flow, err error) (*flow.ExpiredError, error)

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{ RegistrationFlowErrorHandler() *ErrorHandler }

type Flow

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

	// Ory OAuth 2.0 Login Challenge.
	//
	// This value is set using the `login_challenge` query parameter of the registration and login endpoints.
	// If set will cooperate with Ory OAuth2 and OpenID to act as an OAuth2 server / OpenID Provider.
	OAuth2LoginChallenge sqlxx.NullString `json:"oauth2_login_challenge,omitempty" faker:"-" db:"oauth2_login_challenge_data"`

	// HydraLoginRequest is an optional field whose presence indicates that Kratos
	// is being used as an identity provider in a Hydra OAuth2 flow. Kratos
	// populates this field by retrieving its value from Hydra and it is used by
	// the login and consent UIs.
	HydraLoginRequest *hydraclientgo.OAuth2LoginRequest `json:"oauth2_login_request,omitempty" faker:"-" db:"-"`

	// 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 flow expires. If the user still wishes to log in,
	// a new flow has to be initiated.
	//
	// required: true
	ExpiresAt time.Time `json:"expires_at" faker:"time_type" db:"expires_at"`

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

	// InternalContext stores internal context used by internals - for example MFA keys.
	InternalContext sqlxx.JSONRawMessage `db:"internal_context" json:"-" faker:"-"`

	// 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.
	//
	// required: true
	RequestURL string `json:"request_url" faker:"url" db:"request_url"`

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

	// ReturnToVerification contains the redirect URL for the verification flow.
	ReturnToVerification string `json:"-" db:"-"`

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

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

	// 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"`

	// CSRFToken contains the anti-csrf token associated with this flow. Only set for browser flows.
	CSRFToken      string        `json:"-" db:"csrf_token"`
	NID            uuid.UUID     `json:"-" faker:"-" db:"nid"`
	OrganizationID uuid.NullUUID `json:"organization_id,omitempty"  faker:"-" db:"organization_id"`

	// TransientPayload is used to pass data from the registration to a webhook
	//
	// required: false
	TransientPayload json.RawMessage `json:"transient_payload,omitempty" faker:"-" db:"-"`

	// Contains a list of actions, that could follow this flow
	//
	// It can, for example, contain a reference to the verification flow, created as part of the user's
	// registration.
	ContinueWithItems []flow.ContinueWith `json:"-" db:"-" faker:"-" `

	// SessionTokenExchangeCode holds the secret code that the client can use to retrieve a session token after the flow has been completed.
	// This is only set if the client has requested a session token exchange code, and if the flow is of type "api",
	// and only on creating the flow.
	SessionTokenExchangeCode string `json:"session_token_exchange_code,omitempty" faker:"-" db:"-"`

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

	// only used internally
	IDToken string `json:"-" faker:"-" db:"-"`
	// Only used internally
	RawIDTokenNonce string `json:"-" db:"-"`
}

swagger:model registrationFlow

func NewFlow

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

func (*Flow) AddContinueWith added in v0.13.0

func (f *Flow) AddContinueWith(c flow.ContinueWith)

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) ContinueWith added in v0.13.0

func (f *Flow) ContinueWith() []flow.ContinueWith

func (*Flow) EnsureInternalContext

func (f *Flow) EnsureInternalContext()

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) GetInternalContext added in v1.1.0

func (f *Flow) GetInternalContext() sqlxx.JSONRawMessage

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 (f *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) SecureRedirectToOpts added in v1.0.0

func (f *Flow) SecureRedirectToOpts(ctx context.Context, cfg config.Provider) (opts []x.SecureRedirectOption)

func (*Flow) SetInternalContext added in v1.1.0

func (f *Flow) SetInternalContext(bytes sqlxx.JSONRawMessage)

func (*Flow) SetReturnTo

func (f *Flow) SetReturnTo()

func (*Flow) SetReturnToVerification added in v1.2.0

func (f *Flow) SetReturnToVerification(to string)

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 WithFlowOAuth2LoginChallenge added in v1.1.0

func WithFlowOAuth2LoginChallenge(loginChallenge string) FlowOption

func WithFlowReturnTo added in v0.11.0

func WithFlowReturnTo(returnTo string) FlowOption

type FlowPersistenceProvider

type FlowPersistenceProvider interface {
	RegistrationFlowPersister() FlowPersister
}

type FlowPersister

type FlowPersister interface {
	UpdateRegistrationFlow(context.Context, *Flow) error
	CreateRegistrationFlow(context.Context, *Flow) error
	GetRegistrationFlow(context.Context, uuid.UUID) (*Flow, error)
	DeleteExpiredRegistrationFlows(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) FromOldFlow

func (h *Handler) FromOldFlow(w http.ResponseWriter, r *http.Request, of Flow) (*Flow, error)

func (*Handler) NewRegistrationFlow

func (h *Handler) NewRegistrationFlow(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 {
	RegistrationHandler() *Handler
}

type HookExecutor

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

func NewHookExecutor

func NewHookExecutor(d executorDependencies) *HookExecutor

func (*HookExecutor) PostRegistrationHook

func (e *HookExecutor) PostRegistrationHook(w http.ResponseWriter, r *http.Request, ct identity.CredentialsType, provider string, registrationFlow *Flow, i *identity.Identity) (err error)

func (*HookExecutor) PreRegistrationHook

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

type HookExecutorProvider

type HookExecutorProvider interface {
	RegistrationExecutor() *HookExecutor
}

type HooksProvider

type HooksProvider interface {
	PreRegistrationHooks(ctx context.Context) []PreHookExecutor
	PostRegistrationPrePersistHooks(ctx context.Context, credentialsType identity.CredentialsType) []PostHookPrePersistExecutor
	PostRegistrationPostPersistHooks(ctx context.Context, credentialsType identity.CredentialsType) []PostHookPostPersistExecutor
}

type PostHookPostPersistExecutor

type PostHookPostPersistExecutor interface {
	ExecutePostRegistrationPostPersistHook(w http.ResponseWriter, r *http.Request, a *Flow, s *session.Session) error
}

type PostHookPostPersistExecutorFunc

type PostHookPostPersistExecutorFunc func(w http.ResponseWriter, r *http.Request, a *Flow, s *session.Session) error

func (PostHookPostPersistExecutorFunc) ExecutePostRegistrationPostPersistHook

func (f PostHookPostPersistExecutorFunc) ExecutePostRegistrationPostPersistHook(w http.ResponseWriter, r *http.Request, a *Flow, s *session.Session) error

type PostHookPrePersistExecutor

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

type PostHookPrePersistExecutorFunc

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

func (PostHookPrePersistExecutorFunc) ExecutePostRegistrationPrePersistHook

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

type PreHookExecutor

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

type PreHookExecutorFunc

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

func (PreHookExecutorFunc) ExecuteRegistrationPreHook

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

type State added in v1.1.0

type State = flow.State

State represents the state of this request:

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

swagger:model registrationFlowState

type Strategies

type Strategies []Strategy

func (Strategies) MustStrategy

func (s Strategies) MustStrategy(id identity.CredentialsType) Strategy

func (Strategies) RegisterPublicRoutes

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

func (Strategies) Strategy

func (s Strategies) Strategy(id identity.CredentialsType) (Strategy, error)

type Strategy

type Strategy interface {
	ID() identity.CredentialsType
	NodeGroup() node.UiNodeGroup
	RegisterRegistrationRoutes(*x.RouterPublic)
	PopulateRegistrationMethod(r *http.Request, sr *Flow) error
	Register(w http.ResponseWriter, r *http.Request, f *Flow, i *identity.Identity) (err error)
}

type StrategyFilter added in v1.1.0

type StrategyFilter func(strategy Strategy) bool

type StrategyProvider

type StrategyProvider interface {
	RegistrationStrategies(ctx context.Context, filters ...StrategyFilter) Strategies
	AllRegistrationStrategies() Strategies
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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