Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ module PrivatePub
end
PrivatePub.set_config secret_token: ENV['SECRET_KEY']

require 'logger'
Faye.logger = Logger.new(STDOUT)
Faye.logger.level = Logger::INFO

require './lib/private_faye'

options = {
Expand All @@ -27,8 +31,9 @@ options = {
}

Faye::WebSocket.load_adapter('thin')
run Faye::RackAdapter.new(options)
client = Faye::RackAdapter.new(options)

require 'logger'
Faye.logger = Logger.new(STDOUT)
Faye.logger.level = Logger::INFO
client.on(:disconnect) do |client_id|
Faye.logger.info "#{client_id} has been disconnected"
end
run client
10 changes: 10 additions & 0 deletions lib/private_faye.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def incoming(message, callback)
end

def authenticate_subscribe(message)
Faye.logger.info("!!! Attempting authenticated subscription for:")
Faye.logger.info(message)
Faye.logger.info("!!!")

if message["ext"].nil?
message["error"] = "Extension data is missing"
return message
Expand All @@ -17,8 +21,12 @@ def authenticate_subscribe(message)
subscription = PrivatePub.subscription(:channel => message["subscription"], :timestamp => message["ext"]["private_pub_timestamp"])
if message["ext"]["private_pub_signature"] != subscription[:signature]
message["error"] = "Incorrect signature."
Faye.logger.info "WARNING!!!"
Faye.logger.info message["error"]
elsif PrivatePub.signature_expired? message["ext"]["private_pub_timestamp"].to_i
message["error"] = "Signature has expired."
Faye.logger.info "WARNING!!!"
Faye.logger.info message["error"]
end
end
def authenticate_publish(message)
Expand All @@ -31,6 +39,8 @@ def authenticate_publish(message)
raise Error, "No secret_token config set, ensure private_pub.yml is loaded properly."
elsif message["ext"]["private_pub_token"] != PrivatePub.config[:secret_token]
message["error"] = "Incorrect token."
Faye.logger.info "WARNING!!!"
Faye.logger.info message["error"]
else
message["ext"]["private_pub_token"] = nil
end
Expand Down