Documentation
¶
Index ¶
- Variables
- type Config
- type LocalUserConfig
- type LocalUserInfo
- type LoginResult
- type Manager
- func (m *Manager) Close()
- func (m *Manager) CreateLocalUser(username, password string, role Role) error
- func (m *Manager) CreateSession(user *User, r *http.Request) (*Session, error)
- func (m *Manager) GetActiveSessions() []*Session
- func (m *Manager) GetConfig() *Config
- func (m *Manager) GetSession(sessionID string) (*Session, error)
- func (m *Manager) GetSessionFromContext(ctx context.Context) *Session
- func (m *Manager) GetSessionFromRequest(r *http.Request) (*Session, error)
- func (m *Manager) GetUserFromContext(ctx context.Context) *User
- func (m *Manager) GetUserSessions(userID string) []*Session
- func (m *Manager) HandleOAuthCallback(w http.ResponseWriter, r *http.Request)
- func (m *Manager) Handler() http.Handler
- func (m *Manager) InitOAuthFlow(w http.ResponseWriter, r *http.Request)
- func (m *Manager) InvalidateSession(sessionID string) error
- func (m *Manager) InvalidateUserSessions(userID string)
- func (m *Manager) ListLocalUsers() []LocalUserInfo
- func (m *Manager) LocalLogin(w http.ResponseWriter, r *http.Request)
- func (m *Manager) Logout(w http.ResponseWriter, r *http.Request) error
- func (m *Manager) OptionalAuth(next http.Handler) http.Handler
- func (m *Manager) RefreshSession(sessionID string) error
- func (m *Manager) RequireAdmin(next http.Handler) http.Handler
- func (m *Manager) RequireAuth(next http.Handler) http.Handler
- func (m *Manager) RequirePermission(permission Permission) func(http.Handler) http.Handler
- func (m *Manager) RequireRole(role Role) func(http.Handler) http.Handler
- type OAuthEndpoints
- type OAuthTokenResponse
- type OAuthUserInfo
- type Permission
- type Provider
- type Role
- type Session
- type User
Constants ¶
This section is empty.
Variables ¶
var OAuthProviderEndpoints = map[Provider]OAuthEndpoints{ ProviderGoogle: { AuthURL: "https://accounts.google.com/o/oauth2/v2/auth", TokenURL: "https://oauth2.googleapis.com/token", UserInfoURL: "https://openidconnect.googleapis.com/v1/userinfo", Scopes: []string{"openid", "profile", "email"}, }, ProviderMicrosoft: { AuthURL: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize", TokenURL: "https://login.microsoftonline.com/common/oauth2/v2.0/token", UserInfoURL: "https://graph.microsoft.com/v1.0/me", Scopes: []string{"openid", "profile", "email", "User.Read"}, }, ProviderGitHub: { AuthURL: "https://github.com/login/oauth/authorize", TokenURL: "https://github.com/login/oauth/access_token", UserInfoURL: "https://api.github.com/user", Scopes: []string{"read:user", "user:email"}, }, ProviderOkta: { Scopes: []string{"openid", "profile", "email"}, }, ProviderAuth0: { Scopes: []string{"openid", "profile", "email"}, }, }
OAuthProviderEndpoints maps provider names to their OAuth endpoints.
var RolePermissions = map[Role][]Permission{ RoleAdmin: { PermViewDashboard, PermManagePolicies, PermManageCerts, PermViewLogs, PermManageUsers, PermViewReports, PermSystemConfig, PermViewAlerts, }, RoleOperator: { PermViewDashboard, PermManagePolicies, PermViewLogs, PermViewReports, PermViewAlerts, }, RoleViewer: { PermViewDashboard, PermViewReports, PermViewAlerts, }, RoleService: { PermViewDashboard, PermViewReports, }, }
RolePermissions maps roles to permissions.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Provider Provider
ClientID string
ClientSecret string
RedirectURL string
AuthURL string
TokenURL string
UserInfoURL string
Scopes []string
SAMLMetadataURL string
SAMLIssuer string
SAMLCertPath string
SessionDuration time.Duration
CookieName string
CookieSecure bool
CookieHTTPOnly bool
CookieSameSite http.SameSite
RequireHTTPS bool
MaxSessions int
EnableMFA bool
AllowedDomains []string
BlockedDomains []string
LocalUsers map[string]LocalUserConfig
}
Config holds authentication configuration
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns default authentication configuration
type LocalUserConfig ¶
LocalUserConfig holds local user credentials
type LocalUserInfo ¶
LocalUserInfo holds public user information
type LoginResult ¶
type LoginResult struct {
Success bool `json:"success"`
Token string `json:"token"`
Error string `json:"error"`
ExpiresAt time.Time `json:"expires_at"`
}
LoginResult represents the result of a login attempt
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles authentication and session management
func NewManager ¶
NewManager creates a new authentication manager
func (*Manager) CreateLocalUser ¶
CreateLocalUser creates a new local user
func (*Manager) CreateSession ¶
CreateSession creates a new authenticated session
func (*Manager) GetActiveSessions ¶
GetActiveSessions returns all active sessions
func (*Manager) GetSession ¶
GetSession retrieves a session by ID
func (*Manager) GetSessionFromContext ¶
GetSessionFromContext retrieves session from request context
func (*Manager) GetSessionFromRequest ¶
GetSessionFromRequest extracts session from HTTP request cookie
func (*Manager) GetUserFromContext ¶
GetUserFromContext retrieves user from request context
func (*Manager) GetUserSessions ¶
GetUserSessions returns all sessions for a user
func (*Manager) HandleOAuthCallback ¶
func (m *Manager) HandleOAuthCallback(w http.ResponseWriter, r *http.Request)
HandleOAuthCallback processes the OAuth callback response.
func (*Manager) InitOAuthFlow ¶
func (m *Manager) InitOAuthFlow(w http.ResponseWriter, r *http.Request)
InitOAuthFlow initiates the OAuth authentication flow. InitOAuthFlow initiates OAuth authentication flow for the given provider.
func (*Manager) InvalidateSession ¶
InvalidateSession marks a session as inactive
func (*Manager) InvalidateUserSessions ¶
InvalidateUserSessions invalidates all sessions for a user
func (*Manager) ListLocalUsers ¶
func (m *Manager) ListLocalUsers() []LocalUserInfo
ListLocalUsers returns all local users
func (*Manager) LocalLogin ¶
func (m *Manager) LocalLogin(w http.ResponseWriter, r *http.Request)
LocalLogin handles local username/password authentication
func (*Manager) OptionalAuth ¶
OptionalAuth middleware adds user to context if authenticated, but doesn't require it
func (*Manager) RefreshSession ¶
RefreshSession extends session expiration
func (*Manager) RequireAdmin ¶
RequireAdmin middleware ensures user is an admin
func (*Manager) RequireAuth ¶
RequireAuth middleware ensures user is authenticated
func (*Manager) RequirePermission ¶
RequirePermission middleware checks if user has specific permission
type OAuthEndpoints ¶
OAuthEndpoints holds OAuth provider endpoint URLs. OAuthEndpoints defines OAuth provider endpoint URLs.
type OAuthTokenResponse ¶
type OAuthTokenResponse struct {
AccessToken string
TokenType string
ExpiresIn int
RefreshToken string
IDToken string
Scope string
}
OAuthTokenResponse contains OAuth token response data. OAuthTokenResponse contains the OAuth token response from the provider.
type OAuthUserInfo ¶
type OAuthUserInfo struct {
ID string
Email string
Name string
GivenName string
FamilyName string
Picture string
VerifiedEmail bool
Provider string
}
OAuthUserInfo contains user information from OAuth provider. OAuthUserInfo represents user information returned by OAuth provider.
type Permission ¶
type Permission string
Permission represents a specific authorization permission
const ( // PermViewDashboard is the permission to view the dashboard. PermViewDashboard Permission = "view:dashboard" PermManagePolicies Permission = "manage:policies" PermManageCerts Permission = "manage:certificates" PermViewLogs Permission = "view:logs" PermManageUsers Permission = "manage:users" PermViewReports Permission = "view:reports" PermSystemConfig Permission = "system:config" PermViewAlerts Permission = "view:alerts" )
type Provider ¶
type Provider string
Provider represents an authentication provider type
const ( // ProviderGoogle identifies the Google OAuth provider. ProviderGoogle Provider = "google" // ProviderMicrosoft identifies the Microsoft OAuth provider. ProviderMicrosoft Provider = "microsoft" ProviderGitHub Provider = "github" ProviderOkta Provider = "okta" ProviderAuth0 Provider = "auth0" ProviderGeneric Provider = "generic_oauth" ProviderSAMLGeneric Provider = "saml" ProviderSAMLAzure Provider = "saml_azure" ProviderSALMOkta Provider = "saml_okta" ProviderLocal Provider = "local" )
type Session ¶
type Session struct {
ID string
UserID string
User *User
CreatedAt time.Time
ExpiresAt time.Time
LastActivity time.Time
IPAddress string
UserAgent string
Active bool
}
Session represents an authenticated session
func (*Session) IsExpired ¶
IsExpired checks if the session has expired. IsExpired checks if the session has expired.
type User ¶
type User struct {
ID string
Email string
Name string
Provider Provider
ProviderID string
Role Role
Permissions []Permission
Attributes map[string]interface{}
SessionID string
Authenticated bool
LastLogin time.Time
CreatedAt time.Time
}
User represents an authenticated user
func (*User) HasPermission ¶
func (u *User) HasPermission(perm Permission) bool
HasPermission checks if the user has a specific permission. HasPermission checks if the user has a specific permission.