Athena::Mercure::Bundle::Schema#
Represents the possible properties used to configure and customize the Mercure integration. See the Getting Started docs for more information on how the bundle system works in Athena.
A full example showing all properties is as follows:
ADI.configure({
mercure: {
hubs: {
default: {
url: "https://internal-hub/.well-known/mercure",
public_url: "https://hub.example.com/.well-known/mercure",
jwt: {
# Provide *secret* to generate JWTs dynamically via a token factory...
secret: "my-jwt-secret",
publish: ["*"],
subscribe: ["https://example.com/books/1"],
algorithm: :hs256,
passphrase: "",
claims: {
"iss" => "https://example.com",
"sub" => "urn:example:app",
"client_id" => "https://example.com",
},
# ...or provide *value* to use a static JWT token directly.
# value: "eyJhbGciOiJIUzI1NiJ9...",
},
protocol_version: "1.0",
cookie_name: "__Secure-mercure_access_token",
},
separate_keys: {
url: "https://hub.example.com/.well-known/mercure",
publisher: {
secret: "my-publisher-jwt-secret",
topics: ["*"],
claims: {"iss" => "https://example.com", "sub" => "urn:example:app", "client_id" => "https://example.com"},
},
subscriber: {
secret: "my-subscriber-jwt-secret",
claims: {"iss" => "https://example.com", "sub" => "urn:example:app", "client_id" => "https://example.com"},
},
},
},
default_hub: "default",
default_cookie_lifetime: 1.hour,
},
})
Configuration Properties
hubs#
Hash(K, V)
{__nil: nil}
Named Mercure hub definitions. Each hub requires a url, and either a jwt or a publisher configuration.
Todo
Support publishing the updates of a hub via a dedicated HTTP::Client service, via http_client.
Configuring it is currently an error.
This property consists of a map of key/value pairs where each value has the following properties:
url#type:
StringRequiredThe internal URL used by the server to publish updates to this hub. Should be set via ENV var.
public_url#type:
String | ::Nildefault:
nilThe public URL exposed to clients via the
Linkheader for hub discovery. Falls back to url if not set. Useful when the internal hub URL differs from the one clients should connect to. Should be set via ENV var.
jwt#type:
JWTdefault:
{value: nil}The JWT configuration used for both publishing and subscribing, see
JWT.This property consists of an object with the following properties:
value#type:
String | ::Nildefault:
nilA pre-built static JWT token string provided via
AMC::TokenProvider::Static. When set, the token is used as-is to publish updates.
provider#type:
String | ::Nildefault:
nilThe ID of a service implementing
AMC::TokenProvider::Interfacethat provides the token used to publish updates.
factory#type:
String | ::Nildefault:
nilThe ID of a service implementing
AMC::TokenFactory::Interfaceused to generate tokens, instead of secret.
secret#type:
String | ::Nildefault:
nilThe secret key used to sign JWTs generated via
AMC::TokenFactory::JWT. Should be set via ENV var.
passphrase#type:
StringRequiredPassphrase for the secret key, if the algorithm requires one (e.g. RSA).
algorithm#type:
Symboldefault:
hs256The signing algorithm used to encode the JWT, as the name of a JWT::Algorithm member, such as
:hs256or:rs256.
claims#type:
Hash(String, String | Array(String))default:
{} of String => String | Array(String)Additional claims of the generated JWTs. Under the Mercure protocol 1.0, the
iss,sub, andclient_idclaims are required when using secret, andauddefaults to the hub's public_url, or url.
publish#type:
Array(String)default:
[] of StringTopic selectors that the token used to publish updates is allowed to publish to.
subscribe#type:
Array(String)default:
[] of StringTopic selectors that the token used to publish updates is allowed to subscribe to.
publisher#type:
Publisherdefault:
{value: nil}The JWT configuration used for publishing, as an alternative to jwt, see
Publisher.This property consists of an object with the following properties:
value#type:
String | ::Nildefault:
nilA pre-built static JWT token string provided via
AMC::TokenProvider::Static.
provider#type:
String | ::Nildefault:
nilThe ID of a service implementing
AMC::TokenProvider::Interfacethat provides the token.
factory#type:
String | ::Nildefault:
nilThe ID of a service implementing
AMC::TokenFactory::Interfaceused to generate the token, instead of secret.
topics#type:
Array(String)default:
[] of StringTopic selectors that the generated token is allowed to publish to.
secret#type:
String | ::Nildefault:
nilThe secret key used to sign the token generated via
AMC::TokenFactory::JWT. Should be set via ENV var.
passphrase#type:
StringRequiredPassphrase for the secret key, if the algorithm requires one (e.g. RSA).
algorithm#type:
Symboldefault:
hs256The signing algorithm used to encode the JWT, as the name of a JWT::Algorithm member, such as
:hs256or:rs256.
claims#type:
Hash(String, String | Array(String))default:
{} of String => String | Array(String)Additional claims of the generated token, see the claims of jwt.
subscriber#type:
Subscriberdefault:
{factory: nil}The JWT configuration used for subscribing, as an alternative to jwt, see
Subscriber.This property consists of an object with the following properties:
factory#type:
String | ::Nildefault:
nilThe ID of a service implementing
AMC::TokenFactory::Interfaceused to generate the tokens, instead of secret.
secret#type:
String | ::Nildefault:
nilThe secret key used to sign the tokens generated via
AMC::TokenFactory::JWT. Should be set via ENV var.
passphrase#type:
StringRequiredPassphrase for the secret key, if the algorithm requires one (e.g. RSA).
algorithm#type:
Symboldefault:
hs256The signing algorithm used to encode the JWTs, as the name of a JWT::Algorithm member, such as
:hs256or:rs256.
claims#type:
Hash(String, String | Array(String))default:
{} of String => String | Array(String)Additional claims of the generated tokens, see the claims of jwt.
protocol_version#type:
Stringdefault:
1.0The version of the Mercure protocol this hub speaks,
"1.0"or"0.x". Affects the default cookie_name, and the claims of the tokens generated via secret.
cookie_name#type:
String | ::Nildefault:
nilThe name of the subscriber authorization cookie. Defaults to
__Secure-mercure_access_tokenunder the Mercure protocol 1.0, ormercure_access_tokenif theframework.debugparameter istrue, as browsers drop__Secure-cookies over plain HTTP. Defaults tomercureAuthorizationunder the Mercure protocol 0.x.
default_hub#
String | ::Nil
nil
The name of the hub to use when none is specified. Defaults to the first defined hub if not explicitly set.
default_cookie_lifetime#
Time::Span
1.hour
Default lifetime for authorization cookies set via AMC::Bundle::Authorization.