dotnetopenauth,MVC2 且未找到 OpenID 端点
升级到 MVC2 和最新的 dotnetopenauth 后,我不断收到“未找到 OpenID 端点”的消息。当我尝试使用谷歌应用程序登录时。我在本地主机上工作正常,但在我的域上却不行 - 有什么想法吗?
namespace TheDataEngineMVCb1.Areas.Admin.Controllers
{
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Security.Principal;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using System.Web.UI;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.RelyingParty;
using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
[HandleError]
public class AccountController : Controller
{
private static readonly HostMetaDiscoveryService GoogleAppsDiscovery = new HostMetaDiscoveryService
{
UseGoogleHostedHostMeta = true,
};
private static OpenIdRelyingParty openid = new OpenIdRelyingParty();
public ActionResult Index()
{
return View("Index");
}
public ActionResult LoginPopup()
{
return View("LoginPopup");
}
public ActionResult Logout()
{
FormsAuthentication.SignOut();
return Redirect("/Admin");
}
public ActionResult Login()
{
// Stage 1: display login form to user
return View("Login");
}
[ValidateInput(false)]
public ActionResult Authenticate(string returnUrl)
{
openid.DiscoveryServices.Clear();
openid.DiscoveryServices.Insert(0, GoogleAppsDiscovery);
var response = openid.GetResponse();
if (response == null)
{
// Stage 2: user submitting Identifier
Identifier id;
if (Identifier.TryParse(Request.Form["openid_identifier"], out id) && Request.Form["openid_identifier"]!=null)
{
try
{
Session["openid_identifier"] = Server.HtmlEncode(Request.Form["openid_identifier"]);
var request = openid.CreateRequest(Request.Form["openid_identifier"]);
return request.RedirectingResponse.AsActionResult();
}
catch (ProtocolException ex)
{
ViewData["Message"] = ex.Message;
return View("Login");
}
}
else
{
ViewData["Message"] = "Invalid identifier";
return View("Login");
}
}
else
{
// Stage 3: OpenID Provider sending assertion response
switch (response.Status)
{
case AuthenticationStatus.Authenticated:
string authEmail = Request["dnoa.userSuppliedIdentifier"].ToString();
FormsAuthentication.SetAuthCookie(authEmail, false);
if (!string.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
case AuthenticationStatus.Canceled:
ViewData["Message"] = "Canceled at provider";
return View("Login");
case AuthenticationStatus.Failed:
ViewData["Message"] = response.Exception.Message;
return View("Login");
}
}
return new EmptyResult();
}
}
}
After I upgraded to MVC2 and the newest dotnetopenauth I keep getting "No OpenID endpoint found." when I try to login using google apps. I works fine on localhost but not on my domain - any ideas?
namespace TheDataEngineMVCb1.Areas.Admin.Controllers
{
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Security.Principal;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using System.Web.UI;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.RelyingParty;
using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
[HandleError]
public class AccountController : Controller
{
private static readonly HostMetaDiscoveryService GoogleAppsDiscovery = new HostMetaDiscoveryService
{
UseGoogleHostedHostMeta = true,
};
private static OpenIdRelyingParty openid = new OpenIdRelyingParty();
public ActionResult Index()
{
return View("Index");
}
public ActionResult LoginPopup()
{
return View("LoginPopup");
}
public ActionResult Logout()
{
FormsAuthentication.SignOut();
return Redirect("/Admin");
}
public ActionResult Login()
{
// Stage 1: display login form to user
return View("Login");
}
[ValidateInput(false)]
public ActionResult Authenticate(string returnUrl)
{
openid.DiscoveryServices.Clear();
openid.DiscoveryServices.Insert(0, GoogleAppsDiscovery);
var response = openid.GetResponse();
if (response == null)
{
// Stage 2: user submitting Identifier
Identifier id;
if (Identifier.TryParse(Request.Form["openid_identifier"], out id) && Request.Form["openid_identifier"]!=null)
{
try
{
Session["openid_identifier"] = Server.HtmlEncode(Request.Form["openid_identifier"]);
var request = openid.CreateRequest(Request.Form["openid_identifier"]);
return request.RedirectingResponse.AsActionResult();
}
catch (ProtocolException ex)
{
ViewData["Message"] = ex.Message;
return View("Login");
}
}
else
{
ViewData["Message"] = "Invalid identifier";
return View("Login");
}
}
else
{
// Stage 3: OpenID Provider sending assertion response
switch (response.Status)
{
case AuthenticationStatus.Authenticated:
string authEmail = Request["dnoa.userSuppliedIdentifier"].ToString();
FormsAuthentication.SetAuthCookie(authEmail, false);
if (!string.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
case AuthenticationStatus.Canceled:
ViewData["Message"] = "Canceled at provider";
return View("Login");
case AuthenticationStatus.Failed:
ViewData["Message"] = response.Exception.Message;
return View("Login");
}
}
return new EmptyResult();
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是一个信任问题。 Google Apps OpenID 要求您的 RP 标记为“完全信任”。也许它在您的本地主机上,但不在您的实时站点上?
It could be a trust issue. Google Apps OpenIDs require that your RP be marked with Full Trust. Perhaps it is on your localhost but not on your live site?