services

package
v0.0.0-...-f805a98 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2022 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 AccessTokenCustomClaims

type AccessTokenCustomClaims struct {
	UserID  string
	KeyType string
	jwt.StandardClaims
}

AccessTokenCustomClaims specifies the claims for access token

type AuthService

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

AuthService is the implementation of our Authentication

func NewAuthService

func NewAuthService(logger zap.Logger, configs *utils.Configurations) *AuthService

NewAuthService returns a new instance of the auth service

func (*AuthService) Authenticate

func (auth *AuthService) Authenticate(reqUser *models.User, user *models.User) bool

Authenticate checks the user credentials in request against the db and authenticates the request

func (*AuthService) GenerateAccessToken

func (auth *AuthService) GenerateAccessToken(user *models.User) (string, error)

GenerateAccessToken generates a new access token for the given user

func (*AuthService) GenerateCustomKey

func (auth *AuthService) GenerateCustomKey(userID string, tokenHash string) string

GenerateCustomKey creates a new key for our jwt payload the key is a hashed combination of the userID and user tokenhash

func (*AuthService) GenerateRefreshToken

func (auth *AuthService) GenerateRefreshToken(user *models.User) (string, error)

GenerateRefreshToken generate a new refresh token for the given user

func (*AuthService) ValidateAccessToken

func (auth *AuthService) ValidateAccessToken(tokenString string) (string, error)

ValidateAccessToken parses and validates the given access token returns the userId present in the token payload

func (*AuthService) ValidateRefreshToken

func (auth *AuthService) ValidateRefreshToken(tokenString string) (string, string, error)

ValidateRefreshToken parses and validates the given refresh token returns the userId and customkey present in the token payload

type Authentication

type Authentication interface {
	Authenticate(reqUser *models.User, user *models.User) bool
	GenerateAccessToken(user *models.User) (string, error)
	GenerateRefreshToken(user *models.User) (string, error)
	GenerateCustomKey(userID string, password string) string
	ValidateAccessToken(token string) (string, error)
	ValidateRefreshToken(token string) (string, string, error)
}

Authentication interface lists the methods that our authentication service should implement

type Mail

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

Mail represents a email request

type MailData

type MailData struct {
	Username string
	Code     string
}

MailData represents the data to be sent to the template of the mail.

type MailService

type MailService interface {
	CreateMail(mailReq *Mail) []byte
	SendMail(mailReq *Mail) error
	NewMail(from string, to []string, subject string, mailType MailType, data *MailData) *Mail
}

MailService represents the interface for our mail service.

type MailType

type MailType int
const (
	MailConfirmation MailType = iota + 1
	PassReset
)

List of Mail Types we are going to send.

type RefreshTokenCustomClaims

type RefreshTokenCustomClaims struct {
	UserID    string
	CustomKey string
	KeyType   string
	jwt.StandardClaims
}

RefreshTokenCustomClaims specifies the claims for refresh token

type SGMailService

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

SGMailService is the sendgrid implementation of our MailService.

func NewSGMailService

func NewSGMailService(logger zap.Logger, configs *utils.Configurations) *SGMailService

NewSGMailService returns a new instance of SGMailService

func (*SGMailService) CreateMail

func (ms *SGMailService) CreateMail(mailReq *Mail) []byte

CreateMail takes in a mail request and constructs a sendgrid mail type.

func (*SGMailService) NewMail

func (ms *SGMailService) NewMail(from string, to []string, subject string, mailType MailType, data *MailData) *Mail

NewMail returns a new mail request.

func (*SGMailService) SendMail

func (ms *SGMailService) SendMail(mailReq *Mail) error

SendMail creates a sendgrid mail from the given mail request and sends it.

Jump to

Keyboard shortcuts

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