Permalink
Browse files

add webhook verification

  • Loading branch information...
1 parent 94223a6 commit a4ea470a10d7f0b3172b9fad76a0dadecd5dda13 @jackowayed jackowayed committed with Jul 3, 2010
Showing with 16 additions and 1 deletion.
  1. +16 −1 lib/notifo.rb
View
@@ -1,4 +1,6 @@
require 'httparty'
+require 'cgi'
+require 'digest/sha1'
class Notifo
include HTTParty
@@ -28,4 +30,17 @@ def post(username, msg, title=nil, uri=nil)
options = { :body => {:to => username, :msg => msg, :title=>title, :uri=>uri}, :basic_auth => @auth }
self.class.post('/send_notification', options)
end
-end
+
+ # Require Parameters
+ # params - the hash of params the webhook passed to you. All keys must be *Strings*, not symbols.
+ def verify_webhook_signature(params)
+ signature = params['notifo_signature']
+ other_notifo_params = params.reject {|key,val| !(key =~ /\Anotifo_/ && key != "notifo_signature")}
+ str = other_notifo_params.keys.sort.map do |key|
+ params[key]
+ end.join
+ str << @auth[:password]
+
+ signature == Digest::SHA1.hexdigest(CGI::escape(str))
+ end
+end

0 comments on commit a4ea470

Please sign in to comment.