acl

package
v0.0.0-...-b2c82e1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthAsAdminMiddleware

func AuthAsAdminMiddleware() echo.MiddlewareFunc

func AuthAsPlainMiddleware

func AuthAsPlainMiddleware(resources []string) echo.MiddlewareFunc

func BuildJwt

func BuildJwt(identity Identity) *jwt.Token

func CurrentToken

func CurrentToken(c echo.Context) (int, bool)

func GenerateJWTToken

func GenerateJWTToken(identity Identity, tokenID int, signingKey string, tokenExpiration int) (string, error)

func GenerateRefreshToken

func GenerateRefreshToken(identity Identity, signingKey string, rTokenExpiration int) (string, error)

func HasAccessToResource

func HasAccessToResource(c echo.Context, resource string) bool

HasAccessToResource checks if the current user has access to a specific resource.

func IsAdmin

func IsAdmin(c echo.Context) bool

func MockAuthHandler

func MockAuthHandler() echo.MiddlewareFunc

MockAuthHandler creates a mock authentication middleware for testing purpose. If the request contains an Authorization header whose value is "TEST", then it considers the user is authenticated as "Tester" whose ID is "100". It fails the authentication otherwise.

func MockAuthHeader

func MockAuthHeader() http.Header

MockAuthHeader returns an HTTP header that can pass the authentication check by MockAuthHandler.

Types

type Identity

type Identity interface {
	// GetID returns the user ID.
	GetID() string
	// GetName returns the user name.
	GetName() string
	IsAdmin() bool
	GetResources() []string
	IsPasswordChangeRequired() bool
}

Identity represents an authenticated user identity.

func CurrentUser

func CurrentUser(c echo.Context) Identity

CurrentUser returns the user identity from the given context. Nil is returned if no user identity is found in the context.

type JWTCustomClaims

type JWTCustomClaims struct {
	ID                       string   `json:"id"`
	Name                     string   `json:"name"`
	Admin                    bool     `json:"admin"`
	Resources                []string `json:"resources"`
	Token                    int      `json:"tid"`
	IsPasswordChangeRequired bool     `json:"change_password"`
	jwt.RegisteredClaims
}

type Middleware

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

func NewMiddleware

func NewMiddleware(checker *filter.Checker) *Middleware

func (*Middleware) TokenAndAccessCheckMiddleware

func (s *Middleware) TokenAndAccessCheckMiddleware(next echo.HandlerFunc) echo.HandlerFunc

TokenAndAccessCheckMiddleware is the middleware function.

Jump to

Keyboard shortcuts

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