auth

package
v0.0.0-...-5b70f3c Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(cfg ...*Config) dawn.Moduler

New returns the module

Types

type CodeValidator

type CodeValidator interface {
	// Validate validates whether the code matched with the key
	Validate(key, code string) error
}

CodeValidator defences behaviors of a code validator

type Config

type Config struct {
	// Service is a custom service for auth module
	Service

	// SigningKey is for generating and validating jwt token
	SigningKey string

	// SigningMethod is used to check token signing method
	// Optional. Default: "HS256"
	// Possible values: "HS256", "HS384", "HS512", "ES256", "ES384", "ES512", "RS256", "RS384", "RS512"
	SigningMethod string

	// Expiration is the effective duration of jwt token
	Expiration time.Duration
}

Config defines the config for auth module

type Repo

type Repo interface {
	// RegisterByPassword gets a new user by username and password
	RegisterByPassword(username, pass string) (int, error)

	// RegisterByMobileCode gets a new user by mobile
	RegisterByMobile(mobile string) (int, error)

	// RegisterByEmailCode gets a new user by email
	RegisterByEmail(email string) (int, error)

	// LoginByPassword login system by username and password
	// and return user id if authentication success
	LoginByPassword(username, pass string) (int, error)

	// LoginByMobileCode login system by mobile number
	// and return user id if authentication success
	LoginByMobile(mobile string) (int, error)

	// LoginByEmailCode login system by email address
	// and return user id if authentication success
	LoginByEmail(email string) (int, error)
}

Repo is the repository interface for auth behaviors

type Service

type Service interface {
	// RegisterByPassword gets a new user by username and password
	RegisterByPassword(username, pass string) (int, error)

	// RegisterByMobileCode gets a new user by mobile and code
	RegisterByMobileCode(mobile, code string) (int, error)

	// RegisterByEmailCode gets a new user by email and code
	RegisterByEmailCode(email, code string) (int, error)

	// LoginByPassword login system by username and password
	// and return user id if authentication success
	LoginByPassword(username, pass string) (int, error)

	// LoginByMobileCode login system by mobile number and validate code
	// and return user id if authentication success
	LoginByMobileCode(mobile, code string) (int, error)

	// LoginByEmailCode login system by email address and validate code
	// and return user id if authentication success
	LoginByEmailCode(email, code string) (int, error)
}

Service defines auth behaviors

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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