authsupport

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAuthStoreUnavailable = errors.New("auth store unavailable: database connection required")

Functions

func SelectStore

func SelectStore(cfg *config.Config, db *sql.DB) authStore

Types

type AuthClient

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

AuthClient is the client that handles authentication requests

func NewAuthClient

func NewAuthClient(cfg *config.Config, store authStore) *AuthClient

NewAuthClient creates a new authentication client

func (*AuthClient) AuthenticateUserByEmailPassword

func (c *AuthClient) AuthenticateUserByEmailPassword(
	ctx echo.Context,
	email string,
	password string,
) (*AuthUserRecord, error)

AuthenticateUserByEmailPassword authenticates credentials and returns the user record on success.

func (*AuthClient) CheckPassword

func (c *AuthClient) CheckPassword(password, hash string) error

CheckPassword check if a given password matches a given hash

func (*AuthClient) DeletePasswordTokens

func (c *AuthClient) DeletePasswordTokens(ctx echo.Context, userID int) error

DeletePasswordTokens deletes all password tokens in the database for a belonging to a given user. This should be called after a successful password reset.

func (*AuthClient) FindUserRecordByEmail

func (c *AuthClient) FindUserRecordByEmail(ctx echo.Context, email string) (*AuthUserRecord, error)

FindUserRecordByEmail returns an auth user record by email (case-insensitive).

func (*AuthClient) GenerateEmailVerificationToken

func (c *AuthClient) GenerateEmailVerificationToken(email string) (string, error)

GenerateEmailVerificationToken generates an email verification token for a given email address using JWT which is set to expire based on the duration stored in configuration

func (*AuthClient) GeneratePasswordResetToken

func (c *AuthClient) GeneratePasswordResetToken(ctx echo.Context, userID int) (string, int, error)

GeneratePasswordResetToken generates a password reset token for a given user. For security purposes, the token itself is not stored in the database but rather a hash of the token, exactly how passwords are handled. This method returns both the generated token as well as the created password token ID.

func (*AuthClient) GetAuthenticatedIdentity

func (c *AuthClient) GetAuthenticatedIdentity(ctx echo.Context) (*AuthIdentity, error)

GetAuthenticatedIdentity returns the authenticated identity if the user is logged in.

func (*AuthClient) GetAuthenticatedUserID

func (c *AuthClient) GetAuthenticatedUserID(ctx echo.Context) (int, error)

GetAuthenticatedUserID returns the authenticated user's ID, if the user is logged in

func (*AuthClient) GetIdentityByUserID

func (c *AuthClient) GetIdentityByUserID(ctx stdcontext.Context, userID int) (*AuthIdentity, error)

GetIdentityByUserID returns an auth identity for an explicit user ID.

func (*AuthClient) GetUserDisplayNameByUserID

func (c *AuthClient) GetUserDisplayNameByUserID(ctx echo.Context, userID int) (string, error)

func (*AuthClient) GetValidPasswordToken

func (c *AuthClient) GetValidPasswordToken(ctx echo.Context, userID, tokenID int, token string) error

GetValidPasswordToken validates a non-expired password token for a given user/token ID combination. Since the raw token is not stored in the database for security purposes, the provided token is checked against the stored hash.

func (*AuthClient) HashPassword

func (c *AuthClient) HashPassword(password string) (string, error)

HashPassword returns a hash of a given password

func (*AuthClient) Login

func (c *AuthClient) Login(ctx echo.Context, userID int) error

Login logs in a user of a given ID

func (*AuthClient) Logout

func (c *AuthClient) Logout(ctx echo.Context) error

Logout logs the requesting user out

func (*AuthClient) MarkUserVerifiedByUserID

func (c *AuthClient) MarkUserVerifiedByUserID(ctx echo.Context, userID int) error

func (*AuthClient) RandomToken

func (c *AuthClient) RandomToken(length int) (string, error)

RandomToken generates a random token string of a given length

func (*AuthClient) SetLastOnlineTimestamp

func (c *AuthClient) SetLastOnlineTimestamp(ctx echo.Context, userID int) error

SetLastOnlineTimestamp sets the last online time for a user

func (*AuthClient) SetUserDisplayNameByUserID

func (c *AuthClient) SetUserDisplayNameByUserID(ctx echo.Context, userID int, displayName string) error

func (*AuthClient) SetUserPasswordHashByUserID

func (c *AuthClient) SetUserPasswordHashByUserID(ctx echo.Context, userID int, passwordHash string) error

func (*AuthClient) ValidateEmailVerificationToken

func (c *AuthClient) ValidateEmailVerificationToken(token string) (string, error)

ValidateEmailVerificationToken validates an email verification token and returns the associated email address if the token is valid and has not expired

type AuthIdentity

type AuthIdentity struct {
	UserID                int
	UserName              string
	UserEmail             string
	HasProfile            bool
	ProfileID             int
	ProfileFullyOnboarded bool
}

AuthIdentity is the authenticated user shape exposed to request middleware.

type AuthUserRecord

type AuthUserRecord struct {
	UserID     int
	Name       string
	Email      string
	Password   string
	IsVerified bool
}

AuthUserRecord is the user lookup shape exposed to web controllers.

type InvalidCredentialsError

type InvalidCredentialsError struct{}

InvalidCredentialsError is returned when email/password authentication fails.

func (InvalidCredentialsError) Error

func (e InvalidCredentialsError) Error() string

Error implements the error interface.

type InvalidPasswordTokenError

type InvalidPasswordTokenError struct{}

InvalidPasswordTokenError is an error returned when an invalid token is provided

func (InvalidPasswordTokenError) Error

Error implements the error interface.

type NotAuthenticatedError

type NotAuthenticatedError struct{}

NotAuthenticatedError is an error returned when a user is not authenticated

func (NotAuthenticatedError) Error

func (e NotAuthenticatedError) Error() string

Error implements the error interface.

Jump to

Keyboard shortcuts

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