nbudin / devise_openid_authenticatable

OpenID authentication for Devise
MIT License
99 stars 32 forks source link

adding more required parameters #2

Closed soend closed 14 years ago

soend commented 14 years ago

Hey, i have a question about parameters what are asked from openid server. Right now i think only name is asked. How would it be possible to add requireing nickname and email allso?

greendog99 commented 14 years ago

I've been wanting to do this too. I've been experimenting, but don't have anything working 100% yet. Here's what I did, that works on some OpenID sites... needs more work though...

In devise_openid_authenticatable-1.0.0.alpha/lib/devise_openid_authenticatable/strategy.rb I changed line 33, adding the following "optional" parameter:

header_data = Rack::OpenID.build_header(:identifier => params[scope]["identity_url"], :optional => ["email"])

nbudin commented 14 years ago

I've been meaning to add a feature for full-fledged SReg support to this gem. Basically, greendog99's approach is correct, but I'd like to take it further. The way I'm thinking this could work is in two pieces:

1) We could add a config parameter to specify which fields should be requested from the OpenID provider, using the :optional parameter. For example, in your model, you could say:

devise :openid_authenticatable, :openid_optional_fields => ["email", "name"]

which would cause "email" and "name" to be requested from the provider.

2) The strategy could check the model instance to see if it responds to a method called, say, openid_optional_fields=. That method would take a Hash of the fields passed from the server, and then allow you to use them in whatever way you want. For example:

def openid_optional_fields=(fields)
  fields.each do |key, value|
    case key.to_sym
    when :name
      self.name = value
    when :email
      self.email = value
    end
  end
end
soend commented 14 years ago

Yes, that would be creat. Right now have to settle with authlogic because the openid compability is better.

nbudin commented 14 years ago

OK! As of the new 1.0.0.alpha4, devise_openid_authenticatable supports both SReg and AX fields. See the README for details - it's mostly as I outlined above but some of the details changed in the implementation.

greendog99 commented 14 years ago

Brilliant! Will experiment this weekend.