Ever wonder how to implement OpenID authentication in your Rails app? This episode will show you how to add it to a site with an existing authentication system.
# routes.rb
map.open_id_complete 'session', :controller => "session", :action => "create", :requirements => { :method => :get }
# session_controller.rb
class SessionController < ApplicationController
# render new.rhtml
def new
end
def create
if using_open_id?
open_id_authentication(params[:openid_url])
else
password_authentication(params[:login], params[:password])
end
end
def destroy
self.current_user.forget_me if logged_in?
cookies.delete :auth_token
reset_session
flash[:notice] = "You have been logged out."
redirect_back_or_default('/')
end
protected
def open_id_authentication(openid_url)
authenticate_with_open_id(openid_url, :required => [:nickname, :email]) do |result, identity_url, registration|
if result.successful?
@user = User.find_or_initialize_by_identity_url(identity_url)
if @user.new_record?
@user.login = registration['nickname']
@user.email = registration['email']
@user.save(false)
end
self.current_user = @user
successful_login
else
failed_login result.message
end
end
end
def password_authentication(login, password)
self.current_user = User.authenticate(login, password)
if logged_in?
successful_login
else
failed_login
end
end
def failed_login(message = "Authentication failed.")
flash.now[:error] = message
render :action => 'new'
end
def successful_login
if params[:remember_me] == "1"
self.current_user.remember_me
cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at }
end
redirect_back_or_default('/')
flash[:notice] = "Logged in successfully"
end
end
分享到:
相关推荐
OpenID Authentication 2.0,简称OpenID 2.0,是一种开放标准的协议,用于跨网站的身份验证,允许用户通过第三方身份提供商进行登录,而无需在每个网站上单独创建和维护账户。这种机制不仅简化了用户的登录流程,还...
根据提供的文件信息,我们可以从中提炼出关于OpenID的相关知识点,主要围绕着OpenID的基本概念、工作原理以及示例代码中的具体实现来进行详细说明。 ### OpenID 概念 OpenID 是一种开放标准协议,用于在网络上进行...
Aspnet-OpenId.AspNet.Authentication.zip,旧版asp.net web应用程序的openid connect身份验证openid.aspnet.authentication,asp.net是一个开源的web框架,用于使用.net构建现代web应用和服务。asp.net创建基于html5...
熊猫4 PANDAS Web归档工作流系统的第四代。 该项目处于早期开发阶段...PORT=3001# CONTEXT_PATH=/admin# # Path to store lucene indexes# DATA_PATH=/tmp/data# # OpenID Connect authentication (optional)# OIDC_URL
这个中文文档是针对OpenID认证协议2.0的一个实现者草案,旨在帮助开发者理解和实施OpenID协议。 在OpenID协议中,有几个关键概念和术语需要理解: 1. **Identifier**:标识符,用户在网络上的身份标识,可以由用户...
BuildBot-OpenID BuildBot的OpenID授权/身份验证插件注意:更多文档即将发布。 注意2:此代码适用于BuildBot版本8。如何配置在master.cfg中,将authz_cfg =行替换为类似authz_cfg=openidauthz.OpenIDAuthZ( openid_...
5. **Extension Support**:除了基本的OpenID认证,JOpenID还支持OpenID的扩展,比如PAPE(Policy阿凡达Authentication Permissions)用于增强安全性,AX(Attribute Exchange)用于交换用户信息,SREG(Simple ...
- **OpenID (spring-security-openid.jar)**:支持 OpenID 身份验证。 ## 二、安全命名空间配置 ### 2.1 简介 Spring Security 提供了一个专门的安全命名空间配置方式,简化了配置过程,并且提供了高度可配置的...
此外,认证协议的实现还涉及到一系列的协议或标准,例如Kerberos认证协议、SSL/TLS协议、OAuth、OpenID Connect等,这些协议在各种网络环境和应用中扮演着重要的角色。例如,Kerberos是一种常用的网络认证协议,它...
"OpenID-With-Forms-Authentication.pdf" 可能包含了详细的步骤和代码示例,演示如何在 ASP.NET MVC 应用中实现 OpenID 与表单身份验证的集成。"LogOn.aspx?rp..." 文件名看起来像是一个指向具体资源的链接,可能是...
- **Authentication Flow**:实现OAuth 2.0授权码流,包括重定向用户到IDP进行登录,处理回调并获取授权码。 - **Token Exchange**:使用授权码换取访问令牌和ID令牌。 - **Token Validation**:验证ID令牌,确保...
3. **Authentication Request**:JOpenID库可以帮助开发人员构建OpenID认证请求,包含必要的参数如claimed_id、return_to URL等,并将其封装成HTTP重定向请求,发送给用户。 4. **Response Handling**:当用户完成...
- **OpenID** (`spring-security-openid.jar`):OpenID协议支持。 ### 1.5 源代码检查 对于有兴趣深入研究Spring Security内部实现的开发者,可以考虑检查其源代码,以获得更深入的理解和定制能力。 **二、安全...
ASP.NET Core还提供了其他身份验证机制,如Cookie认证、OAuth2、OpenID Connect等,可以根据实际需求选择合适的方案。对于JWT,它的优点在于轻量级、自包含和跨域支持,常用于API和微服务的认证。 总的来说,ASP...
Agresso.Interface.Authentication.dll Agresso.Interface.CoreServices.dll 该项目是使用Visual Studio 2012创建的。 安装 Newtonsoft.Json.dll必须复制到二进制文件夹 必须将来自app.config的Appsettings放入...
标签"Authentication-"强调了文件与身份验证相关的主题,这通常涉及到网络安全、用户身份验证机制、密码学、令牌、证书、OAuth、OpenID Connect等技术。这些技术是保护系统免受未授权访问的关键组成部分。 压缩包内...
ORY Hydra是经过强化,经过OpenID认证的OAuth 2.0服务器和OpenID Connect提供商,针对低延迟,高吞吐量和低资源消耗进行了优化。 ORY Hydra不是身份提供者(用户注册,用户登录,密码重置流程),而是通过登录和同意...
openid-connect-provider-debugger 使用简单的依赖方(RP)测试和诊断OpenID Connect(OIDC)提供程序(OP)的docker映像。 跑步 要启动调试器,您需要从OP中获取以下信息: 客户编号。 客户机密。 发现URI...
hoba认证概述hoba-authentication... 确定身份验证方案并将对注册表的需求降至最低(不仅因为这个,而且因为这个,服务决定使用社交登录来注册和验证他们的用户——OAuth 和最近的 OpenID Connect 获得了动力! )。 身
- **认证(Authentication)**:验证用户的身份,确保用户是他们声称的人。 - **授权(Authorization)**:允许用户授权第三方应用访问特定资源。 - **ID Token**:OIDC的核心部分,包含用户的基本信息,如用户ID,用于...