auth

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComparePasswords

func ComparePasswords(ctx context.Context, password string, hash []byte) (bool, error)

ComparePasswords compares a hashed password with its possible plaintext equivalent.

password is the plaintext password to verify. hash is the bcrypt hashed password.

Returns true if the password matches, false if it does not. Returns nil on success, or an error on failure.

func GenerateEncryptedPassword

func GenerateEncryptedPassword(ctx context.Context, password string) ([]byte, error)

GenerateEncryptedPassword generates a password hash using the crypto helper.

func VerifyPassword

func VerifyPassword(password string) error

VerifyPassword verifies a password Returns an error if the password is invalid.

Types

type IAuthRedisRepository

type IAuthRedisRepository interface {
	HasState(ctx context.Context, state string) (bool, error)
	SetState(ctx context.Context, state string) error
	DeleteState(ctx context.Context, state string) error
}

IAuthRedisRepository is the interface for the auth redis repository.

func NewRedisRepository

func NewRedisRepository(redisConn *redis.Client) IAuthRedisRepository

NewRedisRepository returns a new redis repository.

type IUseCase

type IUseCase interface {
	Login(ctx context.Context, password string, email string) (string, error)
	Register(ctx context.Context, registerStruct domain.Register) (domain.User, error)
	Logout(ctx context.Context) (string, error)
	RefreshToken(ctx context.Context, user domain.User) (string, error)
	RegisterOauth(ctx context.Context, user domain.User) error
	LoginOauth(ctx context.Context, user domain.User) (string, error)
}

IUseCase is the interface for the auth use case.

func NewUseCase

func NewUseCase(repo user.IRepository) IUseCase

NewUseCase creates a new auth use case.

type RedisRepository

type RedisRepository struct {
	RedisConn *redis.Client
}

RedisRepository is the redis repository for the auth use case.

func (*RedisRepository) DeleteState

func (r *RedisRepository) DeleteState(ctx context.Context, state string) error

DeleteState deletes the state in the redis database.

func (*RedisRepository) HasState

func (r *RedisRepository) HasState(ctx context.Context, state string) (bool, error)

HasState checks if the state exists in the redis database.

func (*RedisRepository) SetState

func (r *RedisRepository) SetState(ctx context.Context, state string) error

SetState sets the state in the redis database.

type UseCase

type UseCase struct {
	user.IRepository
}

UseCase is the auth use case.

func (*UseCase) Login

func (a *UseCase) Login(ctx context.Context, password string, email string) (string, error)

Login logs in a user Returns a token and error.

func (*UseCase) LoginOauth

func (a *UseCase) LoginOauth(ctx context.Context, user domain.User) (string, error)

func (*UseCase) Logout

func (*UseCase) Logout(_ context.Context) (string, error)

Logout returns an empty string It might be used to invalidate a token in the future.

func (*UseCase) RefreshToken

func (*UseCase) RefreshToken(ctx context.Context, user domain.User) (string, error)

RefreshToken refreshes a token.

func (*UseCase) Register

func (a *UseCase) Register(ctx context.Context, registerStruct domain.Register) (domain.User, error)

Register registers a new user Returns an error.

func (*UseCase) RegisterOauth

func (a *UseCase) RegisterOauth(ctx context.Context, user domain.User) error

RegisterOauth registers a new user with oauth.

Jump to

Keyboard shortcuts

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