4

I'm using the rails plugin open_id_authentication in my app. This works for MyOpenID, however authenticating with Google I can't get the email address as part of the required attributes.

From what I understand, Google ignores sreg attribute requests, and only listens to the AX schema for email address.

Here's my code:

     def open_id_authentication(openid_url)

       #google only responds to AX for email, so we must provide that also
       authenticate_with_open_id(openid_url, :required => [:nickname, :email, 'http://axschema.org/contact/email']) do |result, identity_url, registration|
        if result.successful?    
         @user = User.find_or_initialize_by_identity_url(identity_url)
         if @user.new_record?            
             unless registration['email'] || registration['http://axschema.org/contact/email']          
                 failed_login "Your OpenID provider didn't send us an email address."
                 return
              end

          #some providers (like Google) won't send a nick name.  We'll use email instead for those
          nick = registration['nickname']
          nick |= registration['email']
          nick |= registration['http://axschema.org/contact/email']

          email = registration['email'];
          email |= registration['http://axschema.org/contact/email']

          @user.login = nick
          @user.email = email
          @user.save(false)
     end
     self.current_user = @user
     successful_login
    else
       failed_login result.message
    end
   end

My understanding is that I submit the email address (both sreg and AX) as required and I should be able to pull them out of the registration instance that is passed along with the response.

When I log in with Google the email address is passed back as 't'.

Am I handling this incorrectly? How can I get the user's email address from Google? Will I have to jump through any other hoops to support Yahoo?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Ben Scheirman
  • 40,531
  • 21
  • 102
  • 137

4 Answers4

7

I ended up solving this one myself. It wasn't easy finding official docs on which AX schema URLs are supported.

Here's what I found:

Google will respond only to email address using the AX schema: http://schema.openid.net/contact/email

Yahoo will respond to alias & email using these AX schemas:

http://axschema.org/namePerson/friendly
http://axschema.org/contact/email

So I need to request basically all of the known AX schema URLs for email address and hope the provider sends it. /shrug

Ben Scheirman
  • 40,531
  • 21
  • 102
  • 137
  • 2
    Ah, a blog post of mine comes to mind: http://blog.nerdbank.net/2009/03/how-to-pretty-much-guarantee-that-you.html Incidentally, Google supports the axschema.org format also, I'm pretty sure. – Andrew Arnott Dec 25 '09 at 05:52
  • I have 3 different urls for email, but google only responds to the one in http://schema.openid.net/contact/email (in my testing). This is quite annoying, seems like it wouldn't hurt them to be a little more flexible regarding attribute exchange. – Ben Scheirman Dec 25 '09 at 18:32
  • I don't know why google is not responding to the axschema.org url for you. I have one up and running here: http://testingauth.heroku.com , source: http://github.com/shripadk/authlogic_openid_selector_example , which is more or less similar to stackoverflow auto-registration. It uses axschema format and google responds with the email id. – Shripad Krishna Aug 03 '10 at 07:24
  • It certainly wasn't at the time, but that was a while ago. Perhaps they changed it? – Ben Scheirman Aug 03 '10 at 15:17
  • Maybe they did. However, i am not able to receive any other ax attribute other than email and language! Strange. Are you able to retrieve other attributes too? Particularly the name attribute. – Shripad Krishna Aug 16 '10 at 07:50
2

As another poster has already mentioned, Google responds to the AX schema for e-mail now. I know that this post was written a while ago, but Google still does not respond to namePerson. However, they do provide:

http://axschema.org/namePerson/first 
http://axschema.org/namePerson/last

Therefore, to answer Shripad K's question above, you could do, using the code above as an example:

name = [
        registration['http://axschema.org/namePerson/first'],
        registration['http://axschema.org/namePerson/last']
       ].join(" ")
Sean Hill
  • 14,978
  • 2
  • 50
  • 56
1

I don't know the Ruby OpenID library you're using very well, but it looks like you're trying to use AX by mixing its attribute Type URIs into the Simple Registration extension, which is a very different beast. You should (since I don't know it by heart) check out the docs or samples for OpenID use with the library you're using for AX specifically and make sure you're following the right steps. Google only supports AX, whereas Yahoo supports Simple Registration (I'm not sure if Yahoo also supports AX at this point).

Andrew Arnott
  • 80,040
  • 26
  • 132
  • 171
  • Yahoo also supports AX: http://developer.yahoo.net/blog/archives/2009/12/yahoo_openid_now_with_attribute_exchange.html – dhofstet Dec 24 '09 at 05:57
  • 1
    at the bottom of the README of that plugin, it shows an example where you either pass a ruby symbol OR a string (for AX). What they don't show is retrieval. – Ben Scheirman Dec 24 '09 at 13:19
0

For me it still didn't work with http://schema.openid.net/contact/email but found out here https://groups.google.com/forum/?fromgroups=#!topic/google-federated-login-api/dOrQ8Ho5BGI that it must be openid.ax.required and that worked.

Peter Hudec
  • 2,462
  • 3
  • 22
  • 29