Request for Tutorial to add Openid Support to NerdDinner ASP.NET MVC application
Asked Answered
D

5

26

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?

Demonstrative answered 1/6, 2009 at 7:43 Comment(0)
V
14

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();
Vogt answered 2/6, 2009 at 14:2 Comment(3)
I've downloaded the code and read thru directions, but it's still not clear how it all fits together. The NerdDinner sample has the default AccountController. The authenticate and the membership services are contained in AccountController. Does the above code need to get merged into that controller?Demonstrative
The above code uses a controller called UserController. This is basically a replacement to the AccountController. You would just need to update you links or routes to point to it accordingly.Vogt
This sample appears to use the dotnetopenid package and not the newer dotnetopenauth package which replaced it.Sevigny
R
7

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

Runnels answered 1/6, 2009 at 9:52 Comment(0)
D
6

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).

Demonstrative answered 3/6, 2009 at 22:17 Comment(0)
T
1

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

Tracheotomy answered 1/6, 2009 at 17:47 Comment(0)
K
0

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/

Knifeedged answered 1/6, 2009 at 8:31 Comment(1)
Be wary of this one. It's several months out of date and doesn't even compile out of the box any more. Hopefully the project owners will rev it soon.Overnice

© 2022 - 2024 — McMap. All rights reserved.