Forum: Ruby on Rails Problem with MyOpenID.com Simple Registration Extension

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3d04cbd5016544f9eff1c3fbbbbea379?d=identicon&s=25 Dondi (Guest)
on 2007-03-19 02:25
(Received via mailing list)
I'm having problems with Simple Registration Extension with the Ruby
OpenID Login Generator. The code executes without error; but the
provider apparently returns only the sreg.email field, and none of the
others (e.g., sreg.gender, sreg.postcode, etc).

I'm using MyOpenID.com as the provider as they've announced support
for Simple Registration Extension.

Here is the code segment from the openid_account_controller/complete
method (where the user is create and the extended data is append):

# create user object if one does not exist

if @user.nil ?
  registration_info = response.extension_response('sreg')
  @user = User.new(:openid_url => response.identity_url)
  @user.email = registration_info['email']
  @user.gender = registration_info['gender']
  @user.save
end

The code executes without any errors. However, when I check the user
table, *only* the email field is populated; the gender field is not.

Any idea what may be causing the problem? Thx,

Dondi.
Dfd6f9989147955682701da8227df8b4?d=identicon&s=25 Michael Wang (Guest)
on 2007-03-19 03:06
(Received via mailing list)
Dondi wrote:
>
> The code executes without any errors. However, when I check the user
> table, *only* the email field is populated; the gender field is not.
>
> Any idea what may be causing the problem? Thx,

I haven't used that generator before but presumably
registration_info['gender'] is returning "" or nil.

Add something like this to your code:

if @user.nil?
   registration_info = response.extension_response('sreg')
   logger.debug("registration_info: #{registration_info.inspect}")

and see what the values are that are being set in the registration_info
hash. Perhaps your form has some errors in it.


--
Michael Wang
3d04cbd5016544f9eff1c3fbbbbea379?d=identicon&s=25 Dondi (Guest)
on 2007-03-19 05:46
(Received via mailing list)
Thanks Michael.  The problem was with my 'Login' method.  I changed
the following:

  def login
    openid_url = @params[:openid_url]

    if @request.post?
      request = consumer.begin(openid_url)

      case request.status
      when OpenID::SUCCESS
        #request additional profile data: email, gender, state
        request.add_extension_arg('sreg','required','email, gender,
postcode')
        ...

To this:

  def login
    openid_url = @params[:openid_url]

    if @request.post?
      request = consumer.begin(openid_url)

      case request.status
      when OpenID::SUCCESS
        #request additional profile data: email, gender, state
        unless User.find_by_openid_url(request.identity_url)
          request.add_extension_arg('sreg', 'required',
'email,gender,postcode')
        end
      ...

The conditional request (via 'unless User.Find_...') is obviously
better coding; but I'm at a loss as to why the latter works, and why
the former didn't since the 'request.add_extension_arg(...)' statement
is identical. ???
This topic is locked and can not be replied to.