login

package
v0.0.0-...-81cd3a7 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

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

	RouteGetFlow = "/self-service/login/flows"
)

Variables

View Source
var (
	ErrHookAbortFlow   = errors.New("aborted login hook execution")
	ErrAlreadyLoggedIn = herodot.ErrBadRequest.WithReason("A valid session was detected and thus login is not possible. Did you forget to set `?refresh=true`?")
)

Functions

func PostHookExecutorNames

func PostHookExecutorNames(e []PostHookExecutor) []string

func TestFlowPersister

func TestFlowPersister(p FlowPersister) func(t *testing.T)

Types

type APIFlowResponse

type APIFlowResponse struct {
	// The Session Token
	//
	// 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!
	//
	// required: true
	Token string `json:"session_token"`

	// The Session
	//
	// The session contains information about the user, the session device, and so on.
	// This is only available for API flows, not for Browser flows!
	//
	// required: true
	Session *session.Session `json:"session"`
}

The Response for Login Flows via API

swagger:model loginViaApiResponse

type ErrorHandler

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

func NewFlowErrorHandler

func NewFlowErrorHandler(d errorHandlerDependencies, c configuration.Provider) *ErrorHandler

func (*ErrorHandler) WriteFlowError

func (s *ErrorHandler) WriteFlowError(w http.ResponseWriter, r *http.Request, ct identity.CredentialsType, f *Flow, err error)

type ErrorHandlerProvider

type ErrorHandlerProvider interface{ LoginFlowErrorHandler() *ErrorHandler }

type Flow

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

	// Type represents the flow's type which can be either "api" or "browser", depending on the flow interaction.
	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 started.
	//
	// required: true
	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.
	//
	// required: true
	RequestURL string `json:"request_url" db:"request_url"`

	// The active login method
	//
	// If set contains the login method used. If the flow is new, it is unset.
	Active identity.CredentialsType `json:"active,omitempty" db:"active_method"`

	// Messages contains a list of messages to be displayed in the Login UI. Omitting these
	// messages makes it significantly harder for users to figure out what is going on.
	//
	// More documentation on messages can be found in the [User Interface Documentation](https://www.ory.sh/kratos/docs/concepts/ui-user-interface/).
	Messages text.Messages `json:"messages" db:"messages" faker:"-"`

	// List of login methods
	//
	// This is the list of available login methods with their required form fields, such as `identifier` and `password`
	// for the password login method. This will also contain error messages such as "password can not be empty".
	//
	// required: true
	Methods map[identity.CredentialsType]*FlowMethod `json:"methods" faker:"login_flow_methods" db:"-"`

	// MethodsRaw is a helper struct field for gobuffalo.pop.
	MethodsRaw FlowMethodsSlice `json:"-" faker:"-" has_many:"selfservice_login_flow_methods" fk_id:"selfservice_login_flow_id"`

	// CreatedAt is a helper struct field for gobuffalo.pop.
	CreatedAt time.Time `json:"-" db:"created_at"`

	// UpdatedAt is a helper struct field for gobuffalo.pop.
	UpdatedAt time.Time `json:"-" db:"updated_at"`

	// CSRFToken contains the anti-csrf token associated with this flow. Only set for browser flows.
	CSRFToken string `json:"-" db:"csrf_token"`

	// Forced stores whether this login flow should enforce re-authentication.
	Forced bool `json:"forced" db:"forced"`
}

Login Flow

This object represents a login flow. A login flow is initiated at the "Initiate Login API / Browser Flow" endpoint by a client.

Once a login flow is completed successfully, a session cookie or session token will be issued.

swagger:model loginFlow

func NewFlow

func NewFlow(exp time.Duration, csrf string, r *http.Request, flowType flow.Type) *Flow

func (*Flow) AfterCreate

func (f *Flow) AfterCreate(c *pop.Connection) error

func (*Flow) AfterFind

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

func (*Flow) AfterUpdate

func (f *Flow) AfterUpdate(c *pop.Connection) error

func (*Flow) AppendTo

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

func (*Flow) BeforeSave

func (f *Flow) BeforeSave(_ *pop.Connection) error

func (*Flow) GetID

func (f *Flow) GetID() uuid.UUID

func (*Flow) IsForced

func (f *Flow) IsForced() bool

func (Flow) TableName

func (f Flow) TableName() string

func (*Flow) Valid

func (f *Flow) Valid() error

type FlowExpiredError

