Problem with MyOpenID.com Simple Registration Extension


#1

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.


#2

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 W.


#3

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. ???