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
23 changes: 15 additions & 8 deletions lib/sinatra/browserid.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions sinatra-browserid.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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