请求向 NerdDinner ASP.NET MVC 应用程序添加 Openid 支持的教程

发布于 2024-07-22 21:39:16 字数 218 浏览 2 评论 0原文

我正在寻找使用 ASP.NET MVC NerdDinner 教程来了解 ASP.NET MVC 和 OpenId。

我想将 NerdDinner 中的身份验证系统替换为仅 OpenId。 我已经下载了最新的 DotNetOpenAuth 库,但我不确定如何将它们组合在一起。 任何人都可以帮助提供快速的分步教程吗?

这就像放入库一样简单吗?还是应用程序还需要进行重大更改?

I'm looking learn about ASP.NET MVC and OpenId using the ASP.NET MVC NerdDinner tutorial.

I would like to replace the Authentication system in NerdDinner to be OpenId only. I've downloaded the latest DotNetOpenAuth libraries but I'm not sure how to put it all together. Can anyone help with a quick step-by-step tutorial?

Is this as simple as dropping in the library or are there significant changes needed to the application as well?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

醉生梦死 2024-07-29 21:39:16

下载 dotnetopenid 后,请查看示例\RelyingPartyMvc 目录。 有一个示例,他们用 OpenID 替换了默认的 MVC 身份验证系统。 相关代码位于Controllers/UserController.cs中。 这是身份验证操作:

//Stage 1: Show form asking for Open ID identifier URL
var openid = new OpenIdRelyingParty();
if (openid.Response == null) {
    // Stage 2: user submitting Identifier
    Identifier id;
    if (Identifier.TryParse(Request.Form["openid_identifier"], out id)) {
            openid.CreateRequest(Request.Form["openid_identifier"]).RedirectToProvider();
    } else {
            ViewData["Message"] = "Invalid identifier";
            return View("Login");
            }
} else {
    // Stage 3: OpenID Provider sending assertion response
    switch (openid.Response.Status) {
        case AuthenticationStatus.Authenticated:
            FormsAuthentication.RedirectFromLoginPage(openid.Response.ClaimedIdentifier, false);
            break;
        case AuthenticationStatus.Canceled:
            ViewData["Message"] = "Canceled at provider";
            return View("Login");
        case AuthenticationStatus.Failed:
            ViewData["Message"] = openid.Response.Exception.Message;
            return View("Login");
    }
}
return new EmptyResult();

Once you download dotnetopenid, look in the samples\RelyingPartyMvc directory. There is a sample where they replace the default MVC authentication system with OpenID. The relevant code is in Controllers/UserController.cs. Here is the Authenticate action:

//Stage 1: Show form asking for Open ID identifier URL
var openid = new OpenIdRelyingParty();
if (openid.Response == null) {
    // Stage 2: user submitting Identifier
    Identifier id;
    if (Identifier.TryParse(Request.Form["openid_identifier"], out id)) {
            openid.CreateRequest(Request.Form["openid_identifier"]).RedirectToProvider();
    } else {
            ViewData["Message"] = "Invalid identifier";
            return View("Login");
            }
} else {
    // Stage 3: OpenID Provider sending assertion response
    switch (openid.Response.Status) {
        case AuthenticationStatus.Authenticated:
            FormsAuthentication.RedirectFromLoginPage(openid.Response.ClaimedIdentifier, false);
            break;
        case AuthenticationStatus.Canceled:
            ViewData["Message"] = "Canceled at provider";
            return View("Login");
        case AuthenticationStatus.Failed:
            ViewData["Message"] = openid.Response.Exception.Message;
            return View("Login");
    }
}
return new EmptyResult();
尐偏执 2024-07-29 21:39:16

不是 NerdDinner 特定的,但对于想要在 ASP.NET MVC 应用程序中实现 OpenId 支持的人来说可能很有用:

Not NerdDinner specifiс but could be useful for ones who want to implement OpenId support in their ASP.NET MVC application:

未央 2024-07-29 21:39:16

好的,所以我得到了这样的工作!
答案是以下答案的组合加上一些控制器和视图的修改。

