Image.Components.Signing.ImageKit (image_components v0.1.1)

Copy Markdown View Source

ImageKit-flavoured client-side URL signing.

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

HMAC-SHA1 over the path-and-query (ik-s excluded). Signature appended as ?ik-s=<hex> (or &ik-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 ImageKit request path, optionally with an existing query string.

  • keys is a non-empty list of ImageKit private API keys.

Options

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

Returns

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

Examples

iex> Image.Components.Signing.ImageKit.sign("/demo/tr:w-200/cat.jpg", ["k"])
...> |> String.contains?("?ik-s=")
true