auth

package
v0.0.0-...-dc49242 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Sessions *SessionManager
	// contains filtered or unexported fields
}

func NewApp

func NewApp(cfg *conf.Config, db db.DB) *App

NewApp returns a new authz/n web application.

func (*App) Bind

func (a *App) Bind(r chi.Router)

Bind this app to endpoints in the router.

func (*App) GetAdmin

func (a *App) GetAdmin() (app.Admin, error)

GetAdmin returns nil

func (*App) Migrate

func (a *App) Migrate() error

Migrate runs db migrations for the Auth application.

func (*App) Name

func (a *App) Name() string

func (*App) Register

func (a *App) Register(r *mtr.Registry)

type SessionManager

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

A SessionManager manages sessions

func NewSessionManager

func NewSessionManager(cfg *conf.Config) *SessionManager

func SessionFromContext

func SessionFromContext(ctx context.Context) *SessionManager

SessionFromContext returns the session manager from the context

func (*SessionManager) AddSessionMiddleware

func (s *SessionManager) AddSessionMiddleware(next http.Handler) http.Handler

Middleware adds this manager to the context, allowing any handler to utilize it

func (*SessionManager) Context

func (s *SessionManager) Context(ctx context.Context) context.Context

Context adds this session manager to ctx

func (*SessionManager) IsAuthenticated

func (s *SessionManager) IsAuthenticated(r *http.Request) bool

func (*SessionManager) RequireAuthenticated

func (s *SessionManager) RequireAuthenticated(next http.Handler) http.Handler

func (*SessionManager) RequireAuthenticatedRedirect

func (s *SessionManager) RequireAuthenticatedRedirect(url string) func(http.Handler) http.Handler

func (*SessionManager) Session

func (s *SessionManager) Session(r *http.Request) *sessions.Session

Session returns the session for this request

type User

type User struct {
	ID           uint64
	Username     string
	PasswordHash string `db:"password_hash"`
}

type UserService

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

func NewUserService

func NewUserService(conn db.DB) *UserService

func (*UserService) ChangePassword

func (s *UserService) ChangePassword(username, currentPassword, newPassword string) (ok bool, err error)

ChangePassword changes the user's password to newPassword, providing that the current password is correct.

func (*UserService) CreateUser

func (s *UserService) CreateUser(username, password string) error

CreateUser attempts to create a new user with the username and password. If a user with that username already exists, an error is returned.

func (*UserService) Validate

func (s *UserService) Validate(username, password string) (ok bool, err error)

Validate that the username and password match one in the database. If an error occurs, ok will be false.

Jump to

Keyboard shortcuts

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