auth

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPermissionDenied = errors.New("permission denied")
	ErrNoPermissions    = errors.New("no permissions found")
)
View Source
var GlobalPermissionChecker = NewPermissionChecker()

Global permission checker instance

Functions

func GetCurrentTenantID

func GetCurrentTenantID(ctx context.Context) (string, error)

GetCurrentTenantID retrieves current tenant ID

func GetCurrentUserID

func GetCurrentUserID(ctx context.Context) (string, error)

GetCurrentUserID retrieves current user ID

func HasPermission

func HasPermission(ctx context.Context, permission string) bool

Helper functions using global checker

func HasRole

func HasRole(ctx context.Context, role string) bool

func IsAuthenticated

func IsAuthenticated(ctx context.Context) bool

IsAuthenticated checks if user is authenticated

func IsSuperAdmin

func IsSuperAdmin(ctx context.Context) bool

func IsTenantAdmin

func IsTenantAdmin(ctx context.Context) bool

func RequirePermission

func RequirePermission(ctx context.Context, permission string) error

Types

type PermissionChecker

type PermissionChecker struct{}

PermissionChecker provides permission checking functionality

func NewPermissionChecker

func NewPermissionChecker() *PermissionChecker

NewPermissionChecker creates a new permission checker

func (*PermissionChecker) HasAllPermissions

func (pc *PermissionChecker) HasAllPermissions(ctx context.Context, permissions ...string) bool

HasAllPermissions checks if user has all of the specified permissions

func (*PermissionChecker) HasAnyPermission

func (pc *PermissionChecker) HasAnyPermission(ctx context.Context, permissions ...string) bool

HasAnyPermission checks if user has any of the specified permissions

func (*PermissionChecker) HasAnyRole

func (pc *PermissionChecker) HasAnyRole(ctx context.Context, roles ...string) bool

HasAnyRole checks if user has any of the specified roles

func (*PermissionChecker) HasPermission

func (pc *PermissionChecker) HasPermission(ctx context.Context, permission string) bool

HasPermission checks if user has a specific permission

func (*PermissionChecker) HasRole

func (pc *PermissionChecker) HasRole(ctx context.Context, role string) bool

HasRole checks if user has a specific role

func (*PermissionChecker) IsSuperAdmin

func (pc *PermissionChecker) IsSuperAdmin(ctx context.Context) bool

IsSuperAdmin checks if user is super admin

func (*PermissionChecker) IsTenantAdmin

func (pc *PermissionChecker) IsTenantAdmin(ctx context.Context) bool

IsTenantAdmin checks if user is tenant admin

func (*PermissionChecker) RequirePermission

func (pc *PermissionChecker) RequirePermission(ctx context.Context, permission string) error

RequirePermission checks permission and returns error if not authorized

type UserInfo

type UserInfo struct {
	ID          string
	Email       string
	TenantID    string
	Roles       []string
	Permissions []string
}

UserInfo represents current user information

func GetCurrentUser

func GetCurrentUser(ctx context.Context) (*UserInfo, error)

GetCurrentUser retrieves current user info from context

func MustGetCurrentUser

func MustGetCurrentUser(ctx context.Context) *UserInfo

MustGetCurrentUser retrieves current user or panics

Jump to

Keyboard shortcuts

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