# Problem with MyOpenID.com Simple Registration Extension

**URL:** <https://www.ruby-forum.com/t/problem-with-myopenid-com-simple-registration-extension/89260>\
**Category:** Rails\
**Created:** [March 19, 2007, 2:25am UTC](https://www.ruby-forum.com/t/problem-with-myopenid-com-simple-registration-extension/89260 "2007-03-19T02:25:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dondi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8797f3/32.png) [@dondi](https://www.ruby-forum.com/u/dondi)\
**Post date:** [March 19, 2007, 2:25am UTC](https://www.ruby-forum.com/t/problem-with-myopenid-com-simple-registration-extension/89260/1 "2007-03-19T02:25:40Z")

</div>

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](http://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.

---

<div class="post-metadata">

**Author:** ![dondi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8797f3/32.png) [@dondi](https://www.ruby-forum.com/u/dondi)\
**Post date:** [March 19, 2007, 3:06am UTC](https://www.ruby-forum.com/t/problem-with-myopenid-com-simple-registration-extension/89260/2 "2007-03-19T03:06:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dondi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8797f3/32.png) [@dondi](https://www.ruby-forum.com/u/dondi)\
**Post date:** [March 19, 2007, 5:46am UTC](https://www.ruby-forum.com/t/problem-with-myopenid-com-simple-registration-extension/89260/3 "2007-03-19T05:46:55Z")

</div>

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