security

package
v0.0.0-...-d6e685d Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FileTypeGif = "image/gif"
	FileTypePNG = "image/png"
	FileTypeJPG = "image/jpeg"
)
View Source
const (
	WritePost        = 'W' //
	UpdatePost       = 'U' //
	DelatePost       = 'R' //
	SiteConfig       = 'X' //
	UserManagement   = 'G' //
	BanUser          = 'B' //
	PublishPost      = 'P' //
	ControlOtherPost = "O" //
	UploadFiles      = 'L' //
)

Permision Const

Variables

This section is empty.

Functions

func CheckTokenPermissions

func CheckTokenPermissions(Need []rune, r *http.Request) (jwt.MapClaims, error)

From a Request it validates the token and the requested permissions and returns a jwt.MapClaims with the token data.

func CreateToken

func CreateToken(TokenInfo TokenStrocture) (string, error)

Create a token with a user's basic data

func ExtractToken

func ExtractToken(r *http.Request) string

ExtractToken

func GenerateRandomString

func GenerateRandomString(s int) (string, error)

Generates random String Not secure for cryptographic and related implementations

func GetIP

func GetIP(c *gin.Context) string

Get the ip depending on the configuration if the IpaddressByHeader configuration parameter has a value, it will be used to obtain the ip of that header

func GetUserAgent

func GetUserAgent(c *gin.Context) string

Get the user-agent and return it in EscapeString

func GetinfoToken

func GetinfoToken(tokenStr string) (jwt.MapClaims, error)

gets the token information and returns it in the form of jwt.MapClaims.

func IsImageMIME

func IsImageMIME(MIME string) bool

validated if image by mime

func OnlyCheckpermissions

func OnlyCheckpermissions(Permissions string, Need []rune) bool

Checks the permissions and compares them with those required to complete the task.

func PermissionsManager

func PermissionsManager()

func TokenValid

func TokenValid(r *http.Request) error

Only validate that the token is valid and has not expired.

func ValidationPermissions

func ValidationPermissions(Permissions string) bool

func VerifyToken

func VerifyToken(r *http.Request) (*jwt.Token, error)

This verifies that the token is valid from an http.Request.

Types

type TokenStrocture

type TokenStrocture struct {
	Email       string
	ID          string
	Uuid        uuid.UUID
	Permissions string
}

structure of a user token

Jump to

Keyboard shortcuts

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