utils

package
v0.0.0-...-50f6f34 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPassword

func CheckPassword(password string, hash string) bool

CheckPassword method checks the inputted password against the hashed password to validate their hashed equivalence.

func CreateError

func CreateError(c *gin.Context, status int, errMessage string)

CreateError responds to client requests with error payloads.

func EncryptPassword

func EncryptPassword(password string) (string, error)

EncryptPassword method hashes the inputted password and returns whether or not the operation was successfull. Remark: the higher the hashing cost, the more computing power is required resulting in slower server response times

Types

type BasicAuthorizer

type BasicAuthorizer struct {
	Enforcer *casbin.Enforcer
}

BasicAuthorizer stores the casbin enforcer

func (*BasicAuthorizer) CheckPermission

func (a *BasicAuthorizer) CheckPermission(c *gin.Context) bool

CheckPermission checks the user/method/path combination from the request. Returns true (permission granted) or false (permission forbidden)

func (BasicAuthorizer) GetRoleName

func (BasicAuthorizer) GetRoleName(c *gin.Context) interface{}

GetRoleName gets the user name from the request. Currently, only HTTP basic authentication is supported

func (BasicAuthorizer) RequirePermission

func (BasicAuthorizer) RequirePermission(c *gin.Context)

RequirePermission returns the 403 Forbidden to the client

type HTTPError

type HTTPError struct {
	Code    int    `json:"code" example:"400"`
	Message string `json:"message" example:"Bad Request"`
}

HTTPError structure to define response payload on error.

type IBasicAuthorizer

type IBasicAuthorizer interface {
	GetRoleName(c *gin.Context) interface{}
	CheckPermission(c *gin.Context) bool
	RequirePermission(c *gin.Context)
}

IBasicAuthorizer interface.

Jump to

Keyboard shortcuts

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