Limen.Challenge.Pass (limen v0.2.1)

Copy Markdown View Source

The pass cookie a client gets for solving a challenge.

Like challenge tokens, passes are stateless: an expiry and a truncated HMAC-SHA256 over it and the client identity (see Limen.Challenge.pass_binding/1), with a key only used for passes.

<<version, expires_at::32, mac::16 bytes>>

Verifying one is the fast path of Limen.Plug: parse the cookie header, decode 28 characters, compute one HMAC.

Summary

Functions

Finds cookie name in the values of cookie headers without parsing every cookie.

Issues a pass for the client in ctx, returning the cookie value and its lifetime in seconds.

Sets the pass cookie on conn.

Verifies the pass the client in ctx presents, if any.

Verifies a pass cookie value for the client in ctx.

Functions

cookie(cookie_headers, name)

@spec cookie([String.t()], String.t()) :: String.t() | nil

Finds cookie name in the values of cookie headers without parsing every cookie.

iex> Limen.Challenge.Pass.cookie(["a=1; _limen_pass=abc; b=2"], "_limen_pass")
"abc"

issue(ctx)

@spec issue(Limen.Context.t()) :: {String.t(), pos_integer()}

Issues a pass for the client in ctx, returning the cookie value and its lifetime in seconds.

put_cookie(conn, instance, value, max_age)

@spec put_cookie(Plug.Conn.t(), Limen.Instance.t(), String.t(), pos_integer()) ::
  Plug.Conn.t()

Sets the pass cookie on conn.

verify(ctx)

@spec verify(Limen.Context.t()) ::
  {:ok, non_neg_integer()}
  | {:error, :missing | :malformed | :invalid | :expired}

Verifies the pass the client in ctx presents, if any.

verify(value, ctx)

@spec verify(String.t(), Limen.Context.t()) ::
  {:ok, non_neg_integer()} | {:error, :malformed | :invalid | :expired}

Verifies a pass cookie value for the client in ctx.