无法通过Pusher发送身份验证

时间:2019-08-23 17:07:10

标签: ruby authentication pusher

我正在尝试将身份验证请求发送到加密货币交易所的数据流。 Documentation here

为方便起见,here's the Pusher documentation

首先,该代码适用于公共频道。没问题。我只有身份验证问题。 我知道我的JWT是正确生成的,因为我可以通过HTTP API进行身份验证。我只是无法将有效载荷发送到交换机。


require 'pusher-client'
require_relative './JWTliq'

channels_client = PusherClient::Socket.new('LIQUID', {
      secure: true,
      ws_host: 'tap.liquid.com'
  })

channels_client.subscribe('/realtime')

  channels_client['/realtime'].bind('connected') do
    auth2 = generatejwt('/realtime')
     auth_payload = {
        path: '/realtime',
         headers: {
             "X-Quoine-Auth": auth2
        }
  }
  channels_client.send_event('quoine:auth_request', auth_payload)
  end


 channels_client.subscribe('user_executions_cash_btceur_trades')
  channels_client['user_executions_cash_btceur_trades'].bind('updated') do |data|
    puts data
  end

  channels_client.connect


loop do
    sleep(1)
  end

auth_payload的构造正确,我已经从调试器中进行了检查。另一个问题是“ channels_client ['/ realtime']。bind('connected')确实”从未触发。当我只用Sleep(2)或其他东西替换它时,出现此错误:

C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/pusher-client-0.6.2/lib/pusher-client/socket.rb:182:in `send_event': undefined method `{"event":"quoine:auth_request","data":{"path":"/realtime","headers":{"X-Quoine-Auth":"mygeneratedjwtishere"}}}' for nil:NilClass (NoMethodError)
Uncaught exception: undefined method `{"event":"quoine:auth_request","data":{"path":"/realtime","headers":{"X-Quoine-Auth":"mygeneratedjwtishere"}}}' for nil:NilClass
        C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/pusher-client-0.6.2/lib/pusher-client/socket.rb:182:in `send_event'

0 个答案:

没有答案