WebPush.Vapid (web_push v0.1.0)

Copy Markdown View Source

VAPID (RFC 8292) JWT signing for Web Push authentication.

Builds a JWT with ES256 over the claims {aud, exp, sub}, signs it with the VAPID P-256 private key, and returns the Authorization header value in the form vapid t=<jwt>, k=<vapid_public_b64>.

Keys come from application config:

config :web_push, :vapid,
  public_key: "B...",
  private_key: "...",
  subject: "mailto:you@example.com"

Generate a keypair with mix web_push.gen.vapid.

Summary

Functions

Returns the origin (scheme + host + non-default port) of a URL: the value used as the aud claim in the VAPID JWT.

Builds the full Authorization header value for a request to endpoint_url.

Generates a VAPID P-256 keypair, URL-safe base64 without padding.

Returns the configured VAPID public key (URL-safe base64, 65-byte point). The client passes this to pushManager.subscribe({ applicationServerKey }).

Functions

audience_for(url)

@spec audience_for(String.t()) :: String.t()

Returns the origin (scheme + host + non-default port) of a URL: the value used as the aud claim in the VAPID JWT.

authorization_header(endpoint_url)

@spec authorization_header(String.t()) :: String.t()

Builds the full Authorization header value for a request to endpoint_url.

generate_keypair()

@spec generate_keypair() :: %{public_key: String.t(), private_key: String.t()}

Generates a VAPID P-256 keypair, URL-safe base64 without padding.

public_key()

@spec public_key() :: String.t()

Returns the configured VAPID public key (URL-safe base64, 65-byte point). The client passes this to pushManager.subscribe({ applicationServerKey }).