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
Private
Optional
#contentPrivate
#httpPrivate
#requestPrivate
#requestPrivate
Optional
#signedPrivate
Optional
#signingPrivate
Optional
#signingThe 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.
Private
#canonicalCompute the canonical signed header names value from an array of HTTP header names.
the sorted, lower-cased HTTP header names to include
the canonical signed header names string value
Private
#computeCompute the canonical request data that will be included in the data to sign with the request, using a specific set of HTTP header names to sign.
the sorted, lower-cased HTTP header names to sign with the request
the canonical request data
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 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.
Error if a saved signing key is not configured
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
Set the authorization request date.
when called as a getter the request date, otherwise 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 or 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.
when called as a getter the current saved signing key value, otherwise this object
Net.AuthorizationV2Builder#signingKeyExpirationDate
Optional
date: DateSet the HTTP method (verb) to use.
this object
Set the HTTP request path to use.
this object
Set the HTTP GET
query parameters, or POST
form-encoded
parameters.
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
Set additional HTTP header names to sign with the authentication.
when called as a getter, the current signed header names, otherwise 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
Generated using TypeDoc
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.