ASP.NET中的安全单点登录,用于通过OpenID从anthother(php)网站进行身份验证
我需要在我的asp.net上实现以下身份验证:asp.net和PHP网站上的用户应该使用OpenID进行身份验证。登录和注册仅存在于PHP网站上。因此,要求如下: 我的ASP.NET网站应该重定向到PHP网站进行身份验证。用户将 使用PHP网站上的OpenID进行身份验证。 如果用户是新用户,我计划使用coookie访问我的ASP.NET网站,它将重定向为空 帕拉马特。否则,我将在重定向请求中传递存储的OpenID。 如果传递的OpenID为空,PHP网站将向用户显示登录页面,并允许用户进行身份验证和注册。如果传递的OpenID不是空的。PHP网站应检查其有效状态。 只有验证/注册成功,PHP网站才会重定向回我的ASP.NET网站OpenID,我将为用户使用该OpenID。 当然,这个过程必须是安全的。 我发现应该使用FormAuthentication在Application_AuthenticateRequest事件的Global.asax中实现身份验证检查。我是这样计划的ASP.NET中的安全单点登录,用于通过OpenID从anthother(php)网站进行身份验证,php,asp.net,authentication,openid,single-sign-on,Php,Asp.net,Authentication,Openid,Single Sign On,我需要在我的asp.net上实现以下身份验证:asp.net和PHP网站上的用户应该使用OpenID进行身份验证。登录和注册仅存在于PHP网站上。因此,要求如下: 我的ASP.NET网站应该重定向到PHP网站进行身份验证。用户将 使用PHP网站上的OpenID进行身份验证。 如果用户是新用户,我计划使用coookie访问我的ASP.NET网站,它将重定向为空 帕拉马特。否则,我将在重定向请求中传递存储的OpenID。 如果传递的OpenID为空,PHP网站将向用户显示登录页面,并允许用户进行身份
protected void Application_AuthenticateRequest(Object sender, EventArgs e) {
if(HttpContext.Current.User != null) {
// Extract the forms authentication cookie if exists.
// Redirects to the php website using the OpenID extracted from the cookies, or empty.
// Pass also a new generated token to secure the communication.
} else {
// Store a new GeneralPrincipal to the HttpContext.Current.User.
}
}
protected void Application_BeginRequest(Object sender, EventArgs e) {
// Check for the redirected back token and OpenID.
// Create FormsAuthenticationTicket for the openid and store it in the cookie.
}
protected override void OnInit(EventArgs e) {
// Check Identity.
if(HttpContext.Current.User.Identity.IsAuthenticated) {
// The user is already authenticated.
// Get the user...
return;
}
// Check if the php server sends request with token.
if(!string.IsNullOrEmpty(Request.QueryString["token"])) {
try {
// Get user from the PHP-Server by the token.
//...
// Remove old FormsAuthentication.
FormsAuthentication.SignOut();
// Save new authentication.
SaveAuthentication();
} catch(Exception exception) {
// Handle...
return;
}
} else {
// Get new php-token and redirect to the php-server for the authentication.
//...
}
问题是,我无法在会话中保存生成的令牌,因为会话状态当时未初始化
解决上述要求的最佳实践是什么?我已经通过对我所有应该受到保护的站点使用基本页面类解决了这个问题。在每次这样的请求中,都会在OnInit中检查用户
protected void Application_AuthenticateRequest(Object sender, EventArgs e) {
if(HttpContext.Current.User != null) {
// Extract the forms authentication cookie if exists.
// Redirects to the php website using the OpenID extracted from the cookies, or empty.
// Pass also a new generated token to secure the communication.
} else {
// Store a new GeneralPrincipal to the HttpContext.Current.User.
}
}
protected void Application_BeginRequest(Object sender, EventArgs e) {
// Check for the redirected back token and OpenID.
// Create FormsAuthenticationTicket for the openid and store it in the cookie.
}
protected override void OnInit(EventArgs e) {
// Check Identity.
if(HttpContext.Current.User.Identity.IsAuthenticated) {
// The user is already authenticated.
// Get the user...
return;
}
// Check if the php server sends request with token.
if(!string.IsNullOrEmpty(Request.QueryString["token"])) {
try {
// Get user from the PHP-Server by the token.
//...
// Remove old FormsAuthentication.
FormsAuthentication.SignOut();
// Save new authentication.
SaveAuthentication();
} catch(Exception exception) {
// Handle...
return;
}
} else {
// Get new php-token and redirect to the php-server for the authentication.
//...
}
对于可本地化的ASP.NET网站,它可以通过InitializeCulture方法实现。我知道它是offtopic,但它是SO配置文件中指定的主页上的js特洛伊木马。我已编辑了主要目标的描述,以澄清我需要什么。ASP.NET和PHP网站都将检查cource的请求url。