Documentation
¶
Overview ¶
Package admin provides cross-cutting administrative operations for the AuthSome platform.
This service handles platform-level operations that span multiple core services:
- User lifecycle management (create, list, delete users)
- Security operations (ban, unban, impersonate users)
- Session oversight (list and revoke sessions across all users)
- Platform statistics (aggregated metrics)
- Centralized audit log access
Plugin-specific administrative operations should be implemented in the respective plugins. See docs/PLUGIN_ADMIN_ENDPOINTS.md for guidelines on adding plugin admin endpoints.
Architecture Decision: Based on decisions 1b, 2a, 3a:
- This service handles cross-cutting operations only
- Individual plugins expose their own admin endpoints for plugin-specific features
- Impersonation remains centralized here (security-sensitive)
Index ¶
- Constants
- type BanUserRequest
- type BanUserRequestDTO
- type Config
- type CreateUserRequest
- type CreateUserRequestDTO
- type DeleteUserRequestDTO
- type ErrorResponse
- type GetAuditLogsRequestDTO
- type GetStatsRequestDTO
- type Handler
- func (h *Handler) BanUser(c forge.Context) error
- func (h *Handler) CreateUser(c forge.Context) error
- func (h *Handler) DeleteUser(c forge.Context) error
- func (h *Handler) GetAuditLogs(c forge.Context) error
- func (h *Handler) GetStats(c forge.Context) error
- func (h *Handler) ImpersonateUser(c forge.Context) error
- func (h *Handler) ListSessions(c forge.Context) error
- func (h *Handler) ListUsers(c forge.Context) error
- func (h *Handler) RevokeSession(c forge.Context) error
- func (h *Handler) SetUserRole(c forge.Context) error
- func (h *Handler) UnbanUser(c forge.Context) error
- type ImpersonateUserRequest
- type ImpersonateUserRequestDTO
- type ListSessionsRequest
- type ListSessionsRequestDTO
- type ListSessionsResponse
- type ListUsersRequest
- type ListUsersRequestDTO
- type ListUsersResponse
- type MessageResponse
- type Plugin
- func (p *Plugin) Description() string
- func (p *Plugin) ID() string
- func (p *Plugin) Init(auth interface{}) error
- func (p *Plugin) Migrate() error
- func (p *Plugin) Name() string
- func (p *Plugin) RegisterHooks(registry interface{}) error
- func (p *Plugin) RegisterRoles(registry interface{}) error
- func (p *Plugin) RegisterRoutes(router forge.Router) error
- func (p *Plugin) RegisterServiceDecorators(registry interface{}) error
- func (p *Plugin) Version() string
- type RevokeSessionRequestDTO
- type Service
- func (s *Service) BanUser(ctx context.Context, req *BanUserRequest) error
- func (s *Service) CreateUser(ctx context.Context, req *CreateUserRequest) (*user.User, error)
- func (s *Service) DeleteUser(ctx context.Context, userID, adminID xid.ID) error
- func (s *Service) ImpersonateUser(ctx context.Context, req *ImpersonateUserRequest) (*session.Session, error)
- func (s *Service) ListSessions(ctx context.Context, req *ListSessionsRequest) (*ListSessionsResponse, error)
- func (s *Service) ListUsers(ctx context.Context, req *ListUsersRequest) (*ListUsersResponse, error)
- func (s *Service) RevokeSession(ctx context.Context, sessionID, adminID xid.ID) error
- func (s *Service) SetUserRole(ctx context.Context, req *SetUserRoleRequest) error
- func (s *Service) UnbanUser(ctx context.Context, req *UnbanUserRequest) error
- type SetUserRoleRequest
- type SetUserRoleRequestDTO
- type StatsResponse
- type UnbanUserRequest
- type UnbanUserRequestDTO
Constants ¶
const ( PermUserCreate = "admin:user:create" PermUserRead = "admin:user:read" PermUserUpdate = "admin:user:update" PermUserDelete = "admin:user:delete" PermUserBan = "admin:user:ban" PermUserImpersonate = "admin:user:impersonate" PermSessionRead = "admin:session:read" PermSessionRevoke = "admin:session:revoke" PermRoleAssign = "admin:role:assign" PermStatsRead = "admin:stats:read" PermAuditRead = "admin:audit:read" )
Admin Permissions These permission strings are registered with the RBAC system during plugin initialization
const ( PluginID = "admin" PluginName = "Admin" PluginVersion = "1.0.0" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BanUserRequest ¶
type BanUserRequest struct {
AppID xid.ID `json:"app_id"` // Platform app (required)
UserOrganizationID *xid.ID `json:"user_organization_id,omitempty"` // User-created org (optional)
UserID xid.ID `json:"user_id"`
Reason string `json:"reason"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
AdminID xid.ID `json:"-"` // Set by handler
}
BanUserRequest represents a request to ban a user Updated for V2 architecture
type BanUserRequestDTO ¶ added in v0.0.7
type Config ¶
type Config struct {
// RequiredRole is the role required to access admin endpoints
RequiredRole string `json:"required_role"`
// AllowUserCreation allows admins to create users
AllowUserCreation bool `json:"allow_user_creation"`
// AllowUserDeletion allows admins to delete users
AllowUserDeletion bool `json:"allow_user_deletion"`
// AllowImpersonation allows admins to impersonate users
AllowImpersonation bool `json:"allow_impersonation"`
// MaxImpersonationDuration is the maximum duration for impersonation sessions
MaxImpersonationDuration time.Duration `json:"max_impersonation_duration"`
}
Config holds the admin plugin configuration
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default admin plugin configuration
type CreateUserRequest ¶
type CreateUserRequest struct {
AppID xid.ID `json:"app_id"` // Platform app (required)
UserOrganizationID *xid.ID `json:"user_organization_id,omitempty"` // User-created org (optional)
Email string `json:"email"`
Password string `json:"password,omitempty"`
Name string `json:"name,omitempty"`
Username string `json:"username,omitempty"`
Role string `json:"role,omitempty"`
EmailVerified bool `json:"email_verified"`
Metadata map[string]string `json:"metadata,omitempty"`
AdminID xid.ID `json:"-"` // Set by handler
}
CreateUserRequest represents a request to create a user Updated for V2 architecture: App → Environment → Organization
type CreateUserRequestDTO ¶ added in v0.0.7
type CreateUserRequestDTO struct {
Email string `json:"email" validate:"required,email"`
Password string `json:"password,omitempty"`
Name string `json:"name,omitempty"`
Username string `json:"username,omitempty"`
Role string `json:"role,omitempty"`
EmailVerified bool `json:"email_verified"`
Metadata map[string]string `json:"metadata,omitempty"`
}
Request types
type DeleteUserRequestDTO ¶ added in v0.0.7
type DeleteUserRequestDTO struct {
ID string `path:"id" validate:"required"`
}
type ErrorResponse ¶
type ErrorResponse = responses.ErrorResponse
Response types - use shared responses from core
type GetAuditLogsRequestDTO ¶ added in v0.0.7
type GetStatsRequestDTO ¶ added in v0.0.7
type GetStatsRequestDTO struct {
Period string `query:"period"`
}
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles admin HTTP requests Updated for V2 architecture: App → Environment → Organization
func (*Handler) CreateUser ¶
CreateUser handles POST /admin/users
func (*Handler) DeleteUser ¶
DeleteUser handles DELETE /admin/users/:id
func (*Handler) GetAuditLogs ¶
GetAuditLogs handles GET /admin/audit
func (*Handler) ImpersonateUser ¶
ImpersonateUser handles POST /admin/users/:id/impersonate
func (*Handler) ListSessions ¶
ListSessions handles GET /admin/sessions
func (*Handler) RevokeSession ¶
RevokeSession handles DELETE /admin/sessions/:id
func (*Handler) SetUserRole ¶
SetUserRole handles POST /admin/users/:id/role
type ImpersonateUserRequest ¶
type ImpersonateUserRequest struct {
AppID xid.ID `json:"app_id"` // Platform app (required)
UserOrganizationID *xid.ID `json:"user_organization_id,omitempty"` // User-created org (optional)
UserID xid.ID `json:"user_id"`
Duration time.Duration `json:"duration,omitempty"`
IPAddress string `json:"-"` // Set by handler
UserAgent string `json:"-"` // Set by handler
AdminID xid.ID `json:"-"` // Set by handler
}
ImpersonateUserRequest represents a request to impersonate a user Updated for V2 architecture
type ImpersonateUserRequestDTO ¶ added in v0.0.7
type ListSessionsRequest ¶
type ListSessionsRequest struct {
AppID xid.ID `json:"app_id"` // Platform app (required)
UserOrganizationID *xid.ID `json:"user_organization_id,omitempty"` // User-created org (optional)
UserID *xid.ID `json:"user_id,omitempty"`
Page int `json:"page"`
Limit int `json:"limit"`
AdminID xid.ID `json:"-"` // Set by handler
}
ListSessionsRequest represents a request to list sessions Updated for V2 architecture
type ListSessionsRequestDTO ¶ added in v0.0.7
type ListSessionsResponse ¶
type ListSessionsResponse struct {
Sessions []*session.Session `json:"sessions"`
Total int `json:"total"`
Page int `json:"page"`
Limit int `json:"limit"`
TotalPages int `json:"total_pages"`
}
ListSessionsResponse represents the response for listing sessions
type ListUsersRequest ¶
type ListUsersRequest struct {
AppID xid.ID `json:"app_id"` // Platform app (required)
UserOrganizationID *xid.ID `json:"user_organization_id,omitempty"` // User-created org (optional)
Page int `json:"page"`
Limit int `json:"limit"`
Search string `json:"search,omitempty"`
Role string `json:"role,omitempty"`
Status string `json:"status,omitempty"` // active, banned, inactive
AdminID xid.ID `json:"-"` // Set by handler
}
ListUsersRequest represents a request to list users Updated for V2 architecture
type ListUsersRequestDTO ¶ added in v0.0.7
type ListUsersResponse ¶
type ListUsersResponse struct {
Users []*user.User `json:"users"`
Total int `json:"total"`
Page int `json:"page"`
Limit int `json:"limit"`
TotalPages int `json:"total_pages"`
}
ListUsersResponse represents the response for listing users
type MessageResponse ¶
type MessageResponse = responses.MessageResponse
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin implements the AuthSome plugin interface for admin operations
func (*Plugin) Description ¶
Description returns the plugin description
func (*Plugin) RegisterHooks ¶
RegisterHooks implements the hooks registration (placeholder)
func (*Plugin) RegisterRoles ¶
RegisterRoles implements the PluginWithRoles optional interface This is called automatically during server initialization to register admin permissions
func (*Plugin) RegisterRoutes ¶
RegisterRoutes registers HTTP routes for the plugin
func (*Plugin) RegisterServiceDecorators ¶
RegisterServiceDecorators implements service decoration (not needed for admin)
type RevokeSessionRequestDTO ¶ added in v0.0.7
type RevokeSessionRequestDTO struct {
ID string `path:"id" validate:"required"`
}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides admin functionality for user management
func NewService ¶
func NewService( config Config, userService interface{}, sessionService interface{}, rbacService *rbac.Service, auditService interface{}, banService interface{}, ) *Service
NewService creates a new admin service
func (*Service) BanUser ¶
func (s *Service) BanUser(ctx context.Context, req *BanUserRequest) error
BanUser bans a user
func (*Service) CreateUser ¶
CreateUser creates a new user with admin privileges
func (*Service) DeleteUser ¶
DeleteUser deletes a user
func (*Service) ImpersonateUser ¶
func (s *Service) ImpersonateUser(ctx context.Context, req *ImpersonateUserRequest) (*session.Session, error)
ImpersonateUser creates a session for impersonating a user
func (*Service) ListSessions ¶
func (s *Service) ListSessions(ctx context.Context, req *ListSessionsRequest) (*ListSessionsResponse, error)
ListSessions lists all sessions with filtering and pagination
func (*Service) ListUsers ¶
func (s *Service) ListUsers(ctx context.Context, req *ListUsersRequest) (*ListUsersResponse, error)
ListUsers lists users with filtering and pagination
func (*Service) RevokeSession ¶
RevokeSession revokes a session
func (*Service) SetUserRole ¶
func (s *Service) SetUserRole(ctx context.Context, req *SetUserRoleRequest) error
SetUserRole sets a user's role
type SetUserRoleRequest ¶
type SetUserRoleRequest struct {
AppID xid.ID `json:"app_id"` // Platform app (required)
UserOrganizationID *xid.ID `json:"user_organization_id,omitempty"` // User-created org (optional)
UserID xid.ID `json:"user_id"`
Role string `json:"role"`
AdminID xid.ID `json:"-"` // Set by handler
}
SetUserRoleRequest represents a request to set a user's role Updated for V2 architecture
type SetUserRoleRequestDTO ¶ added in v0.0.7
type StatsResponse ¶
type UnbanUserRequest ¶
type UnbanUserRequest struct {
AppID xid.ID `json:"app_id"` // Platform app (required)
UserOrganizationID *xid.ID `json:"user_organization_id,omitempty"` // User-created org (optional)
UserID xid.ID `json:"user_id"`
Reason string `json:"reason,omitempty"`
AdminID xid.ID `json:"-"` // Set by handler
}
UnbanUserRequest represents a request to unban a user Updated for V2 architecture