Class: Pushkin::Faye::Authentication
- Inherits:
-
Object
- Object
- Pushkin::Faye::Authentication
- Defined in:
- lib/pushkin/faye/authentication.rb
Instance Method Summary collapse
- #authenticate_publish(message) ⇒ Object
- #authenticate_subscribe(message) ⇒ Object
- #incoming(message, callback) ⇒ Object
Instance Method Details
#authenticate_publish(message) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/pushkin/faye/authentication.rb', line 30 def authenticate_publish() if Pushkin.secret_token.nil? raise AuthenticationError.new("No secret_token config set") elsif ["ext"]["pushkin_token"] != Pushkin.secret_token ["error"] = "Incorrect token." else ["ext"]["pushkin_token"] = nil end end |
#authenticate_subscribe(message) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pushkin/faye/authentication.rb', line 15 def authenticate_subscribe() signature = ["ext"]["pushkin_signature"] = ["ext"]["pushkin_timestamp"] subscription = Pushkin::Subscription.new \ channel: ["subscription"], timestamp: if signature != subscription.signature ["error"] = "Incorrect signature." elsif subscription.signature_expired? ["error"] = "Signature has expired." end end |
#incoming(message, callback) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/pushkin/faye/authentication.rb', line 6 def incoming(, callback) if ["channel"] == '/meta/subscribe' authenticate_subscribe() elsif ["channel"] !~ %r{^/meta/} authenticate_publish() end callback.call() end |