auth

package
v0.0.0-...-2a11bd6 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package auth is a service for authenticating http requets

Index

Constants

This section is empty.

Variables

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

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, j TokenGenerator, sec Securer, rbac RBAC) *Auth

Initialize initializes auth application service

func New

func New(db *gorm.DB, udb UserDBClientInterface, j TokenGenerator, sec Securer, rbac RBAC) *Auth

New creates new iam service

func (*Auth) Authenticate

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

Authenticate tries to authenticate the user provided by username and password

func (*Auth) Me

func (a *Auth) Me(c echo.Context) (*models.User, error)

Me returns info about currently logged user

func (*Auth) Refresh

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

Refresh refreshes jwt token and puts new claims inside

type RBAC

type RBAC interface {
	User(echo.Context) *models.AuthUser
}

RBAC represents role-based-access-control interface

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) (*models.AuthToken, error)
	Refresh(echo.Context, string) (*models.RefreshToken, error)
	Me(echo.Context) (*models.User, error)
}

Service represents auth service interface

type TokenGenerator

type TokenGenerator interface {
	GenerateToken(*models.User) (string, string, error)
}

TokenGenerator represents token generator (jwt) interface

type UserDBClientInterface

type UserDBClientInterface interface {
	View(*gorm.DB, uint) (*models.User, error)
	FindByUsername(*gorm.DB, string) (*models.User, error)
	FindByToken(*gorm.DB, string) (*models.User, error)
	Update(*gorm.DB, *models.User) error
}

UserDBClientInterface represents user repository interface

Directories

Path Synopsis
Package transport contians HTTP service for authentication
Package transport contians HTTP service for authentication

Jump to

Keyboard shortcuts

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