Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AdminAuthentificator ¶
AdminAuthentificator is a middle which check if the user is administrator (role=1)
func RandString ¶
RandString generate a random string with the default charset ([A-Za-z])
func RandStringWithCharset ¶
RandStringWithCharset generate a random string with a specific charset
Types ¶
type Auth ¶
Auth refers to a generic interface which must be implemented by every authentication backend
type DatabaseAuth ¶
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 ¶
Authenticate check the input credentials and returns a User the passwords matches
type DevAuth ¶
type DevAuth struct{}
DevAuth is a basic Auth implementation requiring the tuple admin/admin to authenticate successfully
type JwtToken ¶
type JwtToken struct {
Token string `json:"token"`
}
JwtToken wrap the json web token string
type Middleware ¶
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
type NoAuth ¶
type NoAuth struct{}
NoAuth is a basic Auth implementation requiring the tuple admin/admin to authenticate successfully
type User ¶
type User struct { ID int64 `json:"id" db:"id"` Login string `json:"login" db:"login"` Role int64 `json:"role" db:"role"` LastName string `json:"lastName" db:"lastName"` FirstName string `json:"firstName" db:"firstName"` Email string `json:"email" db:"email"` Phone string `json:"phone" db:"phone"` Created time.Time `json:"created" db:"created"` }
User is used as the main user struct
type UserWithPassword ¶
UserWithPassword is used to log in the user (and only this use case) The standard User struct must be used if the password is not required
func (*UserWithPassword) IsValid ¶
func (user *UserWithPassword) IsValid() (bool, error)
IsValid checks if a user with password is valid and has no missing mandatory fields * User must be valid (see User struct) * Password must not be empty * Password must not be shorter than 6 characters