Class: OmniAuth::Strategies::OpenID
- Inherits:
- 
      Object
      
        - Object
- OmniAuth::Strategies::OpenID
 
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omniauth/strategies/open_id.rb
Overview
OmniAuth strategy for connecting via OpenID. This allows for connection
to a wide variety of sites, some of which are listed on the OpenID website.
Constant Summary collapse
- AX =
- { email: "http://axschema.org/contact/email", name: "http://axschema.org/namePerson", nickname: "http://axschema.org/namePerson/friendly", first_name: "http://axschema.org/namePerson/first", last_name: "http://axschema.org/namePerson/last", city: "http://axschema.org/contact/city/home", state: "http://axschema.org/contact/state/home", website: "http://axschema.org/contact/web/default", image: "http://axschema.org/media/image/aspect11", } 
Instance Method Summary collapse
- 
  
    
      #ax_user_info  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #callback_phase  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #dummy_app  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #get_identifier  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #identifier  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #openid_response  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #request_phase  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #sreg_user_info  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #start  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Instance Method Details
#ax_user_info ⇒ Object
| 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | # File 'lib/omniauth/strategies/open_id.rb', line 129 def ax_user_info ax = ::OpenID::AX::FetchResponse.from_success_response(openid_response) return {} unless ax { "email" => ax.get_single(AX[:email]), "first_name" => ax.get_single(AX[:first_name]), "last_name" => ax.get_single(AX[:last_name]), "name" => (ax.get_single(AX[:name]) || [ax.get_single(AX[:first_name]), ax.get_single(AX[:last_name])].join(" ")).strip, "location" => ("#{ax.get_single(AX[:city])}, #{ax.get_single(AX[:state])}" if Array(ax.get_single(AX[:city])).any? && Array(ax.get_single(AX[:state])).any?), "nickname" => ax.get_single(AX[:nickname]), "urls" => ({"Website" => Array(ax.get_single(AX[:website])).first} if Array(ax.get_single(AX[:website])).any?), }.each_with_object({}) { |(k, v), h| h[k] = Array(v).first }.reject { |k, v| v.nil? || v == "" } end | 
#callback_phase ⇒ Object
| 104 105 106 107 | # File 'lib/omniauth/strategies/open_id.rb', line 104 def callback_phase return fail!(:invalid_credentials) unless openid_response && openid_response.status == :success super end | 
#dummy_app ⇒ Object
| 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | # File 'lib/omniauth/strategies/open_id.rb', line 34 def dummy_app lambda { |env| req = Rack::Request.new(env) root_uri = "#{req.scheme}://#{req.host_with_port}/" trust_root = if .trust_root if .trust_root.respond_to?(:call) .trust_root.call(root_uri) else .trust_root end else %r{^(https?://[^/]+)}.match(callback_url) { |m| m[1] } end [ 401, { "WWW-Authenticate" => Rack::OpenID.build_header( identifier: identifier, return_to: callback_url, trust_root: trust_root, required: .required, optional: .optional, method: "post", immediate: .immediate, ), }, [], ] } end | 
#get_identifier ⇒ Object
| 87 88 89 90 91 92 | # File 'lib/omniauth/strategies/open_id.rb', line 87 def get_identifier f = OmniAuth::Form.new(title: "OpenID Authentication") f.label_field("OpenID Identifier", .identifier_param) f.input_field("url", .identifier_param) f.to_response end | 
#identifier ⇒ Object
| 66 67 68 69 70 | # File 'lib/omniauth/strategies/open_id.rb', line 66 def identifier i = .identifier || request.params[.identifier_param.to_s] i = nil if i == "" i end | 
#openid_response ⇒ Object
| 109 110 111 112 113 114 115 116 | # File 'lib/omniauth/strategies/open_id.rb', line 109 def openid_response unless @openid_response openid = Rack::OpenID.new(lambda { |env| [200, {}, []] }, [:store]) openid.call(env) @openid_response = env.delete("rack.openid.response") end @openid_response end | 
#request_phase ⇒ Object
| 72 73 74 | # File 'lib/omniauth/strategies/open_id.rb', line 72 def request_phase identifier ? start : get_identifier end | 
#sreg_user_info ⇒ Object
| 118 119 120 121 122 123 124 125 126 127 | # File 'lib/omniauth/strategies/open_id.rb', line 118 def sreg_user_info sreg = ::OpenID::SReg::Response.from_success_response(openid_response) return {} unless sreg { "email" => sreg["email"], "name" => sreg["fullname"], "location" => sreg["postcode"], "nickname" => sreg["nickname"], }.reject { |k, v| v.nil? || v == "" } end | 
#start ⇒ Object
| 76 77 78 79 80 81 82 83 84 85 | # File 'lib/omniauth/strategies/open_id.rb', line 76 def start openid = Rack::OpenID.new(dummy_app, [:store]) response = openid.call(env) case env["rack.openid.response"] when Rack::OpenID::MissingResponse, Rack::OpenID::TimeoutResponse fail!(:connection_failed) else response end end |