Class: OmniAuth::Strategies::OpenID
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::OpenID
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omniauth/strategies/open_id.rb
Direct Known Subclasses
Constant Summary collapse
- IDENTIFIER_URL_PARAMETER =
'openid_url'
- 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 Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #auth_hash ⇒ Object
- #ax_user_info(response) ⇒ Object
- #callback_phase ⇒ Object
- #callback_url ⇒ Object
- #dummy_app ⇒ Object
- #get_identifier ⇒ Object
- #identifier ⇒ Object
-
#initialize(app, store = nil, options = {}) ⇒ OpenID
constructor
A new instance of OpenID.
- #request_phase ⇒ Object
- #sreg_user_info(response) ⇒ Object
- #start ⇒ Object
- #user_info(response) ⇒ Object
Constructor Details
#initialize(app, store = nil, options = {}) ⇒ OpenID
Returns a new instance of OpenID.
26 27 28 29 30 31 32 |
# File 'lib/omniauth/strategies/open_id.rb', line 26 def initialize(app, store = nil, = {}) super(app, .delete(:name) || :open_id) @options = @options[:required] ||= [AX[:email], AX[:first_name], AX[:last_name], 'email', 'fullname'] @options[:optional] ||= [AX[:nickname], AX[:city], AX[:state], AX[:website], AX[:image], 'postcode', 'nickname'] @store = store end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/omniauth/strategies/open_id.rb', line 10 def @options end |
Instance Method Details
#auth_hash ⇒ Object
87 88 89 90 91 92 |
# File 'lib/omniauth/strategies/open_id.rb', line 87 def auth_hash OmniAuth::Utils.deep_merge(super(), { 'uid' => @openid_response.display_identifier, 'user_info' => user_info(@openid_response) }) end |
#ax_user_info(response) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/omniauth/strategies/open_id.rb', line 109 def ax_user_info(response) ax = ::OpenID::AX::FetchResponse.from_success_response(response) return {} unless ax { 'email' => ax[AX[:email]], 'name' => ax[AX[:name]], 'location' => ("#{ax[AX[:city]]}, #{ax[AX[:state]]}" if Array(ax[AX[:city]]).any? && Array(ax[AX[:state]]).any?), 'nickname' => ax[AX[:nickname]], 'urls' => ({'Website' => Array(ax[AX[:website]]).first} if Array(ax[AX[:website]]).any?) }.inject({}){|h,(k,v)| h[k] = Array(v).first; h}.reject{|k,v| v.nil? || v == ''} end |
#callback_phase ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/omniauth/strategies/open_id.rb', line 75 def callback_phase env['REQUEST_METHOD'] = 'GET' openid = Rack::OpenID.new(lambda{|env| [200,{},[]]}, @store) openid.call(env) @openid_response = env.delete('rack.openid.response') if @openid_response && @openid_response.status == :success super else fail!(:invalid_credentials) end end |
#callback_url ⇒ Object
43 44 45 46 47 |
# File 'lib/omniauth/strategies/open_id.rb', line 43 def callback_url uri = URI.parse(request.url) uri.path += '/callback' uri.to_s end |
#dummy_app ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/omniauth/strategies/open_id.rb', line 34 def dummy_app lambda{|env| [401, {"WWW-Authenticate" => Rack::OpenID.build_header( :identifier => identifier, :return_to => callback_url, :required => @options[:required], :optional => @options[:optional] )}, []]} end |
#get_identifier ⇒ Object
68 69 70 71 72 73 |
# File 'lib/omniauth/strategies/open_id.rb', line 68 def get_identifier OmniAuth::Form.build('OpenID Authentication') do label_field('OpenID Identifier', IDENTIFIER_URL_PARAMETER) input_field('url', IDENTIFIER_URL_PARAMETER) end.to_response end |
#identifier ⇒ Object
49 50 51 |
# File 'lib/omniauth/strategies/open_id.rb', line 49 def identifier [:identifier] || request[IDENTIFIER_URL_PARAMETER] end |
#request_phase ⇒ Object
53 54 55 |
# File 'lib/omniauth/strategies/open_id.rb', line 53 def request_phase identifier ? start : get_identifier end |
#sreg_user_info(response) ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/omniauth/strategies/open_id.rb', line 98 def sreg_user_info(response) sreg = ::OpenID::SReg::Response.from_success_response(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
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/omniauth/strategies/open_id.rb', line 57 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 |
#user_info(response) ⇒ Object
94 95 96 |
# File 'lib/omniauth/strategies/open_id.rb', line 94 def user_info(response) sreg_user_info(response).merge(ax_user_info(response)) end |