Sha256: 0bced50712299eda088798993a4f1563192fe7177b85bf1b5b57580b346f2d77

Contents?: true

Size: 629 Bytes

Versions: 3

Compression:

Stored size: 629 Bytes

Contents

require 'openssl'
require 'base64'

module Stream
  class Signer
    @key = nil

    def initialize(key)
      @key = key.to_s
    end

    def self.create_user_token(user_id, payload = {}, api_secret)
      payload['user_id'] = user_id
      return JWT.encode(payload, api_secret, 'HS256')
    end

    def self.create_jwt_token(resource, action, api_secret, feed_id = nil, user_id = nil)
      payload = {
          resource: resource,
          action: action
      }
      payload['feed_id'] = feed_id if feed_id
      payload['user_id'] = user_id if user_id

      JWT.encode(payload, api_secret, 'HS256')
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
stream-ruby-3.1.0 lib/stream/signer.rb
stream-ruby-3.0.1 lib/stream/signer.rb
stream-ruby-3.0.0 lib/stream/signer.rb