auth

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

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

Go to latest
Published: Sep 30, 2021 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SessionCookieName is the name of the session cookie expected for authentication
	SessionCookieName = "jphotos_session"

	// ExpirationTime is the duration a session cookie is valid for once issued
	ExpirationTime = 7 * 24 * time.Hour // 1 week
)

Variables

View Source
var (
	ErrInvalidUsernameOrPassword = errors.New("Invalid username or password")
	ErrUnauthorized              = errors.New("Unauthorized")
)

Error types returned by functions in auth

Functions

func AddUser

func AddUser(username, password string, db db.Store) error

AddUser hashes the password and adds the new user to the database Returns an error if a user of the same name already exists or a DB error occurs.

func RemoveUser

func RemoveUser(username string, db db.Store) error

RemoveUser removes a user from the database.

Types

type Authorization

type Authorization struct {
	User db.User

	Role Role
	// contains filtered or unexported fields
}

An Authorization represents a users' current authorization and authentication level

func Get

func Get(r *http.Request, minimumRole Role, db db.Store) (*Authorization, error)

Get returns a user's Authorization based on a session and a minimum required Role. If the session is valid, extend it.

func (Authorization) Revoke

func (a Authorization) Revoke(db db.Store)

Revoke invalidates a session token in the database

type Role

type Role int

A Role represents a user's maximum permission level

const (
	RoleInvalid Role = iota
	RoleUser
	RoleSuperUser
)

Permissions work as follows: - Invalid: Deactivated or otherwise invalid users - User: Normal users - SuperUser: Has all server permissions

func (Role) String

func (r Role) String() string

type Token

type Token struct {
	Session string
	Expires time.Time
}

A Token holds a session token

func NewSession

func NewSession(username, password string, s db.Store) (*Token, error)

NewSession creates a new session and inserts it into the session table Possible errors: * ErrInvalidUsernameOrPassword * Errors from database access

Jump to

Keyboard shortcuts

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