middlewares

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthGen

type AuthGen interface {
	GetUserData(user string) (*UserData, bool)
	Authenticate(user string, token string) (string, error)
	GenerateToken(user string, pass string) (string, error)
}

AuthGen is an interface that generates token authenticates the same

type JWT

type JWT struct {
	Users map[string]UserData `yaml:"users"`
}

JWT contains the configuration for JWT tokens

func (*JWT) Authenticate

func (j *JWT) Authenticate(user string, token string) (string, error)

Authenticate authenticates the given token

func (*JWT) CheckUpdateNewCred

func (j *JWT) CheckUpdateNewCred() error

func (*JWT) GenerateToken

func (j *JWT) GenerateToken(user string, pass string) (string, error)

GenerateToken generates a new token for the given user

func (*JWT) GetUserData

func (j *JWT) GetUserData(user string) (*UserData, bool)

func (*JWT) SetNewCred

func (j *JWT) SetNewCred(user string) error

type JWTMiddleware

type JWTMiddleware struct {
	AuthGen AuthGen
}

JWTMiddleware is an AuthGen implementation that uses JWT tokens

func NewMiddleware

func NewMiddleware(a AuthGen) *JWTMiddleware

NewMiddleware creates a new JWTMiddleware

func (*JWTMiddleware) AuthHandler

func (m *JWTMiddleware) AuthHandler(next http.Handler) http.Handler

Handler is a middleware handler

func (*JWTMiddleware) LoginHandler

func (m *JWTMiddleware) LoginHandler(w http.ResponseWriter, r *http.Request)

Handler is a middleware handler

type Logging

type Logging struct {
	Logger *log.Logger
}

Logging is a logrus-enabled logging middleware

func (*Logging) Handler

func (l *Logging) Handler(h http.Handler) http.Handler

Handler wraps provided http.Handler with middleware

type ResponseStatusWriter

type ResponseStatusWriter interface {
	http.ResponseWriter
	Status() int
}

ResponseStatusWriter wraps http.ResponseWriter to save HTTP status code

type UserData

type UserData struct {
	Password   string    `yaml:"password"`
	Exp        uint64    `yaml:"jwt_exp"`
	Secret     string    `yaml:"secret"`
	OldCredExp string    `yaml:"old_cred_exp,omitempty"`
	NewData    *UserData `yaml:"new_data"`
}

Jump to

Keyboard shortcuts

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