authentication

package module
v0.0.0-...-22c6e00 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2020 License: Apache-2.0 Imports: 23 Imported by: 0

README

Neuron HTTP Server - Authentication Module

This repository contains Neuron extension for the HTTP Server, that provides authentication module.

Documentation

Index

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 New

func New(options ...Option) (*API, error)

New creates account API.

func (*API) GetEndpoints

func (a *API) GetEndpoints() []*server.Endpoint

GetEndpoints implements server.EndpointsGetter.

func (*API) InitializeAPI

func (a *API) InitializeAPI(c *core.Controller) error

InitializeAPI implements server/http.API interface.

func (*API) SetRoutes

func (a *API) SetRoutes(router *httprouter.Router) error

SetRoutes implements http server 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

func WithAccountModel(account auth.Account) Option

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

func WithPathPrefix(pathPrefix string) Option

WithPathPrefix is an option that sets path prefix for the API.

func WithPermitRefreshTokenLogout

func WithPermitRefreshTokenLogout(permit bool) Option

WithPermitRefreshTokenLogout sets the option that allows to logout using also refresh token.

func WithRefreshTokenExpiration

func WithRefreshTokenExpiration(d time.Duration) Option

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

func WithRememberMeTokenExpiration(d time.Duration) Option

WithRememberMeTokenExpiration sets the 'RememberTokenExpiration' option for the auth service.

func WithStrictUnmarshal

func WithStrictUnmarshal(setting bool) Option

WithStrictUnmarshal is an option that sets the 'StrictUnmarshal' setting.

func WithTokenExpiration

func WithTokenExpiration(d time.Duration) Option

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

type WithTransactionLoginer interface {
	LoginWithTransaction() *query.TxOptions
}

WithTransactionLoginer is an interface that begins the transaction on the login process.

Jump to

Keyboard shortcuts

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