middleware

package
v0.0.0-...-108e80b Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildBitGroups

func BuildBitGroups(permIDs ...int) map[int]int

BuildBitGroups func builds bit-group that can contains so much permissions data inside with fast and effective with bit manipulations. See the example : permissions = {9:10,10:256} => read as : bit-group-9th, contains 2 permissions => read as : bit-group-10th, contains 8 permissions per group contain max 8 permissions sequentially, for more You can read in paper (for link, see in readme-md)

func CheckHasPermission

func CheckHasPermission(requirePermID int, userPermissions map[int]int) bool

CheckHasPermission func checks if bitGroups (map[int]int) contains require permission ID or not

Types

type Claims

type Claims struct {
	ID          int         `json:"id"`
	Email       string      `json:"email"`
	Role        string      `json:"role"`
	Permissions map[int]int `json:"permissions"`
	jwt.RegisteredClaims
}

Claims struct will be generated as token,contains user data like ID, email, role and permissions.

type JWTHandler

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

JWTHandler struct handles some key and redis connection The purpose of this is to handler and checking HTTP Header and/or checking is JWT blacklisted or not. See IsBlacklisted func.

func NewJWTHandler

func NewJWTHandler() *JWTHandler

NewJWTHandler func creates new JwtHandler struct

func (JWTHandler) CheckHasPermission

func (j JWTHandler) CheckHasPermission(endpointPermID int) func(c *fiber.Ctx) error

CheckHasPermission func is handler/middleware that called before the controller for checks the fiber ctx

func (JWTHandler) CheckHasRole

func (j JWTHandler) CheckHasRole(role string) func(c *fiber.Ctx) error

CheckHasRole func is handler/middleware that called before the controller for checks the fiber ctx

func (JWTHandler) GenerateClaims

func (j JWTHandler) GenerateClaims(cookieToken string) *Claims

GenerateClaims func generates claims struct from jwt.

func (*JWTHandler) GenerateJWT

func (j *JWTHandler) GenerateJWT(id int, email, role string, permissions map[int]int, expired time.Time) (t string, err error)

GenerateJWT func generate new token with expire time for user

func (JWTHandler) HasPermission

func (j JWTHandler) HasPermission(c *fiber.Ctx, endpointPermID int) error

HasPermission func extracts and checks for claims from fiber Ctx

func (JWTHandler) HasRole

func (j JWTHandler) HasRole(c *fiber.Ctx, role string) error

HasRole func check claims-role equal or not with require role

func (JWTHandler) InvalidateToken

func (j JWTHandler) InvalidateToken(c *fiber.Ctx) error

InvalidateToken func stores (blacklistings) token to redis. After storing token in redis, the token is already blacklisted. This func is used in Logout feature.

func (JWTHandler) IsAuthenticated

func (j JWTHandler) IsAuthenticated(c *fiber.Ctx) error

IsAuthenticated func extracts token from context (fiber Ctx), check is blacklisted or not. And checks the expire time too.

func (JWTHandler) IsBlacklisted

func (j JWTHandler) IsBlacklisted(cookie string) bool

IsBlacklisted func check the token/cookie is blacklisted or not.

Jump to

Keyboard shortcuts

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