auth

package
v0.0.0-...-9b07b7c Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCredentials = echo.NewHTTPError(http.StatusUnauthorized, "Username or password does not exist")
)

Custom errors

Functions

This section is empty.

Types

type Auth

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

Auth represents auth application service

func Initialize

func Initialize(db *gorm.DB, ce *casbin.Enforcer, j TokenGenerator, sec Securer) *Auth

Initialize initializes auth application service

func New

func New(db *gorm.DB, ce *casbin.Enforcer, udb UserDB, j TokenGenerator, sec Securer) *Auth

New creates new iam service

func (*Auth) Authenticate

func (a *Auth) Authenticate(c echo.Context, code, pass string) (*schemago.AuthToken, error)

Authenticate tries to authenticate the user provided by username and password

func (*Auth) Logout

func (a *Auth) Logout(c echo.Context, code string) error

Logout 清空权限

func (*Auth) Refresh

func (a *Auth) Refresh(c echo.Context, token string) (*schemago.RefreshToken, error)

Refresh refreshes jwt token and puts new claims inside

type Securer

type Securer interface {
	HashMatchesPassword(string, string) bool
	Token(string) string
}

Securer represents security interface

type Service

type Service interface {
	Authenticate(echo.Context, string, string) (*schemago.AuthToken, error)
	Refresh(echo.Context, string) (*schemago.RefreshToken, error)
	Logout(echo.Context, string) error
}

Service represents auth service interface

type TokenGenerator

type TokenGenerator interface {
	GenerateToken(*schemago.SUser) (string, string, error)
}

TokenGenerator represents token generator (jwt) interface

type UserDB

type UserDB interface {
	FindByCode(*gorm.DB, string) (*schemago.SUser, error)
	FindByToken(*gorm.DB, string) (*schemago.SUser, error)
	Update(*gorm.DB, *schemago.SUser) error
}

UserDB represents user repository interface

Directories

Path Synopsis
platform

Jump to

Keyboard shortcuts

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