【发布时间】:2010-03-22 12:10:19
【问题描述】:
我正在我的 Rails 应用程序中实施 OpenID 的第一步。 open_id_authentication 似乎是一个相当易于使用的插件,这就是我决定使用它的原因。
使用我的 Google 帐户登录似乎可以正常工作,但是我没有获得所需的 sreg/AX 字段。 我的代码目前如下:
class SessionsController < ApplicationController
def new; end
def create
open_id_authentication
end
protected
def open_id_authentication
authenticate_with_open_id(params[:openid_identifier], :required => ["http://axschema.org/contact/email"]) do |result, identity_url, registration|
if result.successful?
p registration.data
@current_user = User.find_by_identity_url(identity_url)
if @current_user
successful_login
else
failed_login "Sorry, no user by that identity URL exists (#{identity_url})"
end
else
failed_login result.message
end
end
end
private
def successful_login
session[:user_id] = @current_user.id
redirect_to(root_url)
end
def failed_login(message)
flash[:error] = message
redirect_to(new_session_url)
end
end
我已经阅读了有关 Google OpenID 的各种讨论,并且都只说您需要 AX 架构而不是 sreg 字段 email,但即使我这样做(如您在上面的代码中所见) ,registration.data 将保持为空 ({})。
如何通过 open_id_authentication 有效地要求来自大多数 OpenID 提供商的电子邮件?
【问题讨论】:
标签: ruby-on-rails openid