mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-09 13:02:33 +02:00
enable auth by default with temporary random JWT
This commit is contained in:
parent
ee27237083
commit
651a7cf83e
3 changed files with 15 additions and 3 deletions
|
@ -82,7 +82,11 @@ func main() {
|
||||||
homepage.InitOverridesConfig,
|
homepage.InitOverridesConfig,
|
||||||
favicon.InitIconCache,
|
favicon.InitIconCache,
|
||||||
)
|
)
|
||||||
// logging.AddHook(notif.GetDispatcher())
|
|
||||||
|
if common.APIJWTSecret == nil {
|
||||||
|
logging.Warn().Msg("API_JWT_SECRET is not set, using random key")
|
||||||
|
common.APIJWTSecret = common.RandomJWTKey()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logging.DiscardLogger()
|
logging.DiscardLogger()
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/yusing/go-proxy/internal/common"
|
"github.com/yusing/go-proxy/internal/common"
|
||||||
"github.com/yusing/go-proxy/internal/logging"
|
|
||||||
"github.com/yusing/go-proxy/internal/net/gphttp"
|
"github.com/yusing/go-proxy/internal/net/gphttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -13,7 +12,6 @@ var defaultAuth Provider
|
||||||
// Initialize sets up authentication providers.
|
// Initialize sets up authentication providers.
|
||||||
func Initialize() error {
|
func Initialize() error {
|
||||||
if !IsEnabled() {
|
if !IsEnabled() {
|
||||||
logging.Warn().Msg("authentication is disabled, please set API_JWT_SECRET or OIDC_* to enable authentication")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
@ -16,3 +17,12 @@ func decodeJWTKey(key string) []byte {
|
||||||
}
|
}
|
||||||
return bytes
|
return bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RandomJWTKey() []byte {
|
||||||
|
key := make([]byte, 32)
|
||||||
|
_, err := rand.Read(key)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic().Err(err).Msg("failed to generate random jwt key")
|
||||||
|
}
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue