gql

package
v0.7.99 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlgorithmHS256 = "HS256"
)
View Source
const FiberContextKey = "FiberContextKey"

Variables

View Source
var JWTconfig = JWTConfig{
	Skipper:       DefaultSkipper,
	SigningMethod: AlgorithmHS256,
	ContextKey:    "user",
	TokenLookup:   "header:Authorization,",
	AuthScheme:    "Bearer",
	Claims:        jwt.MapClaims{},
}

Functions

func Auth

func Auth(c *fiber.Ctx) (jwt.Claims, error)

func CheckAuth

func CheckAuth(ctx context.Context, roles []int) (jwt.MapClaims, error)

func CheckColumns

func CheckColumns(column string, columns []string) error

func DefaultSkipper

func DefaultSkipper(*fiber.Ctx) bool

func Filter

func Filter(filtersPre interface{}, query *gorm.DB, columns []string) (*gorm.DB, error)

func GetNestedPreloads

func GetNestedPreloads(ctx *graphql.OperationContext, fields []graphql.CollectedField, prefix string) (preloads []string)

func GetPaginationTargetAndColumns

func GetPaginationTargetAndColumns(ctx context.Context) (string, []string, error)

func GetPreloadString

func GetPreloadString(prefix, name string) string

func GetPreloads

func GetPreloads(ctx context.Context) []string

func GetRole

func GetRole(role interface{}) int

func GroupFilter

func GroupFilter(filterGroupsPre interface{}, queryMain *gorm.DB, columns []string) (*gorm.DB, error)

func IsLoggedIn

func IsLoggedIn(c *fiber.Ctx) (jwt.Claims, error)

func JWTFromCookie

func JWTFromCookie(name string, c *fiber.Ctx) (string, error)

func JWTFromHeader

func JWTFromHeader(header string, authScheme string, c *fiber.Ctx) (string, error)

func Order

func Order(sortsPre interface{}, query *gorm.DB, columns []string) (*gorm.DB, error)

func ParseToken

func ParseToken(auth string, c *fiber.Ctx) (jwt.Claims, error)

func Process

func Process() fiber.Handler

func RandString

func RandString(n int) string

func RemoveDuplicate

func RemoveDuplicate(intSlice []string) []string

Types

type BeforeFunc

type BeforeFunc func(*fiber.Ctx)

BeforeFunc defines a function which is executed just before the middleware.

type CustomContext

type CustomContext struct {
	*fiber.Ctx
	// contains filtered or unexported fields
}

type JWTConfig

type JWTConfig struct {
	// Skipper defines a function to skip middleware.
	Skipper Skipper

	// BeforeFunc defines a function which is executed just before the middleware.
	BeforeFunc BeforeFunc

	// SuccessHandler defines a function which is executed for a valid token.
	SuccessHandler JWTSuccessHandler

	// ErrorHandler defines a function which is executed for an invalid token.
	// It may be used to define a custom JWT error.
	ErrorHandler JWTErrorHandler

	// ErrorHandlerWithContext is almost identical to ErrorHandler, but it's passed the current context.
	ErrorHandlerWithContext JWTErrorHandlerWithContext

	// Signing key to validate token. Used as fallback if SigningKeys has length 0.
	// Required. This or SigningKeys.
	SigningKey interface{}

	// Map of signing keys to validate token with kid field usage.
	// Required. This or SigningKey.
	SigningKeys map[string]interface{}

	// Signing method, used to check token signing method.
	// Optional. Default value HS256.
	SigningMethod string

	// Context key to store user information from the token into context.
	// Optional. Default value "user".
	ContextKey string

	// Claims are extendable claims data defining token content.
	// Optional. Default value jwt.MapClaims
	Claims jwt.Claims

	// TokenLookup is a string in the form of "<source>:<name>" that is used
	// to extract token from the request.
	// Optional. Default value "header:Authorization".
	// Possible values:
	// - "header:<name>"
	// - "query:<name>"
	// - "param:<name>"
	// - "cookie:<name>"
	TokenLookup string

	// AuthScheme to be used in the Authorization header.
	// Optional. Default value "Bearer".
	AuthScheme string
	// contains filtered or unexported fields
}

JWTConfig defines the config for JWT middleware.

type JWTErrorHandler

type JWTErrorHandler func(error) error

JWTErrorHandler defines a function which is executed for an invalid token.

type JWTErrorHandlerWithContext

type JWTErrorHandlerWithContext func(error, *fiber.Ctx) error

JWTErrorHandlerWithContext is almost identical to JWTErrorHandler, but it's passed the current context.

type JWTSuccessHandler

type JWTSuccessHandler func(*fiber.Ctx)

JWTSuccessHandler defines a function which is executed for a valid token.

type Skipper

type Skipper func(*fiber.Ctx) bool

Skipper defines a function to skip middleware. Returning true skips processing the middleware.

type Sub

type Sub struct {
	Table   string
	Columns []string
}

func GetColumns

func GetColumns(ctx context.Context, prefix string) ([]string, []Sub)

func GetSubTables

func GetSubTables(ctx context.Context, Field graphql.CollectedField, subTable string) []Sub

Jump to

Keyboard shortcuts

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