RezinaLMS-BackEnd/internal/ports/auth.go
n3p-tun3 a81fe3cd19 feat(auth): add learner device sessions with a 2-device limit
- Track learner sessions and revoke them immediately on every request
- Add a device replacement challenge for logins over the limit
- Add learner and admin endpoints to list and remove devices
- Trim excess sessions when enforcement is enabled
- Stop logging refresh tokens and authorization headers

Enforcement is off by default through DEVICE_LIMIT_ENFORCED.
2026-11-23 17:38:48 +03:00

29 lines
1.4 KiB
Go

package ports
import (
"Rezina-Backend/internal/domain"
"context"
"github.com/google/uuid"
)
type TokenStore interface {
CreateRefreshToken(ctx context.Context, rt domain.RefreshToken) error
GetRefreshToken(ctx context.Context, token string) (domain.RefreshToken, error)
GetRefreshTokenByUserID(ctx context.Context, id int64) (domain.RefreshToken, error)
RevokeRefreshToken(ctx context.Context, token string) error
}
type SessionStore interface {
IssueUserSession(ctx context.Context, params domain.SessionIssueParams) (domain.SessionIssueResult, error)
ReplaceUserSession(ctx context.Context, params domain.SessionReplaceParams) (domain.UserSession, error)
RotateSessionRefreshToken(ctx context.Context, params domain.SessionRefreshParams) (domain.RefreshToken, error)
LogoutSession(ctx context.Context, refreshToken string) error
IsUserSessionActive(ctx context.Context, sessionID uuid.UUID, userID int64) (bool, error)
ListUserSessions(ctx context.Context, userID int64) ([]domain.UserSession, error)
RevokeOwnUserSession(ctx context.Context, userID int64, sessionID uuid.UUID, reason string) error
RevokeUserSession(ctx context.Context, userID int64, sessionID uuid.UUID, reason string) error
RevokeAllUserSessionsAndTokens(ctx context.Context, userID int64, reason string) error
RevokeSessionsForRoleExcludingUser(ctx context.Context, role string, excludeUserID int64) error
}