middleware

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: MIT Imports: 10 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 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 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) gin.HandlerFunc

SentryCapture - capture errors and forward to sentry.io

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

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.StandardClaims
}

JWTClaims ...

type JWTParameters added in v1.6.1

type JWTParameters struct {
	AccessKey     []byte
	AccessKeyTTL  int
	RefreshKey    []byte
	RefreshKeyTTL int

	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"`
}

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