middleware

package
v0.0.0-...-4024313 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Authorization             = "Authorization"
	ClientSecret              = "Client-Secret"
	ContentType               = "Content-Type"
	AccessControlAllowOrigin  = "Access-Control-Allow-Origin"
	AccessControlAllowHeaders = "Access-Control-Allow-Headers"
	ScopeSecret               = "secret"
	ScopeJwt                  = "jwt"
)

Http Header, Request scope const

Variables

This section is empty.

Functions

func BindBody

func BindBody(w http.ResponseWriter, r *http.Request, i interface{}) *model.ErrorResBody

Bind request body what http request converts to interface

func ParamGroupUuid

func ParamGroupUuid(r *http.Request) string

Parse request group_uuid of path parameter

func ValidateBody

func ValidateBody(w http.ResponseWriter, i interface{}) *model.ErrorResBody

Validate request body

func ValidateTokenRequest

func ValidateTokenRequest(w http.ResponseWriter, tokenRequest *model.TokenRequest) *model.ErrorResBody

Validate request body

Types

type Interceptor

type Interceptor interface {
	// Intercept Http request and Client-Secret header
	Intercept(next http.HandlerFunc) http.HandlerFunc

	// InterceptSecret
	// Intercept only http header
	InterceptSecret(next http.HandlerFunc) http.HandlerFunc

	// InterceptAuthenticateUser
	// Intercept Http request and Client-Secret header with user authentication
	InterceptAuthenticateUser(next http.HandlerFunc) http.HandlerFunc

	// InterceptAuthenticateGroupAdmin
	// Intercept Http request and Client-Secret header with user and group admin role authentication
	InterceptAuthenticateGroupAdmin(next http.HandlerFunc) http.HandlerFunc

	// InterceptAuthenticateGroupUser
	// Intercept Http request and Client-Secret header with user and group user role authentication
	InterceptAuthenticateGroupUser(next http.HandlerFunc) http.HandlerFunc

	// InterceptAuthenticateOperator
	// Intercept Http request and Client-Secret header with operator authentication
	InterceptAuthenticateOperator(next http.HandlerFunc) http.HandlerFunc
}

func GetInterceptorInstance

func GetInterceptorInstance() Interceptor

func NewInterceptor

func NewInterceptor() Interceptor

type InterceptorImpl

type InterceptorImpl struct {
	// contains filtered or unexported fields
}

func (InterceptorImpl) Intercept

func (i InterceptorImpl) Intercept(next http.HandlerFunc) http.HandlerFunc

func (InterceptorImpl) InterceptAuthenticateGroupAdmin

func (i InterceptorImpl) InterceptAuthenticateGroupAdmin(next http.HandlerFunc) http.HandlerFunc

func (InterceptorImpl) InterceptAuthenticateGroupUser

func (i InterceptorImpl) InterceptAuthenticateGroupUser(next http.HandlerFunc) http.HandlerFunc

func (InterceptorImpl) InterceptAuthenticateOperator

func (i InterceptorImpl) InterceptAuthenticateOperator(next http.HandlerFunc) http.HandlerFunc

func (InterceptorImpl) InterceptAuthenticateUser

func (i InterceptorImpl) InterceptAuthenticateUser(next http.HandlerFunc) http.HandlerFunc

func (InterceptorImpl) InterceptSecret

func (i InterceptorImpl) InterceptSecret(next http.HandlerFunc) http.HandlerFunc

type Migration

type Migration struct {
	// contains filtered or unexported fields
}

func NewMigration

func NewMigration() Migration

func (Migration) V1

func (m Migration) V1()

type TokenProcessor

type TokenProcessor interface {
	// Generate jwt token
	Generate(userType string, tokenRequest model.TokenRequest) (*model.TokenResponse, *model.ErrorResBody)

	// Verify operator token
	VerifyOperatorToken(token string) (*model.JwtPayload, *model.ErrorResBody)

	// Verify user token
	VerifyUserToken(token string, roleNames string, permissionNames string, groupUuid string) (*model.JwtPayload, *model.ErrorResBody)

	// Get auth user data in token
	// If invalid token, return 401
	GetJwtPayload(token string, isRefresh bool) (*model.JwtPayload, *model.ErrorResBody)
}

func GetTokenProcessorInstance

func GetTokenProcessorInstance() TokenProcessor

Get TokenProcessor instance. If use singleton pattern, call this instance method

func NewTokenProcessor

func NewTokenProcessor() TokenProcessor

Constructor

type TokenProcessorImpl

type TokenProcessorImpl struct {
	UserService           service.UserService
	OperatorPolicyService service.OperatorPolicyService
	Service               service.Service
	PolicyService         service.PolicyService
	RoleService           service.RoleService
	PermissionService     service.PermissionService
	ServerConfig          common.ServerConfig
	Token                 *jwt.Token
}

TokenProcessor struct

func (TokenProcessorImpl) Generate

func (tp TokenProcessorImpl) Generate(userType string, tokenRequest model.TokenRequest) (*model.TokenResponse, *model.ErrorResBody)

func (TokenProcessorImpl) GetJwtPayload

func (tp TokenProcessorImpl) GetJwtPayload(token string, isRefresh bool) (*model.JwtPayload, *model.ErrorResBody)

func (TokenProcessorImpl) VerifyOperatorToken

func (tp TokenProcessorImpl) VerifyOperatorToken(token string) (*model.JwtPayload, *model.ErrorResBody)

func (TokenProcessorImpl) VerifyUserToken

func (tp TokenProcessorImpl) VerifyUserToken(token string, roleNames string, permissionNames string, groupUuid string) (*model.JwtPayload, *model.ErrorResBody)

Jump to

Keyboard shortcuts

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