Back to godoc.org

Package security

v0.0.0-...-80ad457
Latest Go to latest

The highest tagged major version is .

Published: Feb 4, 2020 | License: Unlicense | Module: github.com/javiercbk/ppv-crypto

Index

Constants

const (

	// ErrUserNotFound is returned when a jwt token was not found in the request context
	ErrUserNotFound UserNotFoundError = "user was not found in the request context"
	// ErrMalformedUser is returned when a user cannot be parsed from the JWT user
	ErrMalformedUser MalformedUserError = "user data is malformed"
	// Read is a permission that allows the user to read a resource
	Read permission = "read"
	// Write is a permission that allows the user to write a resource
	Write permission = "write"
)

func CanReadResouceMiddleware

func CanReadResouceMiddleware(jwtUser JWTUser, resouce string) echo.MiddlewareFunc

CanReadResouceMiddleware returns a middleware that validates if a user can read a resource

func CanWriteResouceMiddleware

func CanWriteResouceMiddleware(jwtUser JWTUser, resouce string) echo.MiddlewareFunc

CanWriteResouceMiddleware returns a middleware that validates if a user can read/write a resource

func JWTDecode

func JWTDecode(c echo.Context, jwtUser *JWTUser) error

JWTDecode attempt to decode a user

func JWTEncode

func JWTEncode(user JWTUser, d time.Duration) jwt.MapClaims

JWTEncode encodes a user into a jwt.MapClaims

func JWTMiddlewareFactory

func JWTMiddlewareFactory(jwtSecret string, optional bool) echo.MiddlewareFunc

JWTMiddlewareFactory creates a JWTMiddleware

type JWTUser

type JWTUser struct {
	ID          int64         `json:"id"`
	FirstName   string        `json:"firstName"`
	LastName    string        `json:"lastName"`
	Expiry      time.Time     `json:"expiry"`
	Permissions PermissionMap `json:"permissions"`
}

JWTUser is the data being encoded in the JWT token

type MalformedUserError

type MalformedUserError string

MalformedUserError is returned when a user cannot be parsed from the JWT user

func (MalformedUserError) Error

func (e MalformedUserError) Error() string

type PermissionMap

type PermissionMap map[string][]permission

PermissionMap is the user's permission map

func ToPermissionsMap

func ToPermissionsMap(permissions models.PermissionsUserSlice) PermissionMap

ToPermissionsMap creates a permissionsMap out of a PermissionsSlice

type UserNotFoundError

type UserNotFoundError string

UserNotFoundError is returned when a jwt token was not found in the request context

func (UserNotFoundError) Error

func (e UserNotFoundError) Error() string

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier