forked from mtusi2026/mtusi2026lab2
45 lines
1.7 KiB
Go
45 lines
1.7 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab2/internal/model/dto"
|
|
)
|
|
|
|
// Passwords is the password KDF boundary used by authentication.
|
|
type Passwords interface {
|
|
// Hash creates a salted password encoding.
|
|
Hash(password string) (string, error)
|
|
// Verify checks the supplied password against its encoding.
|
|
Verify(encoded, password string) bool
|
|
}
|
|
|
|
// Accounts persists credentials and session validity independently of HTTP.
|
|
type Accounts interface {
|
|
// Register atomically stores a profile with credentials.
|
|
Register(context.Context, dto.UserDTO, string) (dto.UserDTO, error)
|
|
// Credentials looks up the password encoding and account profile.
|
|
Credentials(context.Context, string) (dto.UserDTO, string, error)
|
|
// SaveSession persists an opaque token digest and absolute expiry.
|
|
SaveSession(context.Context, string, uuid.UUID, time.Time) error
|
|
// SessionUser resolves an unexpired token digest.
|
|
SessionUser(context.Context, string) (uuid.UUID, error)
|
|
// RevokeSession invalidates a token digest.
|
|
RevokeSession(context.Context, string) error
|
|
}
|
|
|
|
// Authentication defines registration and opaque session operations.
|
|
type Authentication interface {
|
|
// Register validates registration and persists a password-protected account.
|
|
Register(context.Context, dto.UsersCreateRequestDTO, string) (dto.UserDTO, error)
|
|
// Login verifies credentials and issues an opaque session.
|
|
Login(context.Context, string, string) (dto.SessionDTO, error)
|
|
// Authenticate resolves a valid token to its immutable owner.
|
|
Authenticate(context.Context, string) (string, error)
|
|
// Logout revokes the current token.
|
|
Logout(context.Context, string) error
|
|
}
|