Image.Components.Signing.Imgix (image_components v0.1.0)

Copy Markdown View Source

imgix-flavoured client-side URL signing.

Wire-format-compatible with Image.Plug.Provider.Imgix.Signing on the server side and with imgix's hosted signed URLs. Sign-only — verification happens at the back-end.

HMAC-SHA256 over secret <> path-and-query. Signature appended as ?s=<hex> (or &s=<hex> if a query is already present).

Summary

Functions

Signs path_with_query with the first key in keys.

Functions

sign(path_with_query, keys, options \\ [])

@spec sign(String.t(), [String.t(), ...], keyword()) :: String.t()

Signs path_with_query with the first key in keys.

Arguments

  • path_with_query is the imgix request path, optionally with an existing query string.

  • keys is a non-empty list of imgix secret tokens.

Options

  • :expires_atDateTime or unix-seconds. Adds an expires=<unix> parameter; the back-end's verifier rejects the URL after that time.

Returns

  • The path with ?s=<hex> (and optional ?expires=…) appended.

Examples

iex> Image.Components.Signing.Imgix.sign("/cat.jpg?w=200", ["secret"])
...> =~ "?w=200&s="
true