middleware

package
v1.6.39 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: MIT Imports: 15 Imported by: 12

Documentation

Overview

Package middleware contains:

- CORS - Application firewall - Pongo2 template engine - JWT - Sentry logger - Two-factor auth validator

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORS

func CORS(cp []CORSPolicy) gin.HandlerFunc

CORS - Cross-Origin Resource Sharing

func CheckOrigin added in v1.6.27

func CheckOrigin() gin.HandlerFunc

CheckOrigin - check whether the request generated from the allowed origin

func ConvertContext added in v1.6.6

func ConvertContext(thing interface{}) pongo2.Context

ConvertContext function converts the input map to a pongo2.Context type and preserves the key-value pairs

func Firewall added in v1.4.0

func Firewall(listType string, ipList string) gin.HandlerFunc

Firewall - whitelist/blacklist IPs

func GetJWT

func GetJWT(customClaims MyCustomClaims, tokenType string) (string, string, error)

GetJWT - issue new tokens

func JWT

func JWT() gin.HandlerFunc

JWT - validate access token

func Pongo2 added in v1.4.0

func Pongo2(baseDirectory string) gin.HandlerFunc

Pongo2 uses the Pongo2 template library https://github.com/flosch/pongo2 to render templates

Example: baseDirectory = "templates/"

func RateLimit added in v1.6.27

func RateLimit(limiterInstance *limiter.Limiter) gin.HandlerFunc

RateLimit - rate limit middleware

func RefreshJWT added in v1.2.5

func RefreshJWT() gin.HandlerFunc

RefreshJWT - validate refresh token

func SentryCapture added in v1.2.4

func SentryCapture(sentryDsn string, v ...string) gin.HandlerFunc

SentryCapture - capture errors and forward to sentry.io

required parameter (1st parameter): sentryDsn

optional parameter (2nd parameter): environment (development or production)

optional parameter (3rd parameter): release version or git commit number

optional parameter (4th parameter): enableTracing (yes or no)

optional parameter (5th parameter): tracesSampleRate (0.0 - 1.0)

func StringFromContext added in v1.6.6

func StringFromContext(c *gin.Context, input string) string

StringFromContext function retrieves the value from the context and returns it as a string

func TwoFA added in v1.6.1

func TwoFA(keywordOn, keywordOff, keywordVerified string) gin.HandlerFunc

TwoFA validates 2-FA status from JWT before forwarding the request to the controller

func ValidateAccessJWT added in v1.6.12

func ValidateAccessJWT(token *jwt.Token) (interface{}, error)

ValidateAccessJWT - verify the access JWT's signature, and validate its claims

func ValidateECDSA added in v1.6.15

func ValidateECDSA(token *jwt.Token) (interface{}, error)

ValidateECDSA - validate elliptic curve digital signature algorithm based token

func ValidateHMACAccess added in v1.6.15

func ValidateHMACAccess(token *jwt.Token) (interface{}, error)

ValidateHMACAccess - validate hash based access token

func ValidateHMACRefresh added in v1.6.15

func ValidateHMACRefresh(token *jwt.Token) (interface{}, error)

ValidateHMACRefresh - validate hash based refresh token

func ValidateRSA added in v1.6.15

func ValidateRSA(token *jwt.Token) (interface{}, error)

ValidateRSA - validate Rivest–Shamir–Adleman cryptosystem based token

func ValidateRefreshJWT added in v1.6.12

func ValidateRefreshJWT(token *jwt.Token) (interface{}, error)

ValidateRefreshJWT - verify the refresh JWT's signature, and validate its claims

Types

type CORSPolicy added in v1.6.2

type CORSPolicy struct {
	Key   string
	Value string
}

CORSPolicy struct to handle all policies

type JWTClaims added in v1.5.1

type JWTClaims struct {
	MyCustomClaims
	jwt.RegisteredClaims
}

JWTClaims ...

type JWTParameters added in v1.6.1

type JWTParameters struct {
	Algorithm     string
	AccessKey     []byte
	AccessKeyTTL  int
	RefreshKey    []byte
	RefreshKeyTTL int
	PrivKeyECDSA  *ecdsa.PrivateKey
	PubKeyECDSA   *ecdsa.PublicKey
	PrivKeyRSA    *rsa.PrivateKey
	PubKeyRSA     *rsa.PublicKey

	Audience string
	Issuer   string
	AccNbf   int
	RefNbf   int
	Subject  string
}

JWTParameters - params to configure JWT

var JWTParams JWTParameters

JWTParams - exported variables

type JWTPayload added in v1.2.5

type JWTPayload struct {
	AccessJWT   string `json:"accessJWT,omitempty"`
	RefreshJWT  string `json:"refreshJWT,omitempty"`
	TwoAuth     string `json:"twoFA,omitempty"`
	RecoveryKey string `json:"recoveryKey,omitempty"`
}

JWTPayload ...

type MyCustomClaims

type MyCustomClaims struct {
	AuthID  uint64 `json:"authID,omitempty"`
	Email   string `json:"email,omitempty"`
	Role    string `json:"role,omitempty"`
	Scope   string `json:"scope,omitempty"`
	TwoFA   string `json:"twoFA,omitempty"`
	SiteLan string `json:"siteLan,omitempty"`
	Custom1 string `json:"custom1,omitempty"`
	Custom2 string `json:"custom2,omitempty"`
}

MyCustomClaims ...

Jump to

Keyboard shortcuts

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