Skip to content
Snippets Groups Projects
Commit 506dee9d authored by Luca Moser's avatar Luca Moser
Browse files

fixes bearer format, adds logger to webauth

parent 2a39284b
No related branches found
No related tags found
No related merge requests found
......@@ -116,7 +116,7 @@ func (api *GoShimmerAPI) do(method string, route string, reqObj interface{}, res
// add authorization header with JWT
if len(api.jwt) > 0 {
req.Header.Set("Authorization", fmt.Sprintf("bearer %s", api.jwt))
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", api.jwt))
}
// make the request
......
......@@ -17,7 +17,12 @@
"port": 14666
},
"webapi": {
"bindAddress": "0.0.0.0:8080"
"bindAddress": "0.0.0.0:8080",
"auth": {
"username": "goshimmer",
"password": "goshimmer",
"privateKey": "uUUavNbdr32jE9CqnSMCKt4HMu9AZ2K4rKekUSPx9jk83eyeM7xewv5CqUKYMC9"
}
},
"graph": {
"webrootPath": "./IOTAtangle/webroot",
......
......@@ -7,11 +7,11 @@ import (
const (
WEBAPI_AUTH_USERNAME = "webapi.auth.username"
WEBAPI_AUTH_PASSWORD = "webapi.auth.password"
WEBAPI_AUTH_PRIVATE_KEY = "webapi.auth.private_key"
WEBAPI_AUTH_PRIVATE_KEY = "webapi.auth.privateKey"
)
func init() {
flag.String(WEBAPI_AUTH_USERNAME, "user", "username for the webapi")
flag.String(WEBAPI_AUTH_PASSWORD, "pass", "password for the webapi")
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")
}
......@@ -7,6 +7,7 @@ import (
"github.com/iotaledger/goshimmer/packages/parameter"
"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"
......@@ -14,12 +15,12 @@ import (
"github.com/dgrijalva/jwt-go"
)
var PLUGIN = node.NewPlugin("WebAPI JWT Auth", node.Disabled, configure)
var PLUGIN = node.NewPlugin("WebAPI Auth", node.Disabled, configure)
var log *logger.Logger
var privateKey string
func configure(plugin *node.Plugin) {
log = logger.NewLogger("WebAPI Auth")
privateKey = parameter.NodeConfig.GetString(WEBAPI_AUTH_PRIVATE_KEY)
if len(privateKey) == 0 {
panic("")
......@@ -36,6 +37,7 @@ func configure(plugin *node.Plugin) {
}))
webapi.Server.POST("/login", Handler)
log.Info("WebAPI is now secured through JWT authentication")
}
type Request struct {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment