HTTP digest authentication
The HTTPGet(), HTTPPost(), and HTTPPut() instructions support HTTP digest authentication. This includes the table streaming options of HTTPPut() and HTTPPost(). Use digest authentication when you communicate with devices that require it, such as some IP cameras. You can also use it with any HTTP server that supports and enables digest authentication.
Requirements
Digest authentication requires one of the following operating systems or later:
-
CR1000X: 9.0.0
-
CR6: 15.0.0
-
GRANITE 9: 4.0.0
-
GRANITE 10: 4.0.0
Enabling digest authentication
To enable digest authentication add [digest] to the beginning of the string passed in the URI parameter. This string is case sensitive. Include the user name and password before the host part of the URL. For example:
"[digest]http://<username>:<password>@example.com/path"
NOTE: State for digest authentication is not preserved between calls to the instruction. Each time the instruction is called, it starts fresh and performs authentication again—even if the server-issued one-time token (called a nonce) from the previous call would still be acceptable. However, if a single call triggers multiple HTTP requests (for example, while streaming a table or following redirects), all of those requests within that one call will reuse the same nonce.
Digest and basic authentication
When the URI string starts with [digest], the data logger uses only digest authentication. It does not try basic authentication.
When the URI string does not start with [digest], the data logger uses basic authentication. To use basic authentication, include <username>:<password>@ before the host part of the URL.
Supported standards
Digest authentication follows RFC 2617. The data logger supports legacy digest authentication and qop=auth with algorithm=MD5. RFC 7616, which adds algorithms such as SHA-256, is not supported.
'Declare Public Variables
Public Flag As Boolean
Public socket As Long = -999
Public response As String * 1000
'Main Program
BeginProg
Scan (1,Sec,0,0)
Set Flag to True to send the request.
If Flag Then
'To enable HTTP digest authentication, put the exact string "[digest]"
'at the start of the URL. This string is case sensitive.
'Digest authentication works with HTTPGet(), HTTPPut(), and HTTPPost().
'This example uses postman-echo.com/digest-auth, a publicly available
'endpoint for testing HTTP digest authentication.
'- To connect over unencrypted HTTP, change the scheme at the start
' of the URL to "http://".
'- Replace "postman:password" with your user name and password
'- Replace the URL with your endpoint.
'Timeout parameter is omitted, defaults to 75 seconds
socket = HTTPGet("[digest]https://postman:password@postman-echo.com/digest-auth", response, "")
Flag = False
EndIf
NextScan
EndProg