Skip to content

Commit

Permalink
fix(ws): fix extracting client key in handler
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Gateru <[email protected]>
  • Loading branch information
felixgateru committed Jan 24, 2025
1 parent 0d1f132 commit cf13ed3
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions ws/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,7 @@ func (h *handler) AuthPublish(ctx context.Context, topic *string, payload *[]byt
return errClientNotInitialized
}

var token string
switch {
case strings.HasPrefix(string(s.Password), "Client"):
token = strings.ReplaceAll(string(s.Password), "Client ", "")
default:
token = string(s.Password)
}

clientID, err := h.authAccess(ctx, token, *topic, connections.Publish)
clientID, err := h.authAccess(ctx, string(s.Password), *topic, connections.Publish)
if err != nil {
return err
}
Expand All @@ -129,16 +121,8 @@ func (h *handler) AuthSubscribe(ctx context.Context, topics *[]string) error {
return errMissingTopicSub
}

var token string
switch {
case strings.HasPrefix(string(s.Password), "Client"):
token = strings.ReplaceAll(string(s.Password), "Client ", "")
default:
token = string(s.Password)
}

for _, topic := range *topics {
clientID, err := h.authAccess(ctx, token, topic, connections.Subscribe)
clientID, err := h.authAccess(ctx, string(s.Password), topic, connections.Subscribe)
if err != nil {
return err
}
Expand Down Expand Up @@ -259,15 +243,8 @@ func (h *handler) Unsubscribe(ctx context.Context, topics *[]string) error {
return errMissingTopicSub
}

var token string
switch {
case strings.HasPrefix(string(s.Password), "Client"):
token = strings.ReplaceAll(string(s.Password), "Client ", "")
default:
token = string(s.Password)
}
for _, topic := range *topics {
clientID, err := h.authAccess(ctx, token, topic, connections.Subscribe)
clientID, err := h.authAccess(ctx, string(s.Password), topic, connections.Subscribe)
if err != nil {
return err
}
Expand Down

0 comments on commit cf13ed3

Please sign in to comment.