mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 12:42:34 +02:00

* implement OIDC middleware * auth code cleanup * allow override allowed_user in middleware, fix typos * fix tests and callbackURL * update next release docs * fix OIDC middleware not working with Authentik * feat: add groups support for OIDC claims (#41) Allow users to specify allowed groups in the env and use it to inspect the claims. This performs a logical AND of users and groups (additive). * merge feat/oidc-middleware (#49) * api: enrich provider statistifcs * fix: docker monitor now uses container status * Feat/auto schemas (#48) * use auto generated schemas * go version bump and dependencies upgrade * clarify some error messages --------- Co-authored-by: yusing <yusing@6uo.me> * cleanup some loadbalancer code * api: cleanup websocket code * api: add /v1/health/ws for health bubbles on dashboard * feat: experimental memory logger and logs api for WebUI --------- Co-authored-by: yusing <yusing@6uo.me> --------- Co-authored-by: yusing <yusing@6uo.me> Co-authored-by: Peter Olds <peter@olds.co>
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package auth
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
U "github.com/yusing/go-proxy/internal/api/v1/utils"
|
|
"github.com/yusing/go-proxy/internal/common"
|
|
"github.com/yusing/go-proxy/internal/logging"
|
|
)
|
|
|
|
var defaultAuth Provider
|
|
|
|
// Initialize sets up authentication providers.
|
|
func Initialize() error {
|
|
if !IsEnabled() {
|
|
logging.Warn().Msg("authentication is disabled, please set API_JWT_SECRET or OIDC_* to enable authentication")
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
// Initialize OIDC if configured.
|
|
if common.OIDCIssuerURL != "" {
|
|
defaultAuth, err = NewOIDCProviderFromEnv()
|
|
} else {
|
|
defaultAuth, err = NewUserPassAuthFromEnv()
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func GetDefaultAuth() Provider {
|
|
return defaultAuth
|
|
}
|
|
|
|
func IsEnabled() bool {
|
|
return common.APIJWTSecret != nil || IsOIDCEnabled()
|
|
}
|
|
|
|
func IsOIDCEnabled() bool {
|
|
return common.OIDCIssuerURL != ""
|
|
}
|
|
|
|
func RequireAuth(next http.HandlerFunc) http.HandlerFunc {
|
|
if IsEnabled() {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
if err := defaultAuth.CheckToken(r); err != nil {
|
|
U.RespondError(w, err, http.StatusUnauthorized)
|
|
} else {
|
|
next(w, r)
|
|
}
|
|
}
|
|
}
|
|
return next
|
|
}
|