https://github.com/etkecc/go-echo-basic-auth
https://github.com/etkecc/go-echo-basic-auth
auth echo-framework library
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/etkecc/go-echo-basic-auth
- Owner: etkecc
- License: lgpl-3.0
- Created: 2024-08-08T18:55:16.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-22T16:18:06.000Z (about 1 year ago)
- Last Synced: 2025-04-22T17:36:07.897Z (about 1 year ago)
- Topics: auth, echo-framework, library
- Language: Go
- Size: 38.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# echo basic auth
Basic Auth middleware with constant time equality checks and optional IP whitelisting for Echo framework.
CIDRs are supported for IP whitelisting as well
## Usage
```go
auth := &echobasicauth.Auth{Login: "test", Password: "test", IPs: []string{"127.0.0.1", "10.0.0.0/24"}}
e.Use(echobasicauth.NewMiddleware(auth))
// or you can use echobasicauth.NewValidator(auth) if you want to define the middleware yourself
```
### IP validation without credentials
You can use `AllowedIP` directly to check if an IP is allowed without validating credentials:
```go
auth := &echobasicauth.Auth{IPs: []string{"127.0.0.1", "10.0.0.0/24"}}
if auth.AllowedIP(c.RealIP()) {
// IP is allowed
}
```