service

package
v0.0.0-...-dc61bab Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthService

type AuthService interface {
	SignUp(ctx context.Context, schema UserSignUpSchema) error
	SignIn(ctx context.Context, schema UserSignInSchema) (entity.Tokens, error)
	SignOut(ctx context.Context, userID primitive.ObjectID) error
}

AuthService is a service for authorization/authentication

func NewAuthService

func NewAuthService(
	cache *redis.Client,
	usersRepo repository.UsersRepository,
	hasherServ hash.HasherService,
	jwtServ JWTService,
) (AuthService, error)

type ChangeEmailSchema

type ChangeEmailSchema struct {
	UserID   primitive.ObjectID
	NewEmail string
}

type ChangePasswordSchema

type ChangePasswordSchema struct {
	UserID          primitive.ObjectID
	CurrentPassword string
	NewPassword     string
}

type Dependencies

type Dependencies struct {
	Cache            *redis.Client
	Repos            *repository.Repositories
	HasherService    hash.HasherService
	JWTServiceConfig JWTServiceConfig
}

type JWTService

type JWTService interface {
	CreateTokens(ctx context.Context, userID string) (entity.Tokens, error)
	ProlongTokens(ctx context.Context, userID string)
	ParseAccessToken(token string) (*token.JWTCustomClaims, error)
	ParseRefreshToken(token string) (*token.JWTCustomClaims, error)
	ValidateAccessToken(ctx context.Context, claims *token.JWTCustomClaims) error
	ValidateRefreshToken(ctx context.Context, claims *token.JWTCustomClaims) error
}

JWTService provides logic for JWT & Refresh tokens generation, parsing and validation.

func NewJWTService

func NewJWTService(cfg JWTServiceConfig, cache *redis.Client) (JWTService, error)

type JWTServiceConfig

type JWTServiceConfig struct {
	AccessToken     token.Config  `mapstructure:"accessToken"`
	RefreshToken    token.Config  `mapstructure:"refreshToken"`
	InactiveTimeout time.Duration `mapstructure:"inactiveTimeout"`
}

type Services

type Services struct {
	JWT   JWTService
	Auth  AuthService
	Users UsersService
}

Services is a collection of all services we have in the project.

func NewServices

func NewServices(deps Dependencies) (*Services, error)

type UserSignInSchema

type UserSignInSchema struct {
	Login    string
	Password string
}

type UserSignUpSchema

type UserSignUpSchema struct {
	Username string
	Email    string
	Password string
}

type UsersService

type UsersService interface {
	GetByID(ctx context.Context, userID primitive.ObjectID) (entity.User, error)
	ChangeEmail(ctx context.Context, schema ChangeEmailSchema) error
	ChangePassword(ctx context.Context, schema ChangePasswordSchema) error
}

UsersService is a service for users

func NewUsersService

func NewUsersService(
	usersRepo repository.UsersRepository,
	hasherServ hash.HasherService,
) (UsersService, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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