Basic authentication in generic http

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
marcfon
Normal user
Posts: 11
Joined: 17 Sep 2016, 10:50

Basic authentication in generic http

#1 Post by marcfon » 17 Sep 2016, 15:03

Is there a way to do basic url authentication with the generic http protocol (http://user:pass@node/data). The Domoticz http protocol has this feature.

Update:
Found it. You need to change 2 lines in _C008.ino, recompile and upload the new binary.

Code: Select all

        
        Protocol[protocolCount].usesAccount = true;
        Protocol[protocolCount].usesPassword = true;
Update 2:
There are actually 2 more edits that need to be done in _C008.ino.

Add this section to the very top of the HTTPSend() method.

Code: Select all

  
  // START Borrowed from _C001
  String authHeader = "";
  if ((SecuritySettings.ControllerUser[0] != 0) && (SecuritySettings.ControllerPassword[0] != 0))
  {
    base64 encoder;
    String auth = SecuritySettings.ControllerUser;
    auth += ":";
    auth += SecuritySettings.ControllerPassword;
    authHeader = "Authorization: Basic " + encoder.encode(auth) + " \r\n";
  }
  // END Borrowed from _C001
And replace

Code: Select all

  
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + hostName + "\r\n" +
               "Connection: close\r\n\r\n");
with this

Code: Select all

  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" + authHeader + 
               "Connection: close\r\n\r\n");
Last edited by marcfon on 17 Sep 2016, 15:34, edited 1 time in total.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 45 guests