Documentation ¶
Index ¶
- type API
- type AccountCreateInput
- type AccountGetterHandler
- type AccountRegisterHandler
- type AfterAccountRegistrar
- type AfterFailedLoginer
- type AfterLoginer
- type BeforeAccountRegistrar
- type BeforeLoginer
- type CheckUsernameHandler
- type DefaultHandler
- func (d *DefaultHandler) HandleCheckUsername(ctx context.Context, db database.DB, account auth.Account) error
- func (d *DefaultHandler) HandleLoginAccountRefresh(ctx context.Context, db database.DB, options *LoginOptions) error
- func (d *DefaultHandler) HandleRegisterAccount(ctx context.Context, db database.DB, options *RegisterAccountOptions) error
- func (d *DefaultHandler) Initialize(c *core.Controller) error
- type LoginAccountRefresher
- type LoginInput
- type LoginOptions
- type LoginOutput
- type Option
- func WithAccountHandler(handler interface{}) Option
- func WithAccountModel(account auth.Account) Option
- func WithLoginMiddlewares(middlewares ...server.Middleware) Option
- func WithLogoutMiddlewares(middlewares ...server.Middleware) Option
- func WithMiddlewares(middlewares ...server.Middleware) Option
- func WithPasswordScorer(scorer auth.PasswordScorer) Option
- func WithPasswordValidator(validator auth.PasswordValidator) Option
- func WithPathPrefix(pathPrefix string) Option
- func WithPermitRefreshTokenLogout(permit bool) Option
- func WithRefreshTokenExpiration(d time.Duration) Option
- func WithRefreshTokenMiddlewares(middlewares ...server.Middleware) Option
- func WithRegisterMiddlewares(middlewares ...server.Middleware) Option
- func WithRememberMeTokenExpiration(d time.Duration) Option
- func WithStrictUnmarshal(setting bool) Option
- func WithTokenExpiration(d time.Duration) Option
- func WithUsernameValidator(validator auth.UsernameValidator) Option
- type Options
- type RegisterAccountMarshaler
- type RegisterAccountOptions
- type WithContextLoginer
- type WithTransactionLoginer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct { Options *Options Endpoints []*server.Endpoint DB database.DB Controller *core.Controller // contains filtered or unexported fields }
API is an API for the accounts operations.
func (*API) GetEndpoints ¶
GetEndpoints implements server.EndpointsGetter.
func (*API) InitializeAPI ¶
func (a *API) InitializeAPI(c *core.Controller) error
InitializeAPI implements server/http.API interface.
type AccountCreateInput ¶
type AccountCreateInput struct { Meta codec.Meta `json:"meta"` Username string `json:"username"` Password string `json:"password"` PasswordConfirmation string `json:"password_confirmation"` Attributes map[string]interface{} `json:"attributes"` }
AccountCreateInput is an input for the account creation.
type AccountGetterHandler ¶
type AccountGetterHandler interface {
HandleGetAccount(ctx context.Context, db database.DB, account auth.Account) error
}
AccountGetHandler is an interface that handles getting account.
type AccountRegisterHandler ¶
type AccountRegisterHandler interface {
HandleRegisterAccount(ctx context.Context, db database.DB, options *RegisterAccountOptions) error
}
AccountRegisterHandler is an interface that allows to handle account insertion in a custom way.
type AfterAccountRegistrar ¶
type AfterAccountRegistrar interface {
AfterRegisterAccount(ctx context.Context, db database.DB, options *RegisterAccountOptions) error
}
AfterAccountRegistrar is an interface used for handling hook after insertion of account. Within this hook, developer could set some functions that send emails, sets some additional models etc.
type AfterFailedLoginer ¶
type AfterFailedLoginer interface {
AfterFailedLogin(ctx context.Context, db database.DB, options *LoginOptions) error
}
AfterFailedLogin is an interface used to handle cases when the login fails.
type AfterLoginer ¶
type AfterLoginer interface {
AfterLogin(ctx context.Context, db database.DB, options *LoginOptions) error
}
AfterLoginer is the hook interface used after login process.
type BeforeAccountRegistrar ¶
type BeforeAccountRegistrar interface {
BeforeRegisterAccount(ctx context.Context, db database.DB, options *RegisterAccountOptions) error
}
BeforeAccountRegistrar is an interface used for handling hook before insertion of account.
type BeforeLoginer ¶
type BeforeLoginer interface {
BeforeLogin(ctx context.Context, db database.DB, options *LoginOptions) error
}
BeforeLoginer is the hook interface used before login process.
type CheckUsernameHandler ¶
type CheckUsernameHandler interface {
HandleCheckUsername(ctx context.Context, db database.DB, account auth.Account) error
}
CheckUsernameHandler is an interface that allows to check the username in a custom way.
type DefaultHandler ¶
type DefaultHandler struct { Account auth.Account Model *mapping.ModelStruct UsernameField *mapping.StructField PasswordField *mapping.StructField }
DefaultHandler is the default model handler for the accounts.
func (*DefaultHandler) HandleCheckUsername ¶
func (d *DefaultHandler) HandleCheckUsername(ctx context.Context, db database.DB, account auth.Account) error
HandleCheckUsername implements CheckUsernameHandler interface.
func (*DefaultHandler) HandleLoginAccountRefresh ¶
func (d *DefaultHandler) HandleLoginAccountRefresh(ctx context.Context, db database.DB, options *LoginOptions) error
HandleLoginAccountRefresh implements LoginAccountRefreshHandler.
func (*DefaultHandler) HandleRegisterAccount ¶
func (d *DefaultHandler) HandleRegisterAccount(ctx context.Context, db database.DB, options *RegisterAccountOptions) error
HandleRegisterAccount implements InsertAccountHandler interface.
func (*DefaultHandler) Initialize ¶
func (d *DefaultHandler) Initialize(c *core.Controller) error
Initialize implements core.Initializer.
type LoginAccountRefresher ¶
type LoginAccountRefresher interface {
HandleLoginAccountRefresh(ctx context.Context, db database.DB, options *LoginOptions) error
}
LoginAccountRefresher is an interface used for refreshing - getting the account in the login process. The function should not check the password. It should only check if account exists and get it's value.
type LoginInput ¶
type LoginInput struct { Username string `json:"username"` Password string `json:"password"` RememberToken bool `json:"remember_token"` }
LoginInput is the input login structure.
type LoginOptions ¶
type LoginOptions struct { Header http.Header Account auth.Account Password *auth.Password RememberToken bool }
LoginOptions are the options used while handling the login.
type LoginOutput ¶
type LoginOutput struct { Meta codec.Meta `json:"meta,omitempty"` AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token,omitempty"` TokenType string `json:"token_type,omitempty"` ExpiresIn int64 `json:"expires_in,omitempty"` }
LoginOutput is the successful login output structure.
type Option ¶
type Option func(o *Options)
func WithAccountHandler ¶
func WithAccountHandler(handler interface{}) Option
WithAccountHandler is an option that sets the account handler.
func WithAccountModel ¶
WithAccountModel is an option that sets the account model within options.
func WithLoginMiddlewares ¶
func WithLoginMiddlewares(middlewares ...server.Middleware) Option
WithLoginMiddlewares adds middlewares for all auth.API endpoints.
func WithLogoutMiddlewares ¶
func WithLogoutMiddlewares(middlewares ...server.Middleware) Option
WithLogoutMiddlewares adds middlewares for all auth.API endpoints.
func WithMiddlewares ¶
func WithMiddlewares(middlewares ...server.Middleware) Option
WithMiddlewares adds middlewares for all auth.API endpoints.
func WithPasswordScorer ¶
func WithPasswordScorer(scorer auth.PasswordScorer) Option
WithPasswordScorer sets the password scorer for the auth options.
func WithPasswordValidator ¶
func WithPasswordValidator(validator auth.PasswordValidator) Option
WithPasswordValidator sets the password validator function.
func WithPathPrefix ¶
WithPathPrefix is an option that sets path prefix for the API.
func WithPermitRefreshTokenLogout ¶
WithPermitRefreshTokenLogout sets the option that allows to logout using also refresh token.
func WithRefreshTokenExpiration ¶
WithRefreshTokenExpiration sets the 'RefreshTokenExpiration' option for the auth service.
func WithRefreshTokenMiddlewares ¶
func WithRefreshTokenMiddlewares(middlewares ...server.Middleware) Option
WithRefreshTokenMiddlewares adds middlewares for all auth.API endpoints.
func WithRegisterMiddlewares ¶
func WithRegisterMiddlewares(middlewares ...server.Middleware) Option
WithRegisterMiddlewares adds middlewares for all auth.API endpoints.
func WithRememberMeTokenExpiration ¶
WithRememberMeTokenExpiration sets the 'RememberTokenExpiration' option for the auth service.
func WithStrictUnmarshal ¶
WithStrictUnmarshal is an option that sets the 'StrictUnmarshal' setting.
func WithTokenExpiration ¶
WithTokenExpiration sets the 'TokenExpiration' option for the auth service.
func WithUsernameValidator ¶
func WithUsernameValidator(validator auth.UsernameValidator) Option
WithUsernameValidator sets the username validator function.
type Options ¶
type Options struct { AccountModel auth.Account AccountHandler interface{} PathPrefix string Middlewares []server.Middleware RegisterMiddlewares []server.Middleware LoginMiddlewares []server.Middleware LogoutMiddlewares []server.Middleware RefreshTokenMiddlewares []server.Middleware StrictUnmarshal bool PasswordValidator auth.PasswordValidator PasswordScorer auth.PasswordScorer UsernameValidator auth.UsernameValidator TokenExpiration time.Duration RememberTokenExpiration time.Duration RefreshTokenExpiration time.Duration PermitRefreshTokenLogout bool }
AuthenticatorOptions is the structure that contains auth API settings.
type RegisterAccountMarshaler ¶
type RegisterAccountMarshaler interface {
MarshalRegisteredAccount(ctx context.Context, options *RegisterAccountOptions) (*codec.Payload, error)
}
RegisterAccountMarshaler.
type RegisterAccountOptions ¶
type RegisterAccountOptions struct { Account auth.Account Password *auth.Password Meta codec.Meta Attributes map[string]interface{} }
RegisterAccountOptions are the options used for registering the account.
type WithContextLoginer ¶
type WithContextLoginer interface {
LoginWithContext(ctx context.Context) (context.Context, error)
}
WithContextLoginer is an interface that provides context to the login process.
type WithTransactionLoginer ¶
WithTransactionLoginer is an interface that begins the transaction on the login process.