0
我構建了與各種平臺客戶端交互的Rails API。在服務器端實現了類似的服務器服務器:RAILS Faye - 令牌認證
Faye::RackAdapter.new(:mount => '/faye', :timeout => 25)
在服務器端,我想通過令牌添加驗證。我使用faye擴展:
class ServerAuth
def incoming(message, callback)
# Let non-subscribe messages throughs
unless message['channel'] == '/meta/subscribe'
return callback.call(message)
end
# Get subscribed channel and auth token
msg_token = message['ext'] && message['ext']['authToken']
# Add an error if the tokens don't match
if msg_token != '12345'
message['error'] = 'Invalid subscription auth token'
end
# Call the server back now we're done
callback.call(message)
end
end
其實它不工作,除了我。當客戶端傳遞正確的令牌時,一切似乎都沒問題,但是當他傳遞無效令牌時,他仍然可以推送消息,甚至可以從服務器獲取錯誤消息。我應該如何阻止這樣的消息,客戶端不會收回它們(顯然在服務器端)。