auth

package
v0.0.0-...-05cdca5 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const FieldID userID = "uid"

FieldID field name for user ID

Variables

This section is empty.

Functions

func GenerateUserID

func GenerateUserID() string

GenerateUserID - generates unique user id using uuid

Types

type Account

type Account struct {
	ID           string
	Login        string
	PasswordHash string
}

Account - User

func (*Account) GetID

func (a *Account) GetID() string

GetID get account id

func (*Account) GetLogin

func (a *Account) GetLogin() string

GetLogin get account login

func (*Account) SetPasswordHash

func (a *Account) SetPasswordHash(h string)

SetPasswordHash set password hash

type AuthRepository

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

AuthRepository - Auth repository

func NewAuthRepository

func NewAuthRepository(
	db *sqlx.DB,
	l contract.IApplicationLogger,
) *AuthRepository

NewAuthRepository - create new auth repository

func (*AuthRepository) Create

func (a *AuthRepository) Create(
	ctx context.Context,
	login,
	password string,
) (contract.IAccount, error)

Create - create new user

func (*AuthRepository) Find

func (a *AuthRepository) Find(
	ctx context.Context,
	login,
	password string,
) (contract.IAccount, error)

Find - find user by login and password

type AuthService

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

AuthService - Auth service

func NewAuthService

func NewAuthService(
	tokenProvider contract.ITokenProvider,
	repo contract.IAuthRepository,
	passHasher contract.IPassHasher,
) *AuthService

NewAuthService - create new auth service

func (*AuthService) SignIn

func (a *AuthService) SignIn(
	ctx context.Context,
	login,
	password string,
) (contract.IAccount, string, error)

SignIn - sign in existing user

func (*AuthService) SignUp

func (a *AuthService) SignUp(
	ctx context.Context,
	login,
	password string,
) (contract.IAccount, string, error)

SignUp - sign up new user

type JwtTokenProvider

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

JwtTokenProvider - JWT Token Provider

func NewJwtTokenProvider

func NewJwtTokenProvider(tokenKey []byte, f func() time.Time) *JwtTokenProvider

NewJwtTokenProvider - Create new JWT Token Provider

func (*JwtTokenProvider) GenerateToken

func (j *JwtTokenProvider) GenerateToken(
	ctx context.Context,
	userID string,
) (string, error)

GenerateToken - Generate new token

func (*JwtTokenProvider) ValidateToken

func (j *JwtTokenProvider) ValidateToken(
	ctx context.Context,
	tokenString string,
) (string, error)

ValidateToken - Validate token

type PasswordService

type PasswordService struct{}

PasswordService - Password service

func (*PasswordService) ComparePassword

func (*PasswordService) ComparePassword(
	hashedPwd string,
	plainPwd []byte,
) (bool, error)

ComparePassword - Compare hashed password with plain password

func (*PasswordService) HashPassword

func (*PasswordService) HashPassword(pwd []byte) (string, error)

HashPassword - Hash and salt password

Jump to

Keyboard shortcuts

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