title: Ruby-OpenID: Requiring email-address from OpenID provider
body: <p>I'm playing with the <a href="http://github.com/binarylogic/authlogic_example/tree/with-openid" rel="nofollow noreferrer">authlogic-example-app</a> and I'm failing to get the email address from the OpenID provider (in my case: Google and Yahoo) when I register a user, resp. I get an empty response instead of an email address (check the comments in code below).</p>
  
  <p>This is how my user model looks like (everything else looks like the "with_openid"-branch of the authlogic-example-app mentioned above). Besides the missing 'email', the openid-authentication-process works as expected:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    acts_as_authentic do |c| 
      # not needed because I use OpenID
      c.validate_login_field = false
      # avoid failed validation before OpenID request
      c.validate_email_field = false
      # this one sets 'openid.sreg.required=email'
      c.required_fields = [:email]
    end
  
    private
  
    # overwriting the existing method in '/lib/authlogic_openid/acts_as_authentic.rb'
    def map_openid_registration(registration)
      # this is my problem: 'registration' is an empty hash
      self.email ||= registration[:email] if respond_to?(:email) &amp;&amp; !registration[:email].blank?
    end
  
  end
  </code></pre>
  
  <p>Any idea how to solve this? Has anyone here done this before using <a href="http://github.com/binarylogic/authlogic_openid/tree/master" rel="nofollow noreferrer">authlogic</a>? Or even better: Do you have a working example?</p>
  
  <p><strong>Update</strong>: I checked the <a href="http://code.google.com/apis/accounts/docs/OpenID.html" rel="nofollow noreferrer">Google Account Authentication API</a> and compared the request submitted by <a href="http://github.com/binarylogic/authlogic_openid/tree/master" rel="nofollow noreferrer">authlogic</a> (using <a href="http://openidenabled.com/ruby-openid/" rel="nofollow noreferrer">ruby-openid-gem</a> and <a href="http://github.com/rails/open_id_authentication/tree/master" rel="nofollow noreferrer">openid-authentication-plugin</a>) with the <a href="http://code.google.com/apis/accounts/docs/OpenID.html#Samples" rel="nofollow noreferrer">example requests</a> on the Google Account Authentication API docs:</p>
  
  <hr>
  
  <p><strong>Example request to authenticate and fetch email address by Google</strong>:</p>
  
  <pre><code>https://www.google.com/accounts/o8/ud
  ?openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0
  &amp;openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
  &amp;openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
  &amp;openid.return_to=http%3A%2F%2Fwww.example.com%2Fcheckauth
  &amp;openid.realm=http%3A%2F%2Fwww.example.com%2F
  &amp;openid.assoc_handle=ABSmpf6DNMw
  &amp;openid.mode=checkid_setup
  &amp;openid.ns.ext1=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0
  &amp;openid.ext1.mode=fetch_request
  &amp;openid.ext1.type.email=http%3A%2F%2Faxschema.org%2Fcontact%2Femail
  &amp;openid.ext1.required=email
  </code></pre>
  
  <hr>
  
  <p><strong>Request submitted by my appliation</strong>:</p>
  
  <pre><code>https://www.google.com/accounts/o8/ud
  ?openid.assoc_handle=AOQobUcdICerEyK6SXJfukaz8ygXiBqF_gKXv68OBtPXmeafBSdZ6576
  &amp;openid.ax.mode=fetch_request
  &amp;openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
  &amp;openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
  &amp;openid.mode=checkid_setup
  &amp;openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0
  &amp;openid.ns.ax=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0
  &amp;openid.ns.sreg=http%3A%2F%2Fopenid.net%2Fextensions%2Fsreg%2F1.1
  &amp;openid.realm=http%3A%2F%2Flocalhost%3A3000%2F
  &amp;openid.return_to=http%3A%2F%2Flocalhost%3A3000%2Faccount%3Ffor_model%3D1%26_method%3Dpost%26open_id_complete%3D1
  &amp;openid.sreg.required=email
  </code></pre>
  
  <p>While debugging the whole setup, I've found out that the <a href="http://github.com/rails/open_id_authentication/tree/master" rel="nofollow noreferrer">openid-authentication-plugin</a> never receives an email in the response it receives from the openid provider, this at least explains why the <code>registration</code> hash in my user-model is empty...</p>
  
  <p><strong>UPDATE</strong>: If you're playing around with authlogic and openid, don't forget to check out the <a href="http://railscasts.com/episodes/170-openid-with-authlogic" rel="nofollow noreferrer">latest railscast on this subject</a>!</p>