require 'omniauth' require 'omniauth-persona' require 'faraday' require 'multi_json' module OmniAuth module Strategies class Persona include OmniAuth::Strategy option :verify_url, 'https://verifier.login.persona.org/verify' option :name, 'persona' option :audience_url, nil def other_phase if on_path?(failure_path) fail!('invalid_credentials') else call_app! end end def failure_path options[:failure_path] || "#{path_prefix}/failure" end def request_phase OmniAuth::Form.build( :title => "Persona Login", :url => callback_path, :header_info => <<-HTML HTML ) do |f| f.html "
Click 'Connect' to sign in with Persona.
" end.to_response end uid{ raw_info['email'] } extra{ {:raw_info => raw_info} } info do { :name => raw_info['email'], :email => raw_info['email'] } end def raw_info response = connection.post('', :assertion => request.params['assertion'], :audience => full_host ) MultiJson.decode(response.body) end def connection Faraday.new(:url => options[:verify_url]) end end end end