Documentation
¶
Index ¶
- func ExtractToken(r *http.Request) string
- func ExtractTokenFromQuery(r *http.Request) string
- type Claims
- type Config
- type JWTAuth
- type Permission
- type RBAC
- type RateLimiter
- type Role
- type SQLAccountStore
- func (s *SQLAccountStore) Authenticate(ctx context.Context, username, password string) (string, error)
- func (s *SQLAccountStore) AuthenticateByEmail(ctx context.Context, email, password string) (string, error)
- func (s *SQLAccountStore) AuthenticateByPhone(ctx context.Context, phone, password string) (string, error)
- func (s *SQLAccountStore) CreateUser(ctx context.Context, username, password string) error
- func (s *SQLAccountStore) CreateUserWithContact(ctx context.Context, username, password, phone, email string) error
- func (s *SQLAccountStore) DeleteUser(ctx context.Context, userID string) error
- func (s *SQLAccountStore) GetUser(ctx context.Context, userID string) (core.User, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractToken ¶
ExtractToken extracts a Bearer token from an Authorization header.
func ExtractTokenFromQuery ¶
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 ¶
NewJWTAuth creates a new JWTAuth with the given config.
func (*JWTAuth) GenerateToken ¶
GenerateToken creates a signed JWT for the given user.
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 (*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 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 (*SQLAccountStore) AuthenticateByEmail ¶ added in v0.3.0
func (*SQLAccountStore) AuthenticateByPhone ¶ added in v0.3.0
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