Explorar el Código

Added option to load jwt algorithm from env

master
Patrick Gaskin hace 8 meses
padre
commit
9a41f66991
Firmado por: geek1011 ID de clave GPG: A2FD79F68A2AB707
Se han modificado 1 ficheros con 13 adiciones y 2 borrados
  1. +13
    -2
      config.go

+ 13
- 2
config.go Ver fichero

@ -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

Cargando…
Cancelar
Guardar