Documentation ¶
Index ¶
- func AuthAsAdminMiddleware() echo.MiddlewareFunc
- func AuthAsPlainMiddleware(resources []string) echo.MiddlewareFunc
- func BuildJwt(identity Identity) *jwt.Token
- func CurrentToken(c echo.Context) (int, bool)
- func GenerateJWTToken(identity Identity, tokenID int, signingKey string, tokenExpiration int) (string, error)
- func GenerateRefreshToken(identity Identity, signingKey string, rTokenExpiration int) (string, error)
- func HasAccessToResource(c echo.Context, resource string) bool
- func IsAdmin(c echo.Context) bool
- func MockAuthHandler() echo.MiddlewareFunc
- func MockAuthHeader() http.Header
- type Identity
- type JWTCustomClaims
- type Middleware
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 CurrentToken ¶
func GenerateJWTToken ¶
func GenerateRefreshToken ¶
func HasAccessToResource ¶
HasAccessToResource checks if the current user has access to a specific resource.
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 ¶
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 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.