Skip to content

Commit b10f3db

Browse files
committed
pass the chargepoint id to basic auth handler
1 parent 5e7c199 commit b10f3db

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ Example central system:
380380

381381
```go
382382
server := ws.NewServer()
383-
server.SetBasicAuthHandler(func (username string, password string) bool {
383+
server.SetBasicAuthHandler(func (chargePointID string, username string, password string) bool {
384384
// todo Handle basic auth
385385
return true
386386
})

Diff for: ws/mocks/mock_Server.go

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ws/server.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ type Server interface {
103103
// SetBasicAuthHandler enables HTTP Basic Authentication and requires clients to pass credentials.
104104
// The handler function is called whenever a new client attempts to connect, to check for credentials correctness.
105105
// The handler must return true if the credentials were correct, false otherwise.
106-
SetBasicAuthHandler(handler func(username string, password string) bool)
106+
SetBasicAuthHandler(handler func(chargePointID string, username string, password string) bool)
107107
// SetCheckOriginHandler sets a handler for incoming websocket connections, allowing to perform
108108
// custom cross-origin checks.
109109
//
@@ -137,7 +137,7 @@ type server struct {
137137
checkClientHandler CheckClientHandler
138138
newClientHandler func(ws Channel)
139139
disconnectedHandler func(ws Channel)
140-
basicAuthHandler func(username string, password string) bool
140+
basicAuthHandler func(chargePointID string, username string, password string) bool
141141
tlsCertificatePath string
142142
tlsCertificateKey string
143143
timeoutConfig ServerTimeoutConfig
@@ -232,7 +232,7 @@ func (s *server) SetChargePointIdResolver(resolver func(r *http.Request) (string
232232
s.chargePointIdResolver = resolver
233233
}
234234

235-
func (s *server) SetBasicAuthHandler(handler func(username string, password string) bool) {
235+
func (s *server) SetBasicAuthHandler(handler func(chargePointID string, username string, password string) bool) {
236236
s.basicAuthHandler = handler
237237
}
238238

@@ -387,7 +387,7 @@ out:
387387
if s.basicAuthHandler != nil {
388388
username, password, ok := r.BasicAuth()
389389
if ok {
390-
ok = s.basicAuthHandler(username, password)
390+
ok = s.basicAuthHandler(id, username, password)
391391
}
392392
if !ok {
393393
s.error(fmt.Errorf("basic auth failed: credentials invalid"))

Diff for: ws/websocket_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,8 @@ func (s *WebSocketSuite) TestValidBasicAuth() {
749749
s.server, ok = tlsServer.(*server)
750750
s.True(ok)
751751
// Add basic auth handler
752-
s.server.SetBasicAuthHandler(func(username string, password string) bool {
752+
s.server.SetBasicAuthHandler(func(chargePointID string, username string, password string) bool {
753+
s.Equal(testPath, chargePointID)
753754
s.Equal(authUsername, username)
754755
s.Equal(authPassword, password)
755756
return true
@@ -804,8 +805,8 @@ func (s *WebSocketSuite) TestInvalidBasicAuth() {
804805
s.server, ok = tlsServer.(*server)
805806
s.True(ok)
806807
// Add basic auth handler
807-
s.server.SetBasicAuthHandler(func(username string, password string) bool {
808-
validCredentials := authUsername == username && authPassword == password
808+
s.server.SetBasicAuthHandler(func(chargePointID string, username string, password string) bool {
809+
validCredentials := testPath == chargePointID && authUsername == username && authPassword == password
809810
s.False(validCredentials)
810811
return validCredentials
811812
})

0 commit comments

Comments
 (0)