diff --git a/lib/sinatra/browserid.rb b/lib/sinatra/browserid.rb old mode 100644 new mode 100755 index 39ba9b1..4de2191 --- a/lib/sinatra/browserid.rb +++ b/lib/sinatra/browserid.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby require "json" -require "net/https" +require 'curb' require "sinatra/base" # This module provides an interface to verify a users email address @@ -77,21 +77,28 @@ def self.registered(app) app.post '/_browserid_assert' do # TODO(petef): do verification locally, without a callback - audience = request.host_with_port - bid_uri = URI.parse(settings.browserid_url) - http = Net::HTTP.new(bid_uri.host, bid_uri.port) - http.use_ssl = true data = { "assertion" => params[:assertion], - "audience" => audience, + "audience" => request.host_with_port, } data_str = data.collect { |k, v| "#{k}=#{v}" }.join("&") - res, body = http.post("/verify", data_str) + body = "" + c = begin + Curl::Easy.http_post(settings.browserid_url + "/verify") do |curl| + curl.use_ssl = Curl::CURL_USESSL_ALL + curl.post_body = data_str + curl.on_body {|data| body << data; data.length} + end + rescue Exception => e + # Processing error + $stderr.puts "request was not successful. #{e.message}" + return + end - # TODO: check res is a 200 verify = JSON.parse(body) || nil if verify.nil? # JSON parsing error + $stderr.puts "Invalid Response" return end diff --git a/sinatra-browserid.gemspec b/sinatra-browserid.gemspec index cd7dac6..18b6573 100644 --- a/sinatra-browserid.gemspec +++ b/sinatra-browserid.gemspec @@ -13,4 +13,5 @@ Gem::Specification.new do |s| s.summary = "Sinatra extension for user authentication with browserid.org" s.add_dependency("sinatra", ">= 1.1.0") + s.add_dependency("curb", ">= 0.8.0") end