Documentation ¶
Overview ¶
Package middleware contains:
- CORS - Application firewall - Pongo2 template engine - JWT - Sentry logger - Two-factor auth validator
Index ¶
- func CORS(cp []CORSPolicy) gin.HandlerFunc
- func CheckOrigin() gin.HandlerFunc
- func ConvertContext(thing interface{}) pongo2.Context
- func Firewall(listType string, ipList string) gin.HandlerFunc
- func GetJWT(customClaims MyCustomClaims, tokenType string) (string, string, error)
- func InitSentry(sentryDsn string, v ...string) (*sentry.Hook, error)
- func JWT() gin.HandlerFunc
- func Pongo2(baseDirectory string) gin.HandlerFunc
- func RateLimit(limiterInstance *limiter.Limiter) gin.HandlerFunc
- func RefreshJWT() gin.HandlerFunc
- func SentryCapture(sentryDsn string, v ...string) gin.HandlerFunc
- func StringFromContext(c *gin.Context, input string) string
- func TwoFA(keywordOn, keywordOff, keywordVerified string) gin.HandlerFunc
- func ValidateAccessJWT(token *jwt.Token) (interface{}, error)
- func ValidateECDSA(token *jwt.Token) (interface{}, error)
- func ValidateHMACAccess(token *jwt.Token) (interface{}, error)
- func ValidateHMACRefresh(token *jwt.Token) (interface{}, error)
- func ValidateRSA(token *jwt.Token) (interface{}, error)
- func ValidateRefreshJWT(token *jwt.Token) (interface{}, error)
- type CORSPolicy
- type JWTClaims
- type JWTParameters
- type JWTPayload
- type MyCustomClaims
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 InitSentry ¶ added in v1.6.40
InitSentry - initialize sentry for middleware or separate goroutines
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 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 - sentry middleware to 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
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
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 ...