Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
goshimmer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iota-imt
goshimmer
Commits
ca1d9f1d
Unverified
Commit
ca1d9f1d
authored
5 years ago
by
Angelo Capossele
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix: Web-auth plugin linter warnings (#360)
*
Fixes web auth linter warnings. *
Fixes web auth imports order.
parent
b33aa943
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugins/webauth/parameters.go
+9
-6
9 additions, 6 deletions
plugins/webauth/parameters.go
plugins/webauth/webauth.go
+12
-8
12 additions, 8 deletions
plugins/webauth/webauth.go
with
21 additions
and
14 deletions
plugins/webauth/parameters.go
+
9
−
6
View file @
ca1d9f1d
...
@@ -5,13 +5,16 @@ import (
...
@@ -5,13 +5,16 @@ import (
)
)
const
(
const
(
WEBAPI_AUTH_USERNAME
=
"webapi.auth.username"
// CfgWebAPIAuthUsername defines the config flag of the web API authentication username.
WEBAPI_AUTH_PASSWORD
=
"webapi.auth.password"
CfgWebAPIAuthUsername
=
"webapi.auth.username"
WEBAPI_AUTH_PRIVATE_KEY
=
"webapi.auth.privateKey"
// 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
()
{
func
init
()
{
flag
.
String
(
WEBAPI_AUTH_USERNAME
,
"goshimmer"
,
"username for the webapi"
)
flag
.
String
(
CfgWebAPIAuthUsername
,
"goshimmer"
,
"username for the webapi"
)
flag
.
String
(
WEBAPI_AUTH_PASSWORD
,
"goshimmer"
,
"password for the webapi"
)
flag
.
String
(
CfgWebAPIAuthPassword
,
"goshimmer"
,
"password for the webapi"
)
flag
.
String
(
WEBAPI_AUTH_PRIVATE_KEY
,
""
,
"private key used to sign the JWTs"
)
flag
.
String
(
CfgWebAPIAuthPrivateKey
,
""
,
"private key used to sign the JWTs"
)
}
}
This diff is collapsed.
Click to expand it.
plugins/webauth/webauth.go
+
12
−
8
View file @
ca1d9f1d
...
@@ -5,15 +5,13 @@ import (
...
@@ -5,15 +5,13 @@ import (
"strings"
"strings"
"time"
"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/logger"
"github.com/iotaledger/hive.go/node"
"github.com/iotaledger/hive.go/node"
"github.com/labstack/echo"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"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.
// PluginName is the name of the web API auth plugin.
...
@@ -28,7 +26,7 @@ var (
...
@@ -28,7 +26,7 @@ var (
func
configure
(
plugin
*
node
.
Plugin
)
{
func
configure
(
plugin
*
node
.
Plugin
)
{
log
=
logger
.
NewLogger
(
PluginName
)
log
=
logger
.
NewLogger
(
PluginName
)
privateKey
=
config
.
Node
.
GetString
(
WEBAPI_AUTH_PRIVATE_KEY
)
privateKey
=
config
.
Node
.
GetString
(
CfgWebAPIAuthPrivateKey
)
if
len
(
privateKey
)
==
0
{
if
len
(
privateKey
)
==
0
{
panic
(
""
)
panic
(
""
)
}
}
...
@@ -47,23 +45,29 @@ func configure(plugin *node.Plugin) {
...
@@ -47,23 +45,29 @@ func configure(plugin *node.Plugin) {
log
.
Info
(
"WebAPI is now secured through JWT authentication"
)
log
.
Info
(
"WebAPI is now secured through JWT authentication"
)
}
}
// Request defines the struct of the request.
type
Request
struct
{
type
Request
struct
{
// Username is the username of the request.
Username
string
`json:"username"`
Username
string
`json:"username"`
// Password is the password of the request.
Password
string
`json:"password"`
Password
string
`json:"password"`
}
}
// Response defines the struct of the response.
type
Response
struct
{
type
Response
struct
{
// Token is the json web token.
Token
string
`json:"token"`
Token
string
`json:"token"`
}
}
// Handler handles the web auth request.
func
Handler
(
c
echo
.
Context
)
error
{
func
Handler
(
c
echo
.
Context
)
error
{
login
:=
&
Request
{}
login
:=
&
Request
{}
if
err
:=
c
.
Bind
(
login
);
err
!=
nil
{
if
err
:=
c
.
Bind
(
login
);
err
!=
nil
{
return
echo
.
ErrBadRequest
return
echo
.
ErrBadRequest
}
}
if
login
.
Username
!=
config
.
Node
.
GetString
(
WEBAPI_AUTH_USERNAME
)
||
if
login
.
Username
!=
config
.
Node
.
GetString
(
CfgWebAPIAuthUsername
)
||
login
.
Password
!=
config
.
Node
.
GetString
(
WEBAPI_AUTH_PASSWORD
)
{
login
.
Password
!=
config
.
Node
.
GetString
(
CfgWebAPIAuthPassword
)
{
return
echo
.
ErrUnauthorized
return
echo
.
ErrUnauthorized
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment