auth

package
v1.28.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = fx.Module(
	"auth",
	fx.Decorate(func(log *zap.Logger) *zap.Logger {
		return log.Named("auth")
	}),
	fx.Provide(New),
	fx.Provide(newRepository, fx.Private),
	fx.Invoke(func(lc fx.Lifecycle, svc *Service) {
		ctx, cancel := context.WithCancel(context.Background())
		lc.Append(fx.Hook{
			OnStart: func(_ context.Context) error {
				go svc.Run(ctx)
				return nil
			},
			OnStop: func(_ context.Context) error {
				cancel()
				return nil
			},
		})
	}),
)

Functions

This section is empty.

Types

type AuthCode added in v1.19.0

type AuthCode struct {
	Code       string
	ValidUntil time.Time
}

AuthCode is a one-time user authorization code

type Config

type Config struct {
	Mode         Mode
	PrivateToken string
}

type Mode

type Mode string
const (
	ModePublic  Mode = "public"
	ModePrivate Mode = "private"
)

type Params

type Params struct {
	fx.In

	Config Config

	Users      *repository
	DevicesSvc *devices.Service

	Logger *zap.Logger
}

type Service

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

func New

func New(params Params) *Service

func (*Service) AuthorizeDevice

func (s *Service) AuthorizeDevice(token string) (models.Device, error)

func (*Service) AuthorizeRegistration

func (s *Service) AuthorizeRegistration(token string) error

func (*Service) AuthorizeUser

func (s *Service) AuthorizeUser(username, password string) (models.User, error)

func (*Service) AuthorizeUserByCode added in v1.19.0

func (s *Service) AuthorizeUserByCode(code string) (models.User, error)

AuthorizeUserByCode authorizes a user by one-time code.

func (*Service) ChangePassword added in v1.16.0

func (s *Service) ChangePassword(userID string, currentPassword string, newPassword string) error

func (*Service) GenerateUserCode added in v1.19.0

func (s *Service) GenerateUserCode(userID string) (AuthCode, error)

GenerateUserCode generates a unique one-time user authorization code

func (*Service) IsPublic

func (s *Service) IsPublic() bool

func (*Service) RegisterDevice

func (s *Service) RegisterDevice(user models.User, name, pushToken *string) (models.Device, error)

func (*Service) RegisterUser

func (s *Service) RegisterUser(login, password string) (models.User, error)

func (*Service) Run added in v1.19.0

func (s *Service) Run(ctx context.Context)

Run starts a ticker that triggers the clean function every hour. It runs indefinitely until the provided context is canceled.

Jump to

Keyboard shortcuts

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