lib/cent/notary.rb
# Generate connection JWT for the given user
#
# @param sub [String]
#   Standard JWT claim which must contain an ID of current application user.
#
# @option channel [String]
#   Channel that client tries to subscribe to (string).
#
# @param exp [Integer]
#   (default: nil) UNIX timestamp seconds when token will expire.
#
# @param info [Hash]
#   (default: {}) This claim is optional - this is additional information about
#   client connection that can be provided for Centrifugo.
#
# @example Get user JWT with expiration and extra info
#   notary.issue_connection_token(sub: '1', exp: 3600, info: { 'role' => 'admin' })
#     #=> "eyJhbGciOiJIUzI1NiJ9.eyJzdWIi..."
#
# @see (https://centrifugal.github.io/centrifugo/server/authentication/)
#
# @return [String]
#
Generate connection JWT for the given user
Generate connection JWT for the given user
def issue_connection_token(sub:, info: nil, exp: nil)
      payload = {
        'sub' => sub,
        'info' => info,
        'exp' => exp
      }.compact
      JWT.encode(payload, secret, algorithm)
    end
def issue_connection_token ( sub : , info : nil , exp : nil ) payload = { 'sub' => sub , 'info' => info , 'exp' => exp } . compact JWT . encode ( payload , secret , algorithm ) end
Generate connection JWT for the given user
Generate connection JWT for the given user
None
String
sub
Standard JWT claim which must contain an ID of current application user.
Standard JWT claim which must contain an ID of current application user .
info
{}) This claim is optional - this is additional information about client connection that can be provided for Centrifugo.
{} ) This claim is optional - this is additional information about client connection that can be provided for Centrifugo .
exp
nil) UNIX timestamp seconds when token will expire.
nil ) UNIX timestamp seconds when token will expire .
channel
<not_specific>
Channel that client tries to subscribe to (string).
Channel that client tries to subscribe to ( string ) .
example
Get user JWT with expiration and extra info notary.issue_connection_token(sub: '1', exp: 3600, info: { 'role' => 'admin' }) #=> "eyJhbGciOiJIUzI1NiJ9.eyJzdWIi..."
Get user JWT with expiration and extra info notary . issue_connection_token ( sub : ' 1 ' exp : 3600 info : { ' role ' = > ' admin ' } ) # = > " eyJhbGciOiJIUzI1NiJ9 . eyJzdWIi ... "
see
None