type FlowExpiredError struct {
	*herodot.DefaultError
	// contains filtered or unexported fields
}

func NewFlowExpiredError

func NewFlowExpiredError(at time.Time) *FlowExpiredError

type FlowMethod

type FlowMethod struct {
	// Method contains the methods' credentials type.
	//
	// required: true
	Method identity.CredentialsType `json:"method" db:"method"`

	// Config is the credential type's config.
	//
	// required: true
	Config *FlowMethodConfig `json:"config" db:"config"`

	// ID is a helper struct field for gobuffalo.pop.
	ID uuid.UUID `json:"-" db:"id"`

	// FlowID is a helper struct field for gobuffalo.pop.
	FlowID uuid.UUID `json:"-" db:"selfservice_login_flow_id"`

	// Flow is a helper struct field for gobuffalo.pop.
	Flow *Flow `json:"-" belongs_to:"selfservice_login_flow" fk_id:"FlowID"`

	// CreatedAt is a helper struct field for gobuffalo.pop.
	CreatedAt time.Time `json:"-" db:"created_at"`

	// UpdatedAt is a helper struct field for gobuffalo.pop.
	UpdatedAt time.Time `json:"-" db:"updated_at"`
}

swagger:model loginFlowMethod

func (FlowMethod) TableName

func (u FlowMethod) TableName() string

type FlowMethodConfig

type FlowMethodConfig struct {
	// swagger:ignore
	FlowMethodConfigurator

	FlowMethodConfigMock
}

swagger:model loginFlowMethodConfig

func (*FlowMethodConfig) MarshalJSON

func (c *FlowMethodConfig) MarshalJSON() ([]byte, error)

func (*FlowMethodConfig) Scan

func (c *FlowMethodConfig) Scan(value interface{}) error

func (*FlowMethodConfig) UnmarshalJSON

func (c *FlowMethodConfig) UnmarshalJSON(data []byte) error

func (*FlowMethodConfig) Value

func (c *FlowMethodConfig) Value() (driver.Value, error)

type FlowMethodConfigMock

type FlowMethodConfigMock struct {
	*form.HTMLForm

	// Providers is set for the "oidc" flow method.
	Providers []form.Field `json:"providers"`
}

swagger:model loginFlowMethodConfigPayload

type FlowMethodConfigurator

swagger:ignore

type FlowMethods

type FlowMethods map[identity.CredentialsType]*FlowMethod

func (FlowMethods) TableName

func (u FlowMethods) TableName() string

type FlowMethodsSlice

type FlowMethodsSlice []FlowMethod // workaround for https://github.com/gobuffalo/pop/pull/478

func (FlowMethodsSlice) TableName

func (u FlowMethodsSlice) TableName() string

type FlowPersistenceProvider

type FlowPersistenceProvider interface {
	LoginFlowPersister() FlowPersister
}

type FlowPersister

type FlowPersister interface {
	UpdateLoginFlow(context.Context, *Flow) error
	CreateLoginFlow(context.Context, *Flow) error
	GetLoginFlow(context.Context, uuid.UUID) (*Flow, error)
	UpdateLoginFlowMethod(context.Context, uuid.UUID, identity.CredentialsType, *FlowMethod) error
	ForceLoginFlow(ctx context.Context, id uuid.UUID) error
}

type Handler

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

func NewHandler

func NewHandler(d handlerDependencies, c configuration.Provider) *Handler

func (*Handler) NewLoginFlow

func (h *Handler) NewLoginFlow(w http.ResponseWriter, r *http.Request, flow flow.Type) (*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 {
	LoginHandler() *Handler
}

type HookExecutor

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

func NewHookExecutor

func NewHookExecutor(d executorDependencies, c configuration.Provider) *HookExecutor

func (*HookExecutor) PostLoginHook

func (*HookExecutor) PreLoginHook

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

type HookExecutorProvider

type HookExecutorProvider interface {
	LoginHookExecutor() *HookExecutor
}

type HooksProvider

type HooksProvider interface {
	PreLoginHooks() []PreHookExecutor
	PostLoginHooks(credentialsType identity.CredentialsType) []PostHookExecutor
}

type PostHookExecutor

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

type PreHookExecutor

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

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
	RegisterLoginRoutes(*x.RouterPublic)
	PopulateLoginMethod(r *http.Request, sr *Flow) error
}

type StrategyProvider

type StrategyProvider interface {
	LoginStrategies() Strategies
}

Jump to

Keyboard shortcuts

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