add(auth): optional jwt debug key on startup
This commit is contained in:
@@ -9,6 +9,7 @@ type (
|
||||
configuration struct {
|
||||
jwtSecret string
|
||||
jwtExpiry int64
|
||||
jwtDebug bool
|
||||
}
|
||||
)
|
||||
|
||||
@@ -26,4 +27,5 @@ func (c configuration) validate() error {
|
||||
func Flags(_ ...string) {
|
||||
flag.StringVar(&config.jwtSecret, "auth-jwt-secret", "", "JWT Secret")
|
||||
flag.Int64Var(&config.jwtExpiry, "auth-jwt-expiry", 3600, "JWT Expiration in minutes")
|
||||
flag.BoolVar(&config.jwtDebug, "auth-jwt-debug", false, "Generate debug JWT key")
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package auth
|
||||
import (
|
||||
"github.com/go-chi/jwtauth"
|
||||
"github.com/titpetric/factory/resputil"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -19,6 +20,10 @@ func JWT() (*jwt, error) {
|
||||
|
||||
jwt := &jwt{tokenAuth: jwtauth.New("HS256", []byte(config.jwtSecret), nil)}
|
||||
|
||||
if config.jwtDebug {
|
||||
log.Println("DEBUG JWT TOKEN:", jwt.Encode(NewIdentity(1)))
|
||||
}
|
||||
|
||||
return jwt, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user