security

package
v4.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdminAuthentificator

func AdminAuthentificator(next http.Handler) http.Handler

AdminAuthentificator is a middle which check if the user is administrator (role=1)

func RandString

func RandString(length int) string

RandString generate a random string with the default charset ([A-Za-z])

func RandStringWithCharset

func RandStringWithCharset(length int, charset string) string

RandStringWithCharset generate a random string with a specific charset

Types

type Auth

type Auth interface {
	Authenticate(string, string) (users.User, bool, error)
}

Auth refers to a generic interface which must be implemented by every authentication backend

type DatabaseAuth

type DatabaseAuth struct {
	DBClient *sqlx.DB
}

DatabaseAuth is a basic Auth implementation requiring the tuple admin/admin to authenticate successfully

func NewDatabaseAuth

func NewDatabaseAuth(DBClient *sqlx.DB) *DatabaseAuth

NewDatabaseAuth returns a pointer of DatabaseAuth

func (*DatabaseAuth) Authenticate

func (auth *DatabaseAuth) Authenticate(login string, password string) (users.User, bool, error)

Get search and returns an User from the repository by its id

type JwtToken

type JwtToken struct {
	Token string `json:"token"`
}

JwtToken wrap the json web token string

type Middleware

type Middleware interface {
	Handler(h http.Handler) http.Handler
}

Middleware is an interface for standard http middleware

type MiddlewareJWT

type MiddlewareJWT struct {
	Auth    Auth
	Handler func(h http.Handler) http.Handler
	// contains filtered or unexported fields
}

MiddlewareJWT is an implementation of Middleware interface, which provides a specific security handler based on JWT (JSON Web Token)

func NewMiddlewareJWT

func NewMiddlewareJWT(jwtSigningKey []byte, auth Auth) *MiddlewareJWT

NewMiddlewareJWT initialize a new instance of MiddlewareJWT and returns a pointer of it

func (*MiddlewareJWT) GetToken

func (middleware *MiddlewareJWT) GetToken() http.HandlerFunc

GetToken returns a http.Handler to authenticate and get a JWT

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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