Verifying the signatures of Ring requests, as a function (e.g. for a Pedestal interceptor) and as middleware.
A Ring request has the parts of its URL under separate keys and its body in a stream. So before verifying a signed request, these functions turn it into a message with its whole URL and its body read into bytes. The handler then gets the request with a new stream of those bytes (the bytes themselves in ClojureScript), so it can read the body again.
Verifying the signatures of Ring requests, as a function (e.g. for a Pedestal interceptor) and as middleware. A Ring request has the parts of its URL under separate keys and its body in a stream. So before verifying a signed request, these functions turn it into a message with its whole URL and its body read into bytes. The handler then gets the request with a new stream of those bytes (the bytes themselves in ClojureScript), so it can read the body again.
The default of each option of verified and wrap-verify that has one:
The default of each option of verified and wrap-verify that has one: - :cavage?, false: whether to check a request without a Signature-Input as draft-cavage, rather than treat it as unsigned - :required?, false: whether to refuse an unsigned request - :max-bytes, 10 MB: the largest body that a signed request can have
(message {:keys [request-method uri query-string headers] :as request} b opts)The Ring request as a message that httpsig/verify takes, with the
bytes b as its body and the :origin of opts (or its scheme and Host)
in its URL. The URL is nil when the Host has more than a host name and
a port.
Behind a proxy that ends TLS, the URL that Ring sees isn't the one the client signed, so give the public origin there, e.g. https://example.com.
The Ring `request` as a message that httpsig/verify takes, with the bytes `b` as its body and the :origin of `opts` (or its scheme and Host) in its URL. The URL is nil when the Host has more than a host name and a port. Behind a proxy that ends TLS, the URL that Ring sees isn't the one the client signed, so give the public origin there, e.g. https://example.com.
(verified request key-fn)(verified request key-fn opts)The Ring request with the result of verifying its signature with the
key that key-fn returns, by the opts, under ::httpsig/signature (in
ClojureScript a promise of it).
The result is that of httpsig/verify, or with :cavage? that of cavage/verify for a request without a Signature-Input. The request comes back with a body that the handler can read again. When a signed request's body has more than :max-bytes, the result's :error is ::httpsig/too-large. In ClojureScript, a body that is still a stream has the :error ::httpsig/invalid-body. An unsigned request comes back as it was, without ::httpsig/signature and with its body unread.
The opts are those of default-options, httpsig/verify and
cavage/verify, and the :origin that message takes.
The Ring `request` with the result of verifying its signature with the key that `key-fn` returns, by the `opts`, under ::httpsig/signature (in ClojureScript a promise of it). The result is that of httpsig/verify, or with :cavage? that of cavage/verify for a request without a Signature-Input. The request comes back with a body that the handler can read again. When a signed request's body has more than :max-bytes, the result's :error is ::httpsig/too-large. In ClojureScript, a body that is still a stream has the :error ::httpsig/invalid-body. An unsigned request comes back as it was, without ::httpsig/signature and with its body unread. The `opts` are those of default-options, httpsig/verify and cavage/verify, and the :origin that message takes.
(wrap-verify handler key-fn)(wrap-verify handler key-fn opts)Ring middleware that verifies the signature of each request with the key
that key-fn returns, by the opts of verified, before passing the
request to the handler.
It answers 401 to a request whose signature fails, and to an unsigned request when :required?. It answers 413 to a signed request with a body over :max-bytes. Give :accept-signature, the value of an Accept-Signature field, to say what to sign. Any other request reaches the handler with the result of its signature under ::httpsig/signature, or without one when it's unsigned.
It has both arities of a Ring handler. In ClojureScript, where verifying returns a promise, use the asynchronous arity, or take the promise of a response from the synchronous one.
Ring middleware that verifies the signature of each request with the key that `key-fn` returns, by the `opts` of verified, before passing the request to the `handler`. It answers 401 to a request whose signature fails, and to an unsigned request when :required?. It answers 413 to a signed request with a body over :max-bytes. Give :accept-signature, the value of an Accept-Signature field, to say what to sign. Any other request reaches the handler with the result of its signature under ::httpsig/signature, or without one when it's unsigned. It has both arities of a Ring handler. In ClojureScript, where verifying returns a promise, use the asynchronous arity, or take the promise of a response from the synchronous one.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |