auth

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCredentials              = errors.New("invalid credentials")
	ErrUserAlreadyExists               = errors.New("user already exists")
	ErrUnsupportedProvider             = errors.New("auth provider is not supported")
	ErrAccountExistsMustLink           = errors.New("account exists; must link provider explicitly")
	ErrUsernameTaken                   = errors.New("username already taken")
	ErrInvalidUsername                 = errors.New("invalid username")
	ErrNoRolesInContext                = errors.New("no roles in context for user")
	ErrEmailNotAllowed                 = errors.New("email is not allowed to access the application")
	ErrAuthProviderAlreadyLinked       = errors.New("auth provider already linked to another user")
	ErrAuthProviderAlreadyLinkedToUser = errors.New("auth provider already linked to user")
	ErrCannotRemoveLastAuthProvider    = errors.New("cannot remove last auth provider")
	ErrPasswordAlreadyExists           = errors.New("password provider already exists")
	ErrPendingProviderLinkExpired      = errors.New("pending provider link expired")
	ErrPendingProviderLinkInvalid      = errors.New("pending provider link invalid")
	ErrProviderDisabled                = errors.New("provider disabled")
)

Functions

func EnsureUsername added in v0.1.13

func EnsureUsername(username, email string) (string, error)

func Hash

func Hash(password string) (string, error)

func SanitizeUsername

func SanitizeUsername(s string) string

sanitizeUsername: - keeps only [a-zA-z0-9_-] - turns runs of other chars into a single '-' - trims leading/trailing '-' and '_'

func SecureFiveDigits

func SecureFiveDigits() (int64, error)

func ValidateUsername

func ValidateUsername(username string) error

func Verify

func Verify(password, encoded string) (bool, error)

Types

type Config

type Config struct {
	Store            *store.Store
	Tx               *tx.Manager
	WebhookPublisher webhook.Publisher
	Logger           *slog.Logger
	AccessPolicy     accesspolicy.EmailAccessPolicy
	OAuthProviders   oauth.OAuthProviders
}

type LoginInput

type LoginInput struct {
	Provider domain.Provider

	Username string
	Email    string
	Password string

	OAuthID string
}

type Service

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

func New

func New(cfg Config) *Service

func (*Service) AddPassword added in v0.1.17

func (s *Service) AddPassword(ctx context.Context, userID uuid.UUID, passwordHash string) error

func (*Service) ChangePassword added in v0.1.17

func (s *Service) ChangePassword(ctx context.Context, userID uuid.UUID, currentPassword string, newPasswordHash string) error

func (*Service) ChangeUsername

func (s *Service) ChangeUsername(ctx context.Context, userID uuid.UUID, username string) error
func (s *Service) CompleteProviderLink(
	ctx context.Context,
	linkID uuid.UUID,
	userID uuid.UUID,
	sessionID uuid.UUID,
	provider domain.Provider,
	providerUserID string,
	now time.Time,
) error

func (*Service) DeleteUser

func (s *Service) DeleteUser(ctx context.Context, userID uuid.UUID) error

func (*Service) DisableUser

func (s *Service) DisableUser(ctx context.Context, userID uuid.UUID) error

func (*Service) GetUser

func (s *Service) GetUser(ctx context.Context, userID uuid.UUID) (domain.User, error)

func (*Service) GetUserByEmail added in v0.1.14

func (s *Service) GetUserByEmail(ctx context.Context, email string) (domain.User, error)

func (*Service) IsProviderEnabled added in v0.1.17

func (s *Service) IsProviderEnabled(provider domain.Provider) bool

func (*Service) ListUserAuthProviders added in v0.1.17

func (s *Service) ListUserAuthProviders(ctx context.Context, userID uuid.UUID) ([]domain.AuthProvider, error)

func (*Service) Login

func (s *Service) Login(ctx context.Context, in LoginInput) (domain.User, error)

func (*Service) Signup

func (s *Service) Signup(ctx context.Context, in SignupInput) (domain.User, error)
func (s *Service) StartProviderLink(
	ctx context.Context,
	userID uuid.UUID,
	sessionID uuid.UUID,
	provider domain.Provider,
	now time.Time,
) (uuid.UUID, error)

func (*Service) UnlinkAuthProvider added in v0.1.17

func (s *Service) UnlinkAuthProvider(ctx context.Context, userID uuid.UUID, provider domain.Provider) error

func (*Service) UserExistsByEmail added in v0.1.12

func (s *Service) UserExistsByEmail(ctx context.Context, email string) (bool, error)

type SignupInput

type SignupInput struct {
	Provider domain.Provider

	Username     string
	Email        string
	PasswordHash string

	OAuthID string
}

Jump to

Keyboard shortcuts

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