auth

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(authSvc Service) func(http.Handler) http.Handler

AuthMiddleware creates middleware that validates session tokens.

func ContextWithUser

func ContextWithUser(ctx context.Context, user *store.User) context.Context

ContextWithUser adds a user to the context.

func OptionalAuthMiddleware

func OptionalAuthMiddleware(authSvc Service) func(http.Handler) http.Handler

OptionalAuthMiddleware creates middleware that validates session tokens but allows unauthenticated requests.

func RequireAdmin

func RequireAdmin() func(http.Handler) http.Handler

RequireAdmin creates middleware that requires admin role.

func RequireRole

func RequireRole(role store.Role) func(http.Handler) http.Handler

RequireRole creates middleware that requires a specific role.

func UserFromContext

func UserFromContext(ctx context.Context) *store.User

UserFromContext retrieves the authenticated user from the context.

Types

type GitHubUser

type GitHubUser struct {
	ID    string
	Login string
}

GitHubUser represents a GitHub user profile.

type Service

type Service interface {
	Start(ctx context.Context) error
	Stop() error

	// Authentication.
	AuthenticateBasic(ctx context.Context, username, password string) (*store.User, string, error)
	AuthenticateGitHub(ctx context.Context, code string) (*store.User, string, error)
	ValidateSession(ctx context.Context, token string) (*store.User, error)
	Logout(ctx context.Context, token string) error

	// Authorization.
	HasRole(user *store.User, role store.Role) bool
	IsAdmin(user *store.User) bool

	// GitHub OAuth URL.
	GetGitHubAuthURL(state string) string

	// OAuth State (CSRF protection).
	CreateOAuthState(ctx context.Context) (string, error)
	ValidateOAuthState(ctx context.Context, state string) error

	// Auth Code (one-time exchange).
	CreateAuthCode(ctx context.Context, userID string) (string, error)
	ExchangeAuthCode(ctx context.Context, code string) (*store.User, string, error)
}

Service defines the interface for authentication operations.

func NewService

func NewService(log logrus.FieldLogger, cfg *config.Config, st store.Store) Service

NewService creates a new auth service.

Jump to

Keyboard shortcuts

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