Constructor.
The reset() method is invoked to set up default values for this instance.
Optional
token: stringthe auth token to use
Optional
environment: HostConfigthe environment to use; if not provided a default environment will be created
The SolarNet environment.
Force a port number to be added to host values, even if port would be implied.
This can be useful when working with a server behind a proxy, where the proxy is configured to always forward the port even if the port is implied (i.e. HTTPS is used on the standard port 443).
The signed HTTP headers.
The HTTP query parameters.
Optional
tokenThe SolarNet auth token value.
Static
Readonly
EMPTY_The hex-encoded value for an empty SHA256 digest value.
Static
Readonly
SNWS2_The SolarNetwork V2 authorization scheme.
The authorization request date as a HTTP header string value.
Get the saved signing key expiration date.
This will return the expiration date the signing key saved via key() or saveSigningKey().
Test if a signing key is present and not expired.
Control using the X-SN-Date
HTTP header versus the Date
header.
Set to true
to use the X-SN-Date
header, false
to use
the Date
header. This will return true
if X-SN-Date
has been
added to the signedHeaderNames
property or has been added to the httpHeaders
property.
Compute a HTTP Authorization
header value from the configured
properties on the builder, computing a new signing key based on the
configured Net.AuthorizationV2Builder#date.
the secret to sign the authorization with
the SNWS2 HTTP Authorization header value
Compute the canonical request data that will be included in the data to sign with the request.
the canonical request data
Compute a HTTP Authorization
header value from the configured properties
on the builder, using the provided signing key.
This method does not save the signing key for future use in this builder instance (see key() for that).
the key to sign the computed signature data with
the SNWS2 HTTP Authorization header value
Compute a HTTP Authorization
header value from the configured
properties on the builder, using a signing key configured from a previous
call to saveSigningKey()
or key().
the SNWS2 HTTP Authorization header value.
Get the canonical request content SHA256 digest, hex encoded.
the hex-encoded SHA256 digest of the request content
Compute the canonical HTTP header names to include in the signature.
the sorted, lower-cased HTTP header names to include
Compute the canonical HTTP headers string value.
the sorted, lower-cased HTTP header names to include
the canonical headers string value
Compute the canonical query parameters.
the canonical query parameters string value
Compute the SHA-256 digest of the request body content and configure the result on this builder.
This method will compute the digest and then save the result via the
contentSHA256()
method. In addition, it will set the Digest
HTTP header value via
header().
This means you must also pass the Digest
HTTP header with the request. After calling this
method, you can retrieve the Digest
HTTP header value via the httpHeaders
property.
the request body content to compute a SHA-256 digest value from
this object
Compute the data to be signed by the signing key.
The signature data takes this form:
SNWS2-HMAC-SHA256
20170301T120000Z
Hex(SHA256(canonicalRequestData))
the request data, returned from Net.AuthorizationV2Builder#buildCanonicalRequestData
the data to sign
Compute the signing key, from a secret key and based on the configured date().
This method does not save the signing key for future use in this builder instance (see saveSigningKey() for that). Use this method if you want to compute a signing key that you can later pass to buildWithKey() on some other builder instance. Signing keys are valid for a maximum of 7 days, granular to whole days only. To make a signing key expire in fewer than 7 days, configure a date() value in the past before calling this method.
the secret key string
the computed key
Set the HTTP request body content SHA-256 digest value.
the digest value to use; if a string it is assumed to be Hex encoded
this object
Set the HTTP content type.
This is a shortcut for calling HttpHeaders.put() with the key HttpHeaders.CONTENT_TYPE.
the HTTP content type value to use
this object
Get the authorization request date.
the request date
Set the authorization request date.
the date to use; typically the current time, e.g. new Date()
this object
Set a HTTP header value.
This is a shortcut for calling HttpHeaders#put(headerName, val)
.
the header name to set
the header value to set
this object
Set the HTTP headers to use with the request.
The headers object must include all headers necessary by the authentication scheme, and any additional headers also configured via Net.AuthorizationV2Builder#signedHttpHeaders.
the HTTP headers to use
this object
Set the HTTP host.
This is a shortcut for calling HttpHeaders#put(HttpHeaders.HOST, val)
.
the HTTP host value to use
this object
Get the saved signing key.
the current saved signing key value
Set the signing key.
Use this method to save an existing signing key, for example one received via a refresh
request. The date
parameter is used to track the expirataion date of the key, as
reported by the signingKeyValid
property.
If you have an actual token secret value, use the saveSigningKey() method to save it rather than this method.
the signing key to save
Optional
date: Datean optional date the signing key was generated with; if not provided the configured date() value will be used
this object
Get the HTTP method (verb) to use.
the HTTP method to use
Set the HTTP method (verb) to use.
the method to use; see the Net.HttpMethod enum for possible values
this object
Get the HTTP request path to use.
the request path to use
Set the HTTP request path to use.
the request path to use
this object
Reset to defalut property values.
Any previously saved signing key via saveSigningKey() or key() is preserved. The following items are reset:
GET
this.environment.host
/
this object
Compute and cache the signing key.
Signing keys are derived from the token secret and valid for 7 days, so this method can be used to compute a signing key so that build() can be called later. The signing date will be set to whatever date is currently configured via date(), which defaults to the current time for newly created builder instances.
If you have an externally computed signing key, such as one returned from a token refresh API call, use the key() method to save it rather than this method. If you want to compute the signing key, without caching it on this builder, use the computeSigningKey() method rather than this method.
the secret to sign the digest with
this object
Get additional HTTP header names to sign with the authentication.
the current signed header names
Set additional HTTP header names to sign with the authentication.
additional HTTP header names to include in the signature
this object
Set the useSnDate
property.
true
to use the X-SN-Date
header, false
to use Date
this object
Set the host, path, and query parameters via a URL string.
the URL value to use
Optional
ignoreHost: booleanif true
then do not set the host()
from the given URL; this can be useful when you do not want to override the configured
environment host
this object
A builder object for the SNWS2 HTTP authorization scheme.
This builder can be used to calculate a one-off header value, for example:
Or the builder can be re-used for a given token:
Additionally, a signing key can be generated and re-used for up to 7 days:
Post requests
For handling
POST
orPUT
requests, you must make sure to configure the properties of this class to match your actual HTTP request:Content-Type
header (you can use the HttpContentType constants).application/x-www-form-urlencoded
then you should use the queryParams() method to configure the request parameters.application/x-www-form-urlencoded
then you should use the computeContentDigest() method to configure a HTTPDigest
header.