Class VapidJwt
java.lang.Object
com.iizix.server.push.engine.transport.VapidJwt
The VAPID (RFC 8292) authorization for a Web Push request: an ES256 JWT over the application's key pair, presented as
Authorization: vapid t=<jwt>, k=<public key>.The audience is the origin of the push endpoint - scheme, host and, when it is not the scheme's default, the port. The severed Notification.getOrigin dropped the port (IIZI-PUSH-012), which made every token for an endpoint on a non-default port invalid; origin(String) keeps it.
The token expires after EXPIRY_SECONDS (12 hours; RFC 8292 caps it at 24). It is minted per request rather than cached: the cost is one ECDSA signature, and a cached token near its expiry is the kind of intermittent failure nobody finds.
- Author:
- Christopher Mindus
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe token lifetime: 12 hours, in seconds.Method Summary
Modifier and TypeMethodDescriptionstatic Stringauthorization(String endpoint, String subject, PrivateKey privateKey, byte[] publicKeyRaw) Builds theAuthorizationheader value.static Stringmint(String audience, String subject, PrivateKey privateKey) Mints the compact JWT.static StringComputes the origin of a push endpoint for theaudclaim.
Field Details
EXPIRY_SECONDS
public static final long EXPIRY_SECONDSThe token lifetime: 12 hours, in seconds.- See Also:
Method Details
origin
Computes the origin of a push endpoint for theaudclaim.- Parameters:
endpoint- The push endpoint URL.- Returns:
scheme://hostplus:portwhen the port is explicit and not the scheme's default.- Throws:
IllegalArgumentException- If the endpoint is not an absolute URL with a host.
mint
public static String mint(String audience, String subject, PrivateKey privateKey) throws org.jose4j.lang.JoseException Mints the compact JWT.- Parameters:
audience- The endpoint origin fromorigin(String).subject- Thesubclaim, amailto:orhttps:URI; null to omit.privateKey- The application's P-256 private key.- Returns:
- The compact serialization.
- Throws:
org.jose4j.lang.JoseException- If signing fails.
authorization
public static String authorization(String endpoint, String subject, PrivateKey privateKey, byte[] publicKeyRaw) throws org.jose4j.lang.JoseException Builds theAuthorizationheader value.- Parameters:
endpoint- The push endpoint URL.subject- Thesubclaim, null to omit.privateKey- The application's private key.publicKeyRaw- The application's public key, the 65-byte uncompressed point.- Returns:
vapid t=<jwt>, k=<base64url public key>.- Throws:
org.jose4j.lang.JoseException- If signing fails.