首先下载 DotNetOpenAuth,然后导航到示例目录,您可以在其中找到 OpenIdRelayingPartyMvc 代码。
在我的 NerdDinner 解决方案中,

  • 我添加了对 DotNetOpenAuth 程序集的引用,
  • 添加了新的“UserController”,并从示例的 UserController 中复制了代码
  • ,添加了正确的 using 语句并更改了命名空间以反映 NerdDinner。Controllers
  • 从示例,适当更改它们以反映站点主内容 ID。
  • 在 home 控制器下添加了 xrds 视图。 (还不确定这会做什么)
  • 更改了索引并在 HomeController 中添加 Xrds ActionResult 方法以反映示例。
  • 更改了 web.config 文件(在根文件夹中) Authenticate 部分,以将登录路径更改为新的 UserController 和 Login 方法
  • 更改“LogOnUserControl”ActionLinks 以指向新的 UserControl 以及“Login”和“Logout”方法。
  • 处理直接调用登录功能的各种视图

现在,它的工作方式有限。 我可以使用 OpenID 登录 NerdDinner 应用程序并与之交互。 所以这很酷。 然而,某些功能还无法运行。 保存创建的晚餐不起作用,但它也不会挂起。 我必须研究如何将 AccountController 中的一些成员资格功能迁移到 UserController。 我将更新这篇文章(欢迎建议和指点)。

Ok, So I got this sort of working!
The answer is a combination of the answers below plus some mucking around with the controllers and views.

First download DotNetOpenAuth and then navigate to the samples directory where you can find the OpenIdRelayingPartyMvc code.
In my NerdDinner solution,

  • I added a reference to the DotNetOpenAuth assembly
  • added new a "UserController" and copied in the code from the sample's UserController
  • added the correct using statements and changed the namespace to reflect NerdDinner.Controllers
  • recreated similar "User" views from the sample, changing them appropriately to reflect the site master content id's.
  • added an xrds view under the home controller. (not sure what this does yet)
  • changed the index and add the Xrds ActionResult methods in the HomeController to reflect the sample.
  • changed the web.config file (in root folder) Authenticate section to change the login path to the new UserController and Login method
  • Change the "LogOnUserControl" ActionLinks to point to the new UserControl and "Login" and "Logout" methods.
  • muck around with the various views that directly call the log on functionality

Right now this works in a limited way. I can logon and interact with the NerdDinner app with an OpenID. So that's cool. However some functionality doesn't yet work. Saving a created dinner doesn't work but it doesn't hang either. I'll have to investigate how to migrate some of the membership functionality in AccountController to UserController. I'll update this post (suggestions and pointers welcome).

轻拂→两袖风尘 2024-07-29 21:39:16

Codeplex 上有一个会员入门工具包,应该就是您正在寻找的。 如果他们遵循微软身份验证约定,那么他们都应该遵循提供者模型(阅读它)。

http://mvcmembership.codeplex.com/

There is a membership starter kit on codeplex that should be what you are looking for. They should both be following the provider model (read up on it) if they follow the microsoft authentication convention.

http://mvcmembership.codeplex.com/

柠北森屋 2024-07-29 21:39:16

查看 Samples/OpenIdRelyingPartyMvc 目录(使用 OpenId 身份验证的简单 ASP.NET MVC 网站)。 您可以从将 Home/User Controllers/Views 和设置从 web.config 复制到您的项目开始。 我认为这是为您的网站提供 OpenId 身份验证的最快方法。 然后, 正如 Alexander Prokofyev 所说Andrew Arnott(DotNetOpenAuth/DotNetOpenId 作者)博客上有一篇非常有用的帖子 - 添加 OpenID 登录支持您的 ASP.NET MVC 站点

Look at the Samples/OpenIdRelyingPartyMvc dir (a simple ASP.NET MVC website using OpenId authentication). You can start from copying Home/User Controllers/Views and settings from web.config into your project. I think it is the fastest way to give your site OpenId authentication. Then, as Alexander Prokofyev said, there is very useful post at the Andrew Arnott's (DotNetOpenAuth/DotNetOpenId author) blog - Add OpenID login support to your ASP.NET MVC site

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文