diff --git a/client/lib.go b/client/lib.go index a3d7a3c0eac872b2c11e561b5a56f88ba9f74f2d..487f708307ceeecd7c04d71511adb31902b497a1 100644 --- a/client/lib.go +++ b/client/lib.go @@ -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 diff --git a/config.json b/config.json index d5f7713c05a18e05fb6a1915d09c3b69cdb0af68..9b8fe5db33408029aa287792424d4b1997d395b5 100644 --- a/config.json +++ b/config.json @@ -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", diff --git a/plugins/webauth/parameters.go b/plugins/webauth/parameters.go index 2146da738ad8c6cd92b66d585e50613b8d8cc5a6..5084ce564029b3dc5e7d4ffc2ed8380e8fd1e3c9 100644 --- a/plugins/webauth/parameters.go +++ b/plugins/webauth/parameters.go @@ -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") } diff --git a/plugins/webauth/webauth.go b/plugins/webauth/webauth.go index ed8adfd3209bcf95c346a0e610811d132a373d86..21e943fa9f10518118227f65c3e584c622df1af8 100644 --- a/plugins/webauth/webauth.go +++ b/plugins/webauth/webauth.go @@ -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 {