auth

package
v0.0.0-...-a448e87 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StatusAuthFailure    = errors.New("auth: authencicated failed")
	ErrFailFindingUser   = errors.New("user: user not found")
	ErrDuplicateUsername = errors.New("user existed")
	ErrDuplicateEmail    = errors.New("user existed")
	ErrInvalidCredential = errors.New("auth: invalid credential")
	ErrTokenNotFound     = errors.New("auth: token not found")
	ErrInvalidToken      = errors.New("auth: invalid token")
	ErrSecretKeyNotfound = errors.New("auth: secret key not found")
)

Functions

This section is empty.

Types

type ContextKey

type ContextKey string

ContextKey string

type Engine

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

Engine is a struct aim to seperate gorm Connection from the rest of the logical code

func (Engine) API

func (e Engine) API() gin.HandlerFunc

API is a Authentication middleware for APIs

func (Engine) Auth

func (e Engine) Auth(u UserAuth) (string, error)

Auth authenticate a user. Return a tokenString and error

func (Engine) GetRequestCredential

func (e Engine) GetRequestCredential(tokenString string) (string, error)

GetRequestCredential get username from request Return (username, nil) if successfully, else return ("", error)

func (Engine) Validate

func (e Engine) Validate(uname, tokenString string) error

Validate user before accessing something Compare username that extract from tokenString and provided uname Return nil if validated, else return error

func (Engine) Verify

func (e Engine) Verify(u model.User) error

Verify if a user is existing. If yes, return Err, else return nil

func (Engine) View

func (e Engine) View() gin.HandlerFunc

View is a Authentication middleware for view

type IAuth

type IAuth interface {
	Auth(u UserAuth) (string, error)
	Verify(u model.User) error
	GetRequestCredential(tokenString string) (string, error)
	Validate(uname, tokenString string) error
	View() gin.HandlerFunc
	API() gin.HandlerFunc
}

func New

New create new instance of Authentication Engine

type UserAuth

type UserAuth struct {
	Username string `form:"username" binding:"required"`
	Password string `form:"password" binding:"required"`
}

UserAuth is a struct to get user data from login post

Jump to

Keyboard shortcuts

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