feat: web support http basic authorization (#170)

This commit is contained in:
Levi authored and GitHub committed 2023-07-27 21:02:33 +08:00
1 parent 7c2b81caf7
commit 81518d794f
5 files changed
+179 -18

No files matched your search

+18 -3
View File
@@ -1,6 +1,9 @@
package model
import "io/fs"
import (
"encoding/base64"
"io/fs"
)
type Storage string
@@ -17,8 +20,9 @@ type StartConfig struct {
StorageDir string `json:"storageDir"`
ApiToken string `json:"apiToken"`
WebEnable bool
WebFS fs.FS
WebEnable bool
WebFS fs.FS
WebBasicAuth *WebBasicAuth
}
func (cfg *StartConfig) Init() *StartConfig {
@@ -39,3 +43,14 @@ func (cfg *StartConfig) Init() *StartConfig {
}
return cfg
}
type WebBasicAuth struct {
Username string
Password string
}
// Authorization returns the value of the Authorization header to be used in HTTP requests.
func (cfg *WebBasicAuth) Authorization() string {
userId := cfg.Username + ":" + cfg.Password
return "Basic " + base64.StdEncoding.EncodeToString([]byte(userId))
}