auth

package
v0.0.0-...-6ecc318 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserIsLocked = errors.New("user was locked")
	ErrCompareToken = errors.New("can not compare token")
	ErrTokenInvalid = errors.New("the token is invalid")
)

Functions

func AuthMiddleware

func AuthMiddleware(h http.Handler) http.Handler

func GetRoleFromContext

func GetRoleFromContext(ctx context.Context) types.Role

func NewContextWithUser

func NewContextWithUser(ctx context.Context, u *types.UserInfo) context.Context

Types

type Claims

type Claims struct {
	Email string `validate:"required,email" json:"email"`
	Id    string
	Role  string
	jwt.StandardClaims
}

func VerifyToken

func VerifyToken(token string) (*Claims, error)

type Handler

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

func NewHandler

func NewHandler(srv service) *Handler

func (*Handler) Login

func (h *Handler) Login(w http.ResponseWriter, r *http.Request)

func (*Handler) Routes

func (h *Handler) Routes() []router.Route

type LoginRequest

type LoginRequest struct {
	Email    string `validate:"required,email" json:"email"`
	Password string `validate:"required" json:"password"`
}

type Service

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

func NewService

func NewService(userSvc UserService) *Service

func (*Service) Login

func (s *Service) Login(ctx context.Context, req LoginRequest) (string, error)

type UserService

type UserService interface {
	FindUserByEmail(ctx context.Context, email string) (*types.UserInfo, error)
}

Jump to

Keyboard shortcuts

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