auth

package
v0.0.0-...-b7e086b Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SitePermissionAdmin = "a" // You can do anything
)

Site-wide (aka some kind of superuser) permissions. Stored in auth_user.site_permissions

Variables

This section is empty.

Functions

func IsPasswordOK

func IsPasswordOK(password string) error

Types

type AuthServer

type AuthServer struct {
	// contains filtered or unexported fields
}

func NewAuthServer

func NewAuthServer(db *gorm.DB, log log.Log, sessionCookieName string) *AuthServer

func (*AuthServer) AllUsers

func (a *AuthServer) AllUsers() ([]model.AuthUser, error)

func (*AuthServer) AuthenticateRequest

func (a *AuthServer) AuthenticateRequest(w http.ResponseWriter, r *http.Request, allowTypes AuthType) *Credentials

If authorization fails, sends a response to 'w', and returns nil If authorization succeeds, returns a non-nil Credentials

func (*AuthServer) CreateKey

func (a *AuthServer) CreateKey(w http.ResponseWriter, r *http.Request, cred *Credentials)

func (*AuthServer) CreateUser

func (a *AuthServer) CreateUser(email, password, sitePermissions string) error

func (*AuthServer) EraseAllSessionsExceptCallingSession

func (a *AuthServer) EraseAllSessionsExceptCallingSession(cred *Credentials) error

Erase all sessions except the authentication mechanism that was used to issue this API request

func (*AuthServer) Login

func (a *AuthServer) Login(w http.ResponseWriter, r *http.Request)

func (*AuthServer) Logout

func (a *AuthServer) Logout(w http.ResponseWriter, r *http.Request)

func (*AuthServer) SetPassword

func (a *AuthServer) SetPassword(userID int64, password string) error

type AuthType

type AuthType int
const (
	AuthTypeSessionCookie AuthType = 1 << iota
	AuthTypeUsernamePassword
	AuthTypeApiKey
)

type Credentials

type Credentials struct {
	UserID                           int64
	SitePermissions                  string
	AuthenticatedViaSessionCookie    string // If session was authenticated via session cookie, this is pwdhash.HashSessionTokenBase64(cookie.Value) - aka the value in the DB
	AuthenticatedViaApiKey           string // If session was authenticated via api key, this is pwdhash.HashSessionTokenBase64(key) - aka the value in the DB
	AuthenticatedViaUsernamePassword bool   // If authenticated via username/password, this is true
}

func (*Credentials) IsAdmin

func (c *Credentials) IsAdmin() bool

func (*Credentials) PanicIfNotAdmin

func (c *Credentials) PanicIfNotAdmin()

Jump to

Keyboard shortcuts

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