Skip to content

class Athena::Mercure::Authorization
inherits Reference #

Helper class for adding the Mercure authorization cookie to an HTTP response in order to enable private updates. See Authorization for more information.

Direct known subclasses

Athena::Mercure::Bundle::Authorization

Constructors#

.new(hub_registry : AMC::Hub::Registry, cookie_lifetime : Time::Span = 1.hour, cookie_samesite : ::HTTP::Cookie::SameSite = :strict)#

View source

Methods#

#clear_cookie(request : ::HTTP::Request, response : ::HTTP::Server::Response, hub_name : String | Nil = nil) : Nil#

Clears the Mercure cookie from the provided response, optionally for the provided hub_name.

View source

#create_cookie(request : ::HTTP::Request, grants : Array(AMC::Grant) | Array(String) | Hash(String, Array(String)) | String = [] of AMC::Grant, additional_claims : Hash | Nil = nil, hub_name : String | Nil = nil) : ::HTTP::Cookie#

Returns a Mercure auth cookie given the provided request and optionally for the provided hub_name.

The JWT cookie value by default does not have access to publish or subscribe to any topic. Be sure to provide the grants it should have, such as the topics to subscribe to, or ["*"] to subscribe to all topics. See AMC::Grant.from for the accepted shorthands. additional_claims may also be used to define additional claims to the JWT if needed.

View source

#set_cookie(request : ::HTTP::Request, response : ::HTTP::Server::Response, grants : Array(AMC::Grant) | Array(String) | Hash(String, Array(String)) | String = [] of AMC::Grant, additional_claims : Hash | Nil = nil, hub_name : String | Nil = nil) : Nil#

Sets the authorization cookie of the hub, see AMC::Hub::Interface#cookie_name, on the provided response given the provided request, optionally for the provided hub_name. The JWT cookie value by default does not have access to publish or subscribe to any topic. Be sure to provide the grants it should have, such as the topics to subscribe to, or ["*"] to subscribe to all topics. See AMC::Grant.from for the accepted shorthands. additional_claims may also be used to define additional claims to the JWT if needed.

View source