Compare commits
No commits in common. "db3baa0328686d1ec86dc99d5adac0af3cd9a738" and "4be8726efb3bfc171a76e784acbe215477c0b147" have entirely different histories.
db3baa0328
...
4be8726efb
@ -3,6 +3,5 @@ package domain
|
|||||||
type EnvConfig struct {
|
type EnvConfig struct {
|
||||||
AdminToken string
|
AdminToken string
|
||||||
JwtSecret string
|
JwtSecret string
|
||||||
ApiUri string
|
|
||||||
DisableMigrationsOnStartUp bool
|
DisableMigrationsOnStartUp bool
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ func (h *Handler) AuthLogin(c echo.Context) error {
|
|||||||
return h.InternalServerErrorResponse(c, err.Error())
|
return h.InternalServerErrorResponse(c, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
token, err := h.generateJwt(username, h.Config.ApiUri)
|
token, err := h.generateJwt(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return h.InternalServerErrorResponse(c, err.Error())
|
return h.InternalServerErrorResponse(c, err.Error())
|
||||||
}
|
}
|
||||||
|
@ -56,16 +56,14 @@ func (j JwtToken) hasScope(scope string) error {
|
|||||||
return errors.New(ErrJwtScopeMissing)
|
return errors.New(ErrJwtScopeMissing)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) generateJwt(username, issuer string) (string, error) {
|
func (h *Handler) generateJwt(username string) (string, error) {
|
||||||
secret := []byte(h.Config.JwtSecret)
|
secret := []byte(h.Config.JwtSecret)
|
||||||
|
|
||||||
// Anyone who wants to decrypt the key needs to use the same method
|
|
||||||
token := jwt.New(jwt.SigningMethodHS256)
|
token := jwt.New(jwt.SigningMethodHS256)
|
||||||
claims := token.Claims.(jwt.MapClaims)
|
claims := token.Claims.(jwt.MapClaims)
|
||||||
claims["exp"] = time.Now().Add(10 * time.Minute)
|
claims["exp"] = time.Now().Add(10 * time.Minute)
|
||||||
claims["authorized"] = true
|
claims["authorized"] = true
|
||||||
claims["username"] = username
|
claims["username"] = username
|
||||||
claims["iss"] = issuer
|
|
||||||
|
|
||||||
var scopes []string
|
var scopes []string
|
||||||
scopes = append(scopes, domain.ScopeRecipeRead)
|
scopes = append(scopes, domain.ScopeRecipeRead)
|
||||||
|
@ -16,7 +16,7 @@ func NewEnvConfig() domain.EnvConfig {
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
disableMigrations, err := strconv.ParseBool(os.Getenv("DisableMigrationsOnStartup"))
|
disableMigrations, err := strconv.ParseBool(os.Getenv("DisableMigrationsOnStartup"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
disableMigrations = false
|
disableMigrations = false
|
||||||
}
|
}
|
||||||
@ -24,7 +24,6 @@ func NewEnvConfig() domain.EnvConfig {
|
|||||||
return domain.EnvConfig{
|
return domain.EnvConfig{
|
||||||
AdminToken: os.Getenv("AdminToken"),
|
AdminToken: os.Getenv("AdminToken"),
|
||||||
JwtSecret: os.Getenv("JwtSecret"),
|
JwtSecret: os.Getenv("JwtSecret"),
|
||||||
ApiUri: os.Getenv("ApiUri"),
|
|
||||||
DisableMigrationsOnStartUp: disableMigrations,
|
DisableMigrationsOnStartUp: disableMigrations,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user