Skip to content
Snippets Groups Projects
Unverified Commit ca1d9f1d authored by Angelo Capossele's avatar Angelo Capossele Committed by GitHub
Browse files

Fix: Web-auth plugin linter warnings (#360)

* :rotating_light: Fixes web auth linter warnings.

* :rotating_light: Fixes web auth imports order.
parent b33aa943
No related branches found
No related tags found
No related merge requests found
......@@ -5,13 +5,16 @@ import (
)
const (
WEBAPI_AUTH_USERNAME = "webapi.auth.username"
WEBAPI_AUTH_PASSWORD = "webapi.auth.password"
WEBAPI_AUTH_PRIVATE_KEY = "webapi.auth.privateKey"
// CfgWebAPIAuthUsername defines the config flag of the web API authentication username.
CfgWebAPIAuthUsername = "webapi.auth.username"
// CfgWebAPIAuthPassword defines the config flag of the web API authentication password.
CfgWebAPIAuthPassword = "webapi.auth.password"
// CfgWebAPIAuthPrivateKey defines the config flag of the web API authentication private key.
CfgWebAPIAuthPrivateKey = "webapi.auth.privateKey"
)
func init() {
flag.String(WEBAPI_AUTH_USERNAME, "goshimmer", "username for the webapi")
flag.String(WEBAPI_AUTH_PASSWORD, "goshimmer", "password for the webapi")
flag.String(WEBAPI_AUTH_PRIVATE_KEY, "", "private key used to sign the JWTs")
flag.String(CfgWebAPIAuthUsername, "goshimmer", "username for the webapi")
flag.String(CfgWebAPIAuthPassword, "goshimmer", "password for the webapi")
flag.String(CfgWebAPIAuthPrivateKey, "", "private key used to sign the JWTs")
}
......@@ -5,15 +5,13 @@ import (
"strings"
"time"
"github.com/dgrijalva/jwt-go"
"github.com/iotaledger/goshimmer/plugins/config"
"github.com/iotaledger/goshimmer/plugins/webapi"
"github.com/iotaledger/hive.go/logger"
"github.com/iotaledger/hive.go/node"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/iotaledger/goshimmer/plugins/config"
"github.com/iotaledger/goshimmer/plugins/webapi"
"github.com/dgrijalva/jwt-go"
)
// PluginName is the name of the web API auth plugin.
......@@ -28,7 +26,7 @@ var (
func configure(plugin *node.Plugin) {
log = logger.NewLogger(PluginName)
privateKey = config.Node.GetString(WEBAPI_AUTH_PRIVATE_KEY)
privateKey = config.Node.GetString(CfgWebAPIAuthPrivateKey)
if len(privateKey) == 0 {
panic("")
}
......@@ -47,23 +45,29 @@ func configure(plugin *node.Plugin) {
log.Info("WebAPI is now secured through JWT authentication")
}
// Request defines the struct of the request.
type Request struct {
// Username is the username of the request.
Username string `json:"username"`
// Password is the password of the request.
Password string `json:"password"`
}
// Response defines the struct of the response.
type Response struct {
// Token is the json web token.
Token string `json:"token"`
}
// Handler handles the web auth request.
func Handler(c echo.Context) error {
login := &Request{}
if err := c.Bind(login); err != nil {
return echo.ErrBadRequest
}
if login.Username != config.Node.GetString(WEBAPI_AUTH_USERNAME) ||
login.Password != config.Node.GetString(WEBAPI_AUTH_PASSWORD) {
if login.Username != config.Node.GetString(CfgWebAPIAuthUsername) ||
login.Password != config.Node.GetString(CfgWebAPIAuthPassword) {
return echo.ErrUnauthorized
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment