usecase
import "github.com/prescriptoo/prescriptoo-api/services/identity/internal/usecase"Package usecase defines the identity application's contracts and use cases.
Index
- Variables
- type Auth
- type AuthenticatedDTO
- type ChangePasswordDTO
- type ChangePasswordUseCase
- type ConfirmEmailVerificationUseCase
- type Dependencies
- type EmailDTO
- type ForgotPasswordUseCase
- type GetAccountUseCase
- type GetMeUseCase
- type ListSessionsUseCase
- type LoginDTO
- type LoginUseCase
- func NewLoginUseCase(auth *Auth) *LoginUseCase
- func (uc *LoginUseCase) Execute(ctx context.Context, input LoginDTO) (result *TokenPair, err error)
- func (uc *LoginUseCase) ExecuteWithAuthorization(ctx context.Context, input LoginDTO, authorize func(context.Context, string) error) (result *TokenPair, err error)
- type LogoutAllUseCase
- type LogoutUseCase
- type Message
- type Principal
- type Provisioner
- type RefreshDTO
- type RefreshUseCase
- type RegisterDTO
- type RegisterUseCase
- type RequestEmailVerificationUseCase
- type ResetPasswordDTO
- type ResetPasswordUseCase
- type RevokeSessionDTO
- type RevokeSessionUseCase
- type Session
- type Sessions
- type TokenDTO
- type TokenPair
- type UpdateMeDTO
- type UpdateMeUseCase
- type User
- type ValidateAuthorizationUseCase
- type ValidateTokenUseCase
Variables
ErrUnavailable indicates missing dependencies, such as a documentation-only module.
var ErrUnavailable = errors.New("authentication dependencies are unavailable")type Auth
Auth holds shared dependencies for identity operations.
type Auth struct {
// contains filtered or unexported fields
}func NewAuth
func NewAuth(d Dependencies) (*Auth, error)NewAuth wires authentication dependencies and prepares timing protection.
type AuthenticatedDTO
AuthenticatedDTO carries the bearer authorization header.
type AuthenticatedDTO struct{ Authorization string }type ChangePasswordDTO
ChangePasswordDTO carries credentials for a password change.
type ChangePasswordDTO struct{ Authorization, CurrentPassword, NewPassword string }type ChangePasswordUseCase
ChangePasswordUseCase changes a password and revokes sessions.
type ChangePasswordUseCase struct {
// contains filtered or unexported fields
}func NewChangePasswordUseCase
func NewChangePasswordUseCase(auth *Auth) *ChangePasswordUseCaseNewChangePasswordUseCase wires the operation to its dependencies.
func (*ChangePasswordUseCase) Execute
func (uc *ChangePasswordUseCase) Execute(ctx context.Context, input ChangePasswordDTO) errorExecute changes a password and revokes sessions.
type ConfirmEmailVerificationUseCase
ConfirmEmailVerificationUseCase consumes an email verification token.
type ConfirmEmailVerificationUseCase struct {
// contains filtered or unexported fields
}func NewConfirmEmailVerificationUseCase
func NewConfirmEmailVerificationUseCase(auth *Auth) *ConfirmEmailVerificationUseCaseNewConfirmEmailVerificationUseCase wires the operation to its dependencies.
func (*ConfirmEmailVerificationUseCase) Execute
func (uc *ConfirmEmailVerificationUseCase) Execute(ctx context.Context, input TokenDTO) errorExecute consumes an email verification token.
type Dependencies
Dependencies supplies persistence, cryptography, and the shared email sender.
type Dependencies struct {
Users ports.UserRepository
Sessions ports.SessionRepository
Accounts ports.AccountRepository
Passwords ports.PasswordHasher
Tokens ports.AccessTokens
Email email.Sender
AccessTTL, RefreshTTL time.Duration
}type EmailDTO
EmailDTO identifies an email recipient.
type EmailDTO struct{ Email string }type ForgotPasswordUseCase
ForgotPasswordUseCase requests a password-reset token.
type ForgotPasswordUseCase struct {
// contains filtered or unexported fields
}func NewForgotPasswordUseCase
func NewForgotPasswordUseCase(auth *Auth) *ForgotPasswordUseCaseNewForgotPasswordUseCase wires the operation to its dependencies.
func (*ForgotPasswordUseCase) Execute
func (uc *ForgotPasswordUseCase) Execute(ctx context.Context, input EmailDTO) (*Message, error)Execute requests a password-reset token.
type GetAccountUseCase
GetAccountUseCase reads an identity account for an internal service call.
type GetAccountUseCase struct {
// contains filtered or unexported fields
}func NewGetAccountUseCase
func NewGetAccountUseCase(auth *Auth) *GetAccountUseCaseNewGetAccountUseCase wires account lookup to the authentication dependencies.
func (*GetAccountUseCase) Execute
func (uc *GetAccountUseCase) Execute(ctx context.Context, userID string) (*User, error)Execute retrieves a user by ID without exposing private identity fields.
type GetMeUseCase
GetMeUseCase returns the authenticated user profile.
type GetMeUseCase struct {
// contains filtered or unexported fields
}func NewGetMeUseCase
func NewGetMeUseCase(auth *Auth) *GetMeUseCaseNewGetMeUseCase wires the operation to authentication dependencies.
func (*GetMeUseCase) Execute
func (uc *GetMeUseCase) Execute(ctx context.Context, input AuthenticatedDTO) (*User, error)Execute returns the authenticated user profile.
type ListSessionsUseCase
ListSessionsUseCase lists the authenticated user’s active sessions.
type ListSessionsUseCase struct {
// contains filtered or unexported fields
}func NewListSessionsUseCase
func NewListSessionsUseCase(auth *Auth) *ListSessionsUseCaseNewListSessionsUseCase wires the operation to its dependencies.
func (*ListSessionsUseCase) Execute
func (uc *ListSessionsUseCase) Execute(ctx context.Context, input AuthenticatedDTO) (*Sessions, error)Execute lists the authenticated user’s active sessions.
type LoginDTO
LoginDTO carries login credentials.
type LoginDTO struct{ Email, Password, IPAddress, UserAgent string }type LoginUseCase
LoginUseCase authenticates credentials and creates a session.
type LoginUseCase struct {
// contains filtered or unexported fields
}func NewLoginUseCase
func NewLoginUseCase(auth *Auth) *LoginUseCaseNewLoginUseCase wires the operation to authentication dependencies.
func (*LoginUseCase) Execute
func (uc *LoginUseCase) Execute(ctx context.Context, input LoginDTO) (result *TokenPair, err error)Execute authenticates credentials and creates a session.
func (*LoginUseCase) ExecuteWithAuthorization
func (uc *LoginUseCase) ExecuteWithAuthorization(ctx context.Context, input LoginDTO, authorize func(context.Context, string) error) (result *TokenPair, err error)ExecuteWithAuthorization checks caller-owned eligibility after authenticating an active account and before issuing credentials or persisting a session.
type LogoutAllUseCase
LogoutAllUseCase revokes all sessions belonging to the authenticated user.
type LogoutAllUseCase struct {
// contains filtered or unexported fields
}func NewLogoutAllUseCase
func NewLogoutAllUseCase(auth *Auth) *LogoutAllUseCaseNewLogoutAllUseCase wires the operation to its dependencies.
func (*LogoutAllUseCase) Execute
func (uc *LogoutAllUseCase) Execute(ctx context.Context, input AuthenticatedDTO) errorExecute revokes all sessions belonging to the authenticated user.
type LogoutUseCase
LogoutUseCase revokes the session identified by a refresh token.
type LogoutUseCase struct {
// contains filtered or unexported fields
}func NewLogoutUseCase
func NewLogoutUseCase(auth *Auth) *LogoutUseCaseNewLogoutUseCase wires the operation to authentication dependencies.
func (*LogoutUseCase) Execute
func (uc *LogoutUseCase) Execute(ctx context.Context, input RefreshDTO) errorExecute revokes the session identified by a refresh token.
type Message
Message is the public result of an identity operation.
type Message struct {
Message string `json:"message" example:"If the account is eligible, email delivery has been requested." doc:"Generic acknowledgement independent of account existence."`
}type Principal
Principal is the result of validating an Authorization header.
type Principal struct {
UserID string
SessionID string
}type Provisioner
Provisioner atomically saves an account and its initiating admin's audit event.
type Provisioner interface {
Create(context.Context, audit.OperationContext, *domain.User) error
}type RefreshDTO
RefreshDTO carries a refresh token.
type RefreshDTO struct{ RefreshToken string }type RefreshUseCase
RefreshUseCase rotates credentials for an existing session.
type RefreshUseCase struct {
// contains filtered or unexported fields
}func NewRefreshUseCase
func NewRefreshUseCase(auth *Auth) *RefreshUseCaseNewRefreshUseCase wires the operation to authentication dependencies.
func (*RefreshUseCase) Execute
func (uc *RefreshUseCase) Execute(ctx context.Context, input RefreshDTO) (*TokenPair, error)Execute rotates credentials for an existing session.
type RegisterDTO
RegisterDTO carries account registration fields.
type RegisterDTO struct{ Email, Password, Name string }type RegisterUseCase
RegisterUseCase creates an active account.
type RegisterUseCase struct {
// contains filtered or unexported fields
}func NewRegisterUseCase
func NewRegisterUseCase(auth *Auth) *RegisterUseCaseNewRegisterUseCase wires the operation to authentication dependencies.
func (*RegisterUseCase) Execute
func (uc *RegisterUseCase) Execute(ctx context.Context, input RegisterDTO) (result *User, err error)Execute creates an active account.
type RequestEmailVerificationUseCase
RequestEmailVerificationUseCase requests an email verification token.
type RequestEmailVerificationUseCase struct {
// contains filtered or unexported fields
}func NewRequestEmailVerificationUseCase
func NewRequestEmailVerificationUseCase(auth *Auth) *RequestEmailVerificationUseCaseNewRequestEmailVerificationUseCase wires the operation to its dependencies.
func (*RequestEmailVerificationUseCase) Execute
func (uc *RequestEmailVerificationUseCase) Execute(ctx context.Context, input EmailDTO) (*Message, error)Execute requests an email verification token.
type ResetPasswordDTO
ResetPasswordDTO carries a reset token and replacement password.
type ResetPasswordDTO struct{ Token, NewPassword string }type ResetPasswordUseCase
ResetPasswordUseCase resets a password and revokes sessions.
type ResetPasswordUseCase struct {
// contains filtered or unexported fields
}func NewResetPasswordUseCase
func NewResetPasswordUseCase(auth *Auth) *ResetPasswordUseCaseNewResetPasswordUseCase wires the operation to its dependencies.
func (*ResetPasswordUseCase) Execute
func (uc *ResetPasswordUseCase) Execute(ctx context.Context, input ResetPasswordDTO) errorExecute resets a password and revokes sessions.
type RevokeSessionDTO
RevokeSessionDTO identifies a session to revoke.
type RevokeSessionDTO struct{ Authorization, SessionID string }type RevokeSessionUseCase
RevokeSessionUseCase revokes a session owned by the authenticated user.
type RevokeSessionUseCase struct {
// contains filtered or unexported fields
}func NewRevokeSessionUseCase
func NewRevokeSessionUseCase(auth *Auth) *RevokeSessionUseCaseNewRevokeSessionUseCase wires the operation to its dependencies.
func (*RevokeSessionUseCase) Execute
func (uc *RevokeSessionUseCase) Execute(ctx context.Context, input RevokeSessionDTO) errorExecute revokes a session owned by the authenticated user.
type Session
Session is the public result of an identity operation.
type Session struct {
ID string `json:"id" format:"uuid" example:"cd20a97b-5107-44db-bf05-66c86c54aa91" doc:"Session identifier for revocation."`
DeviceName string `json:"device_name" example:"Chrome on Linux" doc:"Device label, if available."`
DeviceType string `json:"device_type" example:"web" doc:"Device category, if available."`
IPAddress string `json:"ip_address" example:"192.0.2.1" doc:"IP address associated with the session."`
UserAgent string `json:"user_agent" example:"Mozilla/5.0" doc:"Client user agent, if available."`
Current bool `json:"current" example:"true" doc:"Whether this is the session used for the request."`
CreatedAt time.Time `json:"created_at" doc:"Session creation timestamp."`
LastActiveAt time.Time `json:"last_active_at" doc:"Most recent session activity timestamp."`
ExpiresAt time.Time `json:"expires_at" doc:"Session expiration timestamp."`
}type Sessions
Sessions is the public result of an identity operation.
type Sessions struct {
Sessions []Session `json:"sessions" nullable:"false" doc:"Active sessions, ordered by most recent activity; empty when none exist."`
}type TokenDTO
TokenDTO carries a single-use token.
type TokenDTO struct{ Token string }type TokenPair
TokenPair is the public result of an identity operation.
type TokenPair = identitypublic.TokenPairtype UpdateMeDTO
UpdateMeDTO carries replacement profile fields.
type UpdateMeDTO struct{ Authorization, Name, Phone, AvatarURL string }type UpdateMeUseCase
UpdateMeUseCase updates editable profile fields.
type UpdateMeUseCase struct {
// contains filtered or unexported fields
}func NewUpdateMeUseCase
func NewUpdateMeUseCase(auth *Auth) *UpdateMeUseCaseNewUpdateMeUseCase wires the operation to its dependencies.
func (*UpdateMeUseCase) Execute
func (uc *UpdateMeUseCase) Execute(ctx context.Context, input UpdateMeDTO) (*User, error)Execute updates editable profile fields.
type User
User is the public result of an identity operation.
type User struct {
ID string `json:"id" format:"uuid" example:"b3f1c812-479a-4f37-a67b-0e089cc827f4" doc:"Unique user identifier."`
Email string `json:"email" format:"email" example:"user@example.com" doc:"Account email address."`
Name string `json:"name" example:"Jane Doe" doc:"Display name."`
Phone string `json:"phone" example:"+8801700000000" doc:"Contact phone number, or an empty string when unset."`
AvatarURL string `json:"avatar_url" example:"https://example.com/avatar.png" doc:"Avatar URL, or an empty string when unset."`
Status string `json:"status" example:"active" doc:"Account lifecycle status."`
EmailVerified bool `json:"email_verified" example:"false" doc:"Whether the account email has been verified."`
CreatedAt time.Time `json:"created_at" doc:"Account creation timestamp in RFC 3339 format."`
UpdatedAt time.Time `json:"updated_at" doc:"Last profile update timestamp in RFC 3339 format."`
}func ProvisionAccount
func ProvisionAccount(ctx context.Context, auth *Auth, writer Provisioner, op audit.OperationContext, input RegisterDTO) (*User, error)ProvisionAccount validates and hashes credentials before atomically saving the account and its audit entry.
func RegisterWithRepository
func RegisterWithRepository(ctx context.Context, auth *Auth, users ports.UserRepository, input RegisterDTO) (*User, error)RegisterWithRepository keeps validation and password hashing owned by Identity while allowing onboarding to use transaction-bound persistence.
type ValidateAuthorizationUseCase
ValidateAuthorizationUseCase validates an access token and persistent session without exposing identity domain entities.
type ValidateAuthorizationUseCase struct {
// contains filtered or unexported fields
}func NewValidateAuthorizationUseCase
func NewValidateAuthorizationUseCase(auth *Auth) *ValidateAuthorizationUseCaseNewValidateAuthorizationUseCase wires access token and session validation.
func (*ValidateAuthorizationUseCase) Execute
func (uc *ValidateAuthorizationUseCase) Execute(ctx context.Context, authorization string) (*Principal, error)Execute validates an Authorization header and returns its user and active session IDs.
type ValidateTokenUseCase
ValidateTokenUseCase validates an access token against its persistent session.
type ValidateTokenUseCase struct {
// contains filtered or unexported fields
}func NewValidateTokenUseCase
func NewValidateTokenUseCase(auth *Auth) *ValidateTokenUseCaseNewValidateTokenUseCase wires the operation to authentication dependencies.
func (*ValidateTokenUseCase) Execute
func (uc *ValidateTokenUseCase) Execute(ctx context.Context, token string) (*domain.User, error)Execute validates an access token against its persistent session.
Generated by gomarkdoc