https://github.com/bootjp/echo_middleware_path_auth
middleware for path-based authentication of labstack echo. Best when using apikey for path.
https://github.com/bootjp/echo_middleware_path_auth
echo-framework echo-middleware golang-library
Last synced: 11 months ago
JSON representation
middleware for path-based authentication of labstack echo. Best when using apikey for path.
- Host: GitHub
- URL: https://github.com/bootjp/echo_middleware_path_auth
- Owner: bootjp
- License: mit
- Created: 2022-11-08T08:28:45.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-02-09T03:24:11.000Z (12 months ago)
- Last Synced: 2025-02-28T03:41:38.457Z (11 months ago)
- Topics: echo-framework, echo-middleware, golang-library
- Language: Go
- Homepage:
- Size: 75.2 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# echo_middleware_path_auth
middleware for path-based authentication of labstack echo. Best when using apikey for path.
example) https://example.com/api/this_is_api_key
This `this_is_api_key` part can be dynamically submitted to authentication.
For example, whether apikey is active, RateLimit is not exceeded, etc.
Much of this code is based on [key_auth.go in labstack/echo and its test code](https://github.com/labstack/echo/blob/01d7d01bbc1948cd308b2ae93a131654e6dba195/middleware/key_auth.go).
## Badges
[](https://choosealicense.com/licenses/mit/)
[](https://github.com/bootjp/echo_middleware_path_auth/actions/workflows/test.yml)
## Usage/Examples
```go
package main
import (
pa "github.com/bootjp/echo_middleware_path_auth"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func main() {
e := echo.New()
// group route
e.Group("/api/:apikey", pa.PathAuth("apikey", func(auth string, c echo.Context) (bool, error) {
// add your logic
return true, nil
}))
// single route
yourHttpHandler := func(c echo.Context) error { return c.String(200, "OK") }
yourPathAuthLogic := func(auth string, c echo.Context) (bool, error) {
return true, nil
}
e.GET("/api/:apikey", yourHttpHandler, pa.PathAuth("apikey", yourPathAuthLogic))
// with config
config := pa.PathAuthConfig{}
config.Skipper = middleware.DefaultSkipper
config.Param = "apikey"
config.Validator = yourPathAuthLogic
e.GET("/api/:apikey", yourHttpHandler, pa.PathAuthWithConfig(config))
}
```