auth

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

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

Go to latest
Published: Nov 27, 2021 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NotAuthorized means, Authorization Cookie not Found
	NotAuthorized = iota
	// CookieError reports trouble with the golang Request
	CookieError
	// AuthorizationExpired say Authorization Cookie is Ok, but Expired
	AuthorizationExpired
	// AuthorizationFound says that the Cookie is presend and needs to be validated
	AuthorizationFound
	// Authorized says that the User is Authorized via JWT Cookie
	Authorized
	// SignatureInvalid Error
	SignatureInvalid
	// AuthorizationFailed is a general Error in Authorizing a Request
	AuthorizationFailed
)

Variables

View Source
var ErrNoAuth = errors.New("Not Authorized")
View Source
var ErrPassword = errors.New("Password do not match")

ErrPassword indicates that the given Password does not match its master in the DB

View Source
var ErrRefresh = errors.New("refresh of Authorization failed")

ErrRefresh indicates that the Request Token handeling failed

Functions

func CleanExpiredRefresh

func CleanExpiredRefresh(ctx context.Context, hndl *db.Db) error

func CleanExpiredRegistrations

func CleanExpiredRegistrations(ctx context.Context, hndl *db.Db) error

func DoLogin

func DoLogin(lf *pages.LoginForm, db *db.Db, w http.ResponseWriter, r *http.Request) error

func DoRegister

func DoRegister(rf *pages.RegisterPage, mail *util.SmtpClient, db *db.Db, w http.ResponseWriter, r *http.Request) bool

DoRegister handles the Register Requests

func DoRegisterDone

func DoRegisterDone(db *db.Db, w http.ResponseWriter, r *http.Request) (*pages.PostRegisterPage, bool)

DoRegisterDone activates the User after registration

func FinishRegistration

func FinishRegistration(ctx context.Context, hndl *db.Db, token string) error

FinishRegistration finishes the Registration and activates the User

func GetEcdsaKey

func GetEcdsaKey(config *lutra.LutraConfig) *ecdsa.PrivateKey

func LoadEscdaKeyAsBin

func LoadEscdaKeyAsBin(config *lutra.LutraConfig) []byte

Types

type Credentials

type Credentials struct {
	Username string `json:"username"`
	Password string `json:"-", bson:"-"`

	jwt.StandardClaims
	// contains filtered or unexported fields
}

Credentials are decoded from the Token Cookie

func CheckRefresh

func CheckRefresh(w http.ResponseWriter, r *http.Request) (*Credentials, error)

ChecksRefresh updates auth and refresh token

func FindAuthorization

func FindAuthorization(ctx context.Context, r *http.Request) (*Credentials, int)

FindAuthorization tries to Authorize a http Request via Cookie

func (*Credentials) CheckPassword

func (c *Credentials) CheckPassword(pwText string) error

CheckPassword checks the user Password entered from Form

func (*Credentials) CheckUser

func (c *Credentials) CheckUser(ctx context.Context, hndl *db.Db) error

CheckUser Looks up if User is in DB

func (*Credentials) CreateRefreshToken

func (c *Credentials) CreateRefreshToken(ctx context.Context, w http.ResponseWriter, r *http.Request, hndl *db.Db) error

CreateRefreshToken creates a new Refresh Token on given claims

func (*Credentials) SetJWTCookie

func (c *Credentials) SetJWTCookie(w http.ResponseWriter, r *http.Request)

SetJWTCookie sets a JWT Cookie for valid trusted Credentials

type Env

type Env struct {
	User   string
	Config *lutra.LutraConfig
}
var Environment Env

type RefreshToken

type RefreshToken struct {
	SessionId string    `json:"session"`
	Token     string    `json:"token"`
	User      string    `json:"username"`
	Blocked   bool      `json:"blocked"`
	Started   time.Time `json:"started"`
}

RefreshToken is the dao Object for Sessions

Jump to

Keyboard shortcuts

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