Skip to content

struct Athena::Mercure::TokenFactory::JWT
inherits Struct #

A token factory implementation based on the Crystal JWT shard.

Under the Mercure protocol 1.0, it creates RFC 9068 access tokens. The grants are encoded as its authorization_details claim, and the iss, aud, sub, and client_id claims must be provided as additional_claims, such as via AMC::TokenFactory::DefaultClaims. Under the Mercure protocol 0.x, the grants are encoded as its mercure claim, which only supports topics that are matched exactly, and no payload.

Note

Only available if the jwt shard is installed and required, see the installation instructions.

Included modules

Athena::Mercure::TokenFactory::Interface

Constructors#

.new(jwt_secret : String, algorithm : ::JWT::Algorithm = :hs256, jwt_lifetime : Int32 | Time::Span | Nil = 3600, passphrase : String = "", protocol_version : AMC::ProtocolVersion = :v1)#

View source

Methods#

#create(grants : Array(AMC::Grant) = [] of AMC::Grant, additional_claims : Hash | Nil = nil) : String#

Returns a JWT token that is allowed the provided grants, such as to subscribe or publish to some topics. Optionally, additional_claims may be added to the JWT.

View source