auth

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractToken

func ExtractToken(r *http.Request) string

ExtractToken extracts a Bearer token from an Authorization header.

func ExtractTokenFromQuery

func ExtractTokenFromQuery(r *http.Request) string

ExtractTokenFromQuery extracts a token from a URL query parameter.

Types

type Claims

type Claims struct {
	jwt.RegisteredClaims
	UserID   string `json:"user_id"`
	Username string `json:"username"`
	Role     Role   `json:"role"`
}

Claims extends standard JWT claims with Mana-specific fields.

type Config

type Config struct {
	Secret      string        `json:"secret"`
	Issuer      string        `json:"issuer"`
	TokenExpiry time.Duration `json:"token_expiry"`
}

Config holds JWT authentication configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type JWTAuth

type JWTAuth struct {
	// contains filtered or unexported fields
}

JWTAuth handles JWT token generation and validation.

func NewJWTAuth

func NewJWTAuth(cfg Config) *JWTAuth

NewJWTAuth creates a new JWTAuth with the given config.

func (*JWTAuth) GenerateToken

func (a *JWTAuth) GenerateToken(userID, username string, role Role) (string, error)

GenerateToken creates a signed JWT for the given user.

func (*JWTAuth) ValidateToken

func (a *JWTAuth) ValidateToken(tokenStr string) (*Claims, error)

ValidateToken parses and validates a JWT string.

type Permission

type Permission string

Permission defines a specific action that can be authorized.

const (
	PermRoomCreate  Permission = "room:create"
	PermRoomJoin    Permission = "room:join"
	PermRoomDelete  Permission = "room:delete"
	PermMessageSend Permission = "message:send"
	PermCallStart   Permission = "call:start"
	PermCallEnd     Permission = "call:end"
	PermAdminAll    Permission = "admin:all"
)

type RBAC

type RBAC struct {
	// contains filtered or unexported fields
}

RBAC manages role-based access control.

func NewRBAC

func NewRBAC() *RBAC

NewRBAC creates a new RBAC manager with default permissions.

func (*RBAC) Authorize

func (r *RBAC) Authorize(role Role, perm Permission) bool

Authorize checks if a role has a specific permission.

func (*RBAC) GrantPermission

func (r *RBAC) GrantPermission(role Role, perm Permission)

GrantPermission adds a permission to a role.

func (*RBAC) RevokePermission

func (r *RBAC) RevokePermission(role Role, perm Permission)

RevokePermission removes a permission from a role.

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter implements a per-key token bucket rate limiter.

func NewRateLimiter

func NewRateLimiter(rate, burst int) *RateLimiter

NewRateLimiter creates a rate limiter with the given rate (tokens/sec) and burst capacity.

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow(key string) bool

Allow checks whether a request identified by key is allowed. Returns true if allowed, false if rate limited.

type Role

type Role string

Role defines access levels for RBAC.

const (
	RoleAdmin Role = "admin"
	RoleUser  Role = "user"
	RoleGuest Role = "guest"
)

type SQLAccountStore

type SQLAccountStore struct {
	// contains filtered or unexported fields
}

func NewSQLAccountStore

func NewSQLAccountStore(backend *db.Backend) (*SQLAccountStore, error)

func NewSQLAccountStoreWithPrefix

func NewSQLAccountStoreWithPrefix(backend *db.Backend, prefix string) (*SQLAccountStore, error)

func (*SQLAccountStore) Authenticate

func (s *SQLAccountStore) Authenticate(ctx context.Context, username, password string) (string, error)

func (*SQLAccountStore) AuthenticateByEmail added in v0.3.0

func (s *SQLAccountStore) AuthenticateByEmail(ctx context.Context, email, password string) (string, error)

func (*SQLAccountStore) AuthenticateByPhone added in v0.3.0

func (s *SQLAccountStore) AuthenticateByPhone(ctx context.Context, phone, password string) (string, error)

func (*SQLAccountStore) CreateUser

func (s *SQLAccountStore) CreateUser(ctx context.Context, username, password string) error

func (*SQLAccountStore) CreateUserWithContact added in v0.3.0

func (s *SQLAccountStore) CreateUserWithContact(ctx context.Context, username, password, phone, email string) error

func (*SQLAccountStore) DeleteUser added in v0.3.0

func (s *SQLAccountStore) DeleteUser(ctx context.Context, userID string) error

func (*SQLAccountStore) GetUser

func (s *SQLAccountStore) GetUser(ctx context.Context, userID string) (core.User, error)

Jump to

Keyboard shortcuts

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