Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNilInterceptions = errors.New("nil interceptions") ErrInterceptionNotFound = errors.New("interception not found") )
View Source
var (
ErrCodeInterceptionNotFound string
)
Functions ¶
This section is empty.
Types ¶
type Authenticator ¶
type Authenticator interface {
AuthenticateFromHeader(
rpcMethod string,
) func(next http.Handler) http.Handler
AuthenticateFromCookie(
rpcMethod string,
) func(next http.Handler) http.Handler
}
Authenticator interface
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware struct is the authentication middleware for a REST API that is a gateway to a gRPC service.
func NewMiddleware ¶
func NewMiddleware( interceptions map[string]*gojwttoken.Token, responsesHandler gonethttphandler.ResponsesHandler, authenticator gonethttpmiddlewareauth.Authenticator, logger *slog.Logger, ) (*Middleware, error)
NewMiddleware creates a new instance of the authentication middleware.
Parameters:
- interceptions: A map of string keys to JWT tokens for interception purposes.
- responsesHandler: An instance of a ResponsesHandler to manage HTTP responses.
- authenticator: An instance of an Authenticator to handle authentication logic.
- logger: A pointer to a slog.Logger for logging purposes.
Returns:
- *Middleware: A pointer to the newly created Middleware instance.
- error: An error if the middleware could not be created.
func (Middleware) AuthenticateFromCookie ¶
func (m Middleware) AuthenticateFromCookie( rpcMethod string, ) func(next http.Handler) http.Handler
AuthenticateFromCookie is a middleware function that authenticates requests based on the provided RPC method using tokens from cookies.
Parameters:
- rpcMethod: The RPC method to authenticate against.
Returns:
- func(next http.Handler) http.Handler: A middleware function that authenticates requests.
func (Middleware) AuthenticateFromHeader ¶
func (m Middleware) AuthenticateFromHeader( rpcMethod string, ) func(next http.Handler) http.Handler
AuthenticateFromHeader is a middleware function that authenticates requests based on the provided RPC method using tokens from the request header.
Parameters:
- rpcMethod: The RPC method to authenticate against.
Returns:
- func(next http.Handler) http.Handler: A middleware function that authenticates requests.
Click to show internal directories.
Click to hide internal directories.