Documentation
¶
Index ¶
- func AuthMiddleware(authSvc Service) func(http.Handler) http.Handler
- func ContextWithUser(ctx context.Context, user *store.User) context.Context
- func OptionalAuthMiddleware(authSvc Service) func(http.Handler) http.Handler
- func RequireAdmin() func(http.Handler) http.Handler
- func RequireRole(role store.Role) func(http.Handler) http.Handler
- func UserFromContext(ctx context.Context) *store.User
- type GitHubUser
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthMiddleware ¶
AuthMiddleware creates middleware that validates session tokens.
func ContextWithUser ¶
ContextWithUser adds a user to the context.
func OptionalAuthMiddleware ¶
OptionalAuthMiddleware creates middleware that validates session tokens but allows unauthenticated requests.
func RequireAdmin ¶
RequireAdmin creates middleware that requires admin role.
func RequireRole ¶
RequireRole creates middleware that requires a specific role.
Types ¶
type GitHubUser ¶
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 ¶
NewService creates a new auth service.
Click to show internal directories.
Click to hide internal directories.