auth

package
v0.0.0-...-0eef1dd Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewVerifyCode

func NewVerifyCode(n int) string

NewVerifyCode returns a verification code with specified length. the bigger n is, the conflicts will be less, the recommended n is 8.

Types

type AuthHandler

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

AuthHandler is responsible for user authentication

func NewAuthHandler

func NewAuthHandler(userRepo *repo.UserRepo, tokenHandler *TokenHandler, verify *VerifyCodeHandler) *AuthHandler

func (*AuthHandler) EncryptPassword

func (a *AuthHandler) EncryptPassword(s string) string

EncryptPassword encrypts password with sha512

func (*AuthHandler) LoginWithPassword

func (a *AuthHandler) LoginWithPassword(ctx context.Context, option auth.LoginOption) (*auth.TokenPair, error)

LoginWithPassword user login by password

func (*AuthHandler) RegisterNewUser

func (a *AuthHandler) RegisterNewUser(ctx context.Context, option auth.RegisterOption) (*ent.User, error)

RegisterNewUser registers new user and returns it

func (*AuthHandler) ResetPassword

func (a *AuthHandler) ResetPassword(ctx context.Context, option auth.ResetPasswordOption) error

ResetPassword resets specified user password and returns uid

type TokenHandler

type TokenHandler struct {
	JwtConf conf.Jwt
	// contains filtered or unexported fields
}

TokenHandler is responsible for maintaining authentication tokens

func NewTokenHandler

func NewTokenHandler(jwtConf conf.Jwt, client *redis.Client) *TokenHandler

func (*TokenHandler) Issue

func (t *TokenHandler) Issue(ctx context.Context, payload auth.TokenPayload, refresh bool) (auth.TokenPair, error)

func (*TokenHandler) Refresh

func (t *TokenHandler) Refresh(ctx context.Context, accessToken string, refreshToken string) (auth.TokenPair, error)

Refresh refreshes the access token lifetime with the given refresh token

func (*TokenHandler) VerifyAccess

func (t *TokenHandler) VerifyAccess(ctx context.Context, token string, now time.Time) (auth.Token, error)

VerifyAccess verifies the access token if is valid and parses the payload in the token.

func (*TokenHandler) VerifyRefresh

func (t *TokenHandler) VerifyRefresh(ctx context.Context, token string) (auth.Token, error)

VerifyRefresh verifies the refresh token if is valid.

type VerifyCodeHandler

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

func NewVerifyCodeHandler

func NewVerifyCodeHandler(codeCache cache.VerifyCodeCache, sender *email.Handler) *VerifyCodeHandler

func (*VerifyCodeHandler) CheckVerifyCode

func (v *VerifyCodeHandler) CheckVerifyCode(ctx context.Context, to, code string, usage auth.Usage) error

CheckVerifyCode check verify code if is valid

func (*VerifyCodeHandler) RemoveVerifyCode

func (v *VerifyCodeHandler) RemoveVerifyCode(ctx context.Context, code string, usage auth.Usage) error

func (*VerifyCodeHandler) SendVerifyCodeEmail

func (v *VerifyCodeHandler) SendVerifyCodeEmail(ctx context.Context, to string, usage auth.Usage) error

SendVerifyCodeEmail send a verify code email to the specified address

Jump to

Keyboard shortcuts

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