-
Notifications
You must be signed in to change notification settings - Fork 2
SolarNet API authentication scheme
SolarNet uses a custom HTTP authentication scheme roughly similar to the Amazon S3 web API scheme. Clients of the API must use a security token pair to authenticate each request using a HMAC+SHA1 digest of specific request headers.
The request must include a HTTP date header, either using the standard HTTP Date header or the custom X-SN-Date header. If X-SN-Date is provided, it will be used in preference to the Date header. The exact date included in HTTP header is included in the message digest so its value must be known by the client. As many browser AJAX fameworks set the Date header automatically, the X-SN-Date can be easier to use.
The value of the request date must match the current date on SolarNetwork at the time the request is made, within a small tolerance value. If the difference between the HTTP header date and the SolarNetwork system date is too large, a HTTP 401 error will be returned with a message along the lines of date skew too large.
The request must include a standard HTTP Authorization header using SolarNetworkWS as the authorization scheme. The authorization value is in the form token:hash where token is a SolarUser generated authorization token and hash is the HMAC+SHA1 hash generated from the token secret and message content, encoded as a Base64 string.
Each request must generate a message out of details included with the request; that message is then used as the input to the HMAC+SHA1 digest algorithm used to authenticate the request. The message consists of the following items, delimited by a newline character such that the last item does not have a newline character added to it (newline character is 0x0A, or \n in most programming languages):
- HTTP request method, e.g.
GET - Value of
Content-MD5header (or empty string if none) - Value of
Content-Typeheader (or empty string if no content) - Request date, from either a
X-SN-Dateheader or a standardDateheader, using the patternEEE, dd MMM yyyy HH:mm:ss zzzin the GMT time zone (thezzzvalue must be the literal text GMT) - Request URI, including lexicographically sorted request parameters. The request parameters must be included regardless of the HTTP method if
application/x-www-form-urlencodedencoding is used, for example, aPOSTrequest (see below).
The request URI component of the message digest must contain the request parameters, sorted lexicographically. If the HTTP body is encoded as application/x-www-form-urlencoded, the parameters must be added to the URI as well. For example, imagine a HTTP request such as:
POST /solaruser/api/v1/sec/instr/add HTTP/1.1
Host: data.solarnetwork.net
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 100
nodeId=11&topic=SetControlParameter¶meters%5B0%5D.name=/power/switch/1¶meters%5B0%5D.value=1
For the message request URI, the POST parameters would be sorted into
nodeId=1parameters[0].name=/power/switch/1parameters[0].value=1topic=SetControlParameter
and appended like it were a HTTP GET request, like this:
/solaruser/api/v1/sec/instr/add?nodeId=11¶meters[0].name=/power/switch/1¶meters[0].value=1&topic=SetControlParameter
Note the parameters are not URL encoded for the message URI!
Here is an example of a GET request using the SolarNetworkWS authentication scheme:
GET /solaruser/api/v1/sec/instr/viewActive?nodeId=11 HTTP/1.1
Host: data.solarnetwork.net
X-SN-Date: Mon, 23 Sep 2013 03:39:39 GMT
Authorization: SolarNetworkWS a09sjds09wu9wjsd9uy2:IXeexIsjH7beMhxLPU1//1fM9FA=
The raw value of the message content is below (note how lines #2 and #3 are empty):
GET
Mon, 23 Sep 2013 03:39:39 GMT
/solaruser/api/v1/sec/instr/viewActive?nodeId=11
Assuming the message is stored in a variable msg then the Authorization header would be calculated like this, using pseudo code:
token = "a09sjds09wu9wjsd9uy2"; // the SolarNet auth token
secret = "my token secret"; // the secret associated with the SolarNet auth token
msg = "..."; // calculated via rules above
hash = Base64(HmacSHA1(msg, secret)); // call function to hash message, then Base64 encode
authHeader = "Authorization: SolarNetworkWS " +token + ":" + hash;See http://data.solarnetwork.net/dev/api/sample.html for a jQuery client implementation of the SolarNetworkWS authentication scheme designed to showcase how the API can be used.
- SolarNetwork API access
- SolarNetwork API authentication
- SolarNetwork API rate limiting
- SolarNetwork global objects
- SolarNetwork aggregation
- SolarFlux API
- SolarIn API
- SolarQuery API
-
SolarUser API
- SolarUser enumerated types
- SolarUser datum expire API
- SolarUser datum export API
- SolarUser datum import API
- SolarUser event hook API
- SolarUser location request API
- SolarUser Cloud Integrations API
- SolarUser DIN API
- SolarUser DNP3 API
- SolarUser ININ API
- SolarUser OCPP API
- SolarUser OSCP API
- SolarUser Secrets API
- SolarUser SolarFlux API