feat: "local only" automatic authentication

Often you want to expose your library publicly, which requires
authentication to prevent unknown users from seeing your
content.

In my case, I also expose the library on a local domain using a local DNS server which doesn't have these security issues.

This change adds a `local_only` option to the feed auth
config which will only supply the provided username/password
when the request comes from a private IP address.

Omitting `local_only` or setting to false will keep the current
logic of sending the credentials no matter the origin of the
request.
This commit is contained in:
Evan Buss
2024-08-10 21:13:57 +00:00
parent ccc6217014
commit e21a648506
4 changed files with 80 additions and 31 deletions

13
main.go
View File

@@ -28,10 +28,15 @@ type AuthConfig struct {
}
type FeedConfig struct {
Name string `koanf:"name"`
Url string `koanf:"url"`
Username string `koanf:"username"`
Password string `koanf:"password"`
Name string `koanf:"name"`
Url string `koanf:"url"`
Auth *FeedConfigAuth `koanf:"auth"`
}
type FeedConfigAuth struct {
Username string `koanf:"username"`
Password string `koanf:"password"`
LocalOnly bool `koanf:"local_only"`
}
func main() {