Class: Cent::Notary
- Inherits:
-
Object
- Object
- Cent::Notary
- Defined in:
- lib/cent/notary.rb
Overview
Cent::Notary
Issues JWT tokens for Centrifugo client connections and channel subscriptions. Supports HMAC, RSA and ECDSA families of algorithms (HS256/384/512, RS256/384/512, ES256/384/512).
Instance Method Summary collapse
-
#initialize(secret:, algorithm: 'HS256') ⇒ Notary
constructor
A new instance of Notary.
-
#issue_channel_token(sub:, channel:, exp: nil, iat: nil, jti: nil, aud: nil, iss: nil, info: nil, b64info: nil, override: nil, expire_at: nil) ⇒ String
Issue a subscription JWT used by clients to authorize subscription to a channel that requires token authorization.
-
#issue_connection_token(sub:, exp: nil, iat: nil, jti: nil, aud: nil, iss: nil, info: nil, b64info: nil, channels: nil, subs: nil, meta: nil, expire_at: nil) ⇒ String
Issue a connection JWT used by clients when establishing a real-time connection to Centrifugo.
Constructor Details
Instance Method Details
#issue_channel_token(sub:, channel:, exp: nil, iat: nil, jti: nil, aud: nil, iss: nil, info: nil, b64info: nil, override: nil, expire_at: nil) ⇒ String
Issue a subscription JWT used by clients to authorize subscription to a channel that requires token authorization.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/cent/notary.rb', line 82 def issue_channel_token(sub:, channel:, exp: nil, iat: nil, jti: nil, aud: nil, iss: nil, info: nil, b64info: nil, override: nil, expire_at: nil) payload = { 'sub' => sub, 'channel' => channel, 'exp' => exp, 'iat' => iat, 'jti' => jti, 'aud' => aud, 'iss' => iss, 'info' => info, 'b64info' => b64info, 'override' => override, 'expire_at' => expire_at }.compact JWT.encode(payload, secret, algorithm) end |
#issue_connection_token(sub:, exp: nil, iat: nil, jti: nil, aud: nil, iss: nil, info: nil, b64info: nil, channels: nil, subs: nil, meta: nil, expire_at: nil) ⇒ String
Issue a connection JWT used by clients when establishing a real-time connection to Centrifugo.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cent/notary.rb', line 45 def issue_connection_token(sub:, exp: nil, iat: nil, jti: nil, aud: nil, iss: nil, info: nil, b64info: nil, channels: nil, subs: nil, meta: nil, expire_at: nil) payload = { 'sub' => sub, 'exp' => exp, 'iat' => iat, 'jti' => jti, 'aud' => aud, 'iss' => iss, 'info' => info, 'b64info' => b64info, 'channels' => channels, 'subs' => subs, 'meta' => , 'expire_at' => expire_at }.compact JWT.encode(payload, secret, algorithm) end |