From 506dee9dd3caaae76f35fdd0e48e70e60e1243a7 Mon Sep 17 00:00:00 2001 From: Luca Moser <moser.luca@gmail.com> Date: Thu, 23 Jan 2020 15:53:32 +0100 Subject: [PATCH] fixes bearer format, adds logger to webauth --- client/lib.go | 2 +- config.json | 7 ++++++- plugins/webauth/parameters.go | 6 +++--- plugins/webauth/webauth.go | 8 +++++--- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/client/lib.go b/client/lib.go index a3d7a3c0..487f7083 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 d5f7713c..9b8fe5db 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 2146da73..5084ce56 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 ed8adfd3..21e943fa 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 { -- GitLab