1 $:.unshift(File.dirname(__FILE__), '..', 'lib')
7 module Rots::RequestHelper
9 def checkid_setup(request, params={}, with_associate=true)
10 assoc_handle = make_association(request) if with_associate
11 send_checkid(request, :setup, params, assoc_handle)
14 def checkid_immediate(request, params={}, with_associate=true)
15 assoc_handle = make_association(request) if with_associate
16 send_checkid(request, :immediate, params, assoc_handle)
19 def openid_params(response)
20 uri = URI(response.headers['Location'])
21 Rack::Utils.parse_query(uri.query)
26 def send_checkid(request, mode, params={}, assoc_handle = nil)
27 params = self.send(:"checkid_#{mode}_params", params)
28 params.merge('openid.assoc_handle' => assoc_handle) if assoc_handle
29 qs = "/?" + Rack::Utils.build_query(params)
33 def make_association(request)
34 associate_qs = Rack::Utils.build_query(associate_params)
35 response = request.post('/', :input => associate_qs)
36 parse_assoc_handle_from(response)
39 def parse_assoc_handle_from(response)
40 response.body.split("\n")[0].match(/^assoc_handle:(.*)$/).captures[0]
43 def checkid_setup_params(params = {})
45 "openid.ns" => "http://specs.openid.net/auth/2.0",
46 "openid.mode" => "checkid_setup",
47 "openid.claimed_id" => 'john.doe',
48 "openid.identity" => 'john.doe',
49 "openid.return_to" => "http://www.google.com"
50 # need to specify the openid_handle by hand
54 def checkid_immediate_params(params = {})
55 checkid_setup_params({'openid.mode' => 'checkid_immediate'}.merge!(params))
60 "openid.ns" => "http://specs.openid.net/auth/2.0",
61 "openid.mode" => "associate",
62 "openid.session_type" => "DH-SHA1",
63 "openid.assoc_type" => "HMAC-SHA1",
64 "openid.dh_consumer_public" =>
65 "U672/RsDUNxAFFAXA+ShVh5LMD2CRdsoqdqhDCPUzfCNy2f44uTWuid/MZuGfJmiVA7QmxqM3GSb8EVq3SGK8eGEwwyzUtatqHidx72rfwAav5AUrZTnwSPQJyiCFrKNGmNhXdRJzcfzSkgaC3hVz2kpADzEevIExG6agns1sYY="
71 Spec::Runner.configure do |config|
72 config.include Rots::RequestHelper