Documentation
¶
Index ¶
- func BuildBitGroups(permIDs ...int) map[int]int
- func CheckHasPermission(requirePermID int, userPermissions map[int]int) bool
- type Claims
- type JWTHandler
- func (j JWTHandler) CheckHasPermission(endpointPermID int) func(c *fiber.Ctx) error
- func (j JWTHandler) CheckHasRole(role string) func(c *fiber.Ctx) error
- func (j JWTHandler) GenerateClaims(cookieToken string) *Claims
- func (j *JWTHandler) GenerateJWT(id int, email, role string, permissions map[int]int, expired time.Time) (t string, err error)
- func (j JWTHandler) HasPermission(c *fiber.Ctx, endpointPermID int) error
- func (j JWTHandler) HasRole(c *fiber.Ctx, role string) error
- func (j JWTHandler) InvalidateToken(c *fiber.Ctx) error
- func (j JWTHandler) IsAuthenticated(c *fiber.Ctx) error
- func (j JWTHandler) IsBlacklisted(cookie string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildBitGroups ¶
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)
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.