Skip to content

Commit

Permalink
check if token is not empty before using it
Browse files Browse the repository at this point in the history
  • Loading branch information
reubenmiller committed May 16, 2024
1 parent c88bf30 commit 062fd2b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/remoteaccess/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ func (c *RemoteAccessClient) createRemoteAccessConnection() (*websocket.Conn, st
requestHeader := http.Header{}
requestHeader.Add("Content-Type", "application/json")

switch c.client.AuthorizationMethod {
case c8y.AuthMethodBasic:
requestHeader.Add("Authorization", c8y.NewBasicAuthString(c.client.GetTenantName(context.Background()), c.client.Username, c.client.Password))
default:
if c.client.Token != "" {
c.log.Debug("Using bearer token")
requestHeader.Add("Authorization", "Bearer "+c.client.Token)
} else {
c.log.Debug("Using basic auth")
requestHeader.Add("Authorization", c8y.NewBasicAuthString(c.client.GetTenantName(context.Background()), c.client.Username, c.client.Password))
}

c.log.Infof("Connection to Cumulocity IoT CRA: remote=%s, headers=%v", remoteURL, requestHeader)

wsConn, _, err := websocket.DefaultDialer.Dial(remoteURL, requestHeader)
Expand Down

0 comments on commit 062fd2b

Please sign in to comment.