Parcourir la source

Added option to load jwt algorithm from env

master
Patrick Gaskin il y a 8 mois
Parent
révision
9a41f66991
Signé par: geek1011 ID de la clé GPG: A2FD79F68A2AB707
1 fichiers modifiés avec 13 ajouts et 2 suppressions
  1. +13
    -2
      config.go

+ 13
- 2
config.go Voir le fichier

@ -185,7 +185,7 @@ func (a AuthProviders) ValidateUserList(u PropList) error {
// for a multiline string), and set the alg to ES512.
type AuthProviderJWT struct {
Secret string `toml:"secret"` // can also be ENV:varname to take from the env var named varname
Alg string `toml:"alg"`
Alg string `toml:"alg"` // can also be ENV:varname to take from the env var named varname
CookieName string `toml:"cookie_name"`
LoginURL string `toml:"login_url"` // optional
LogoutURL string `toml:"logout_url"` // optional
@ -220,7 +220,18 @@ func (a AuthProviderJWT) KeyFunc() (jwt.Keyfunc, error) {
secret = a.Secret
}
switch sm := jwt.GetSigningMethod(a.Alg).(type) {
var alg string
if strings.HasPrefix(a.Alg, "ENV:") {
v := strings.TrimPrefix(a.Alg, "ENV:")
alg = os.Getenv(v)
if alg == "" {
return nil, fmt.Errorf("no alg set from env var %#v", v)
}
} else {
alg = a.Alg
}
switch sm := jwt.GetSigningMethod(alg).(type) {
case *jwt.SigningMethodHMAC:
return jwt.KnownKeyfunc(sm, []byte(secret)), nil

Chargement…
Annuler
Enregistrer