3
我正在将应用程序移动到仅使用Google联合登录(OpenID)的应用程序(我们对所有应用程序都使用Google应用程序,并认为将用户管理结合起来会更容易) 。虽然我可以成功登录并创建用户,但我现在的想法是安全的...Rails中的Google Apps和Open ID身份验证 - 安全
当用户登录时,我只有一个“登录”按钮 - 没有别的。该网站域名是硬编码的(其中SITE_DOMAIN出现在下面),用户被重定向到典型的谷歌登录页面。
下面是代码:
def create
open_id_authentication
end
protected
def open_id_authentication
openid_url = 'https://www.google.com/accounts/o8/site-xrds?hd=SITE_DOMAIN'
authenticate_with_open_id(openid_url,
:required => ['http://axschema.org/contact/email',
'http://axschema.org/namePerson/first',
'http://axschema.org/namePerson/last']) do |result, identity_url, registration|
case result.status
when :missing
failed_login "Sorry, the OpenID server couldn't be found"
when :invalid
failed_login "Sorry, but this does not appear to be a valid OpenID"
when :canceled
failed_login "OpenID verification was canceled"
when :failed
failed_login "Sorry, the OpenID verification failed"
when :successful
if @current_user = User.find_by_id_url(identity_url)
if @current_user.login_from(request.env['REMOTE_ADDR'])
successful_login
else
failed_login "Your OpenID profile registration failed: " + @current_user.errors.full_messages.to_sentence
end
else
ax_response = OpenID::AX::FetchResponse.from_success_response(request.env[Rack::OpenID::RESPONSE])
@current_user = User.login_create(ax_response, identity_url, request.env['REMOTE_ADDR'])
successful_login
end
end
end
end
成功登录后,我只是用户保存到一个会话...
session[:current_user] = @current_user
...,并在应用程序控制器使用简单的方法CURRENT_USER ...
def current_user
return session[:current_user] if defined?(session[:current_user])
end
我主要关心的是安全问题。 OpenIDAuthentication使用的是内存中的存储,总体来说这似乎有点太容易实现(阅读大量文档之后)。基本测试显示这工作正常,但我很紧张。 :)
有什么想法?
我使用的open_id_authentication插件和基本红宝石OpenID的宝石(红宝石,OpenID的应用发现宝石的谷歌应用程序)