WebSecurity vs FormsAuthentication in ASP.NET MVC4

I suppose I'm trying to mix two providers in a project, but I'm looking to use websecurity in conjunction with my form authentication. I need websecurity to authenticate OAUTH with Facebook and google.

The error I get when I try to login using facebook,

To call this method, the Membership.Provider property must be an instance of ExtendedMembershipProvider .

Here are some sample code. How can i use both?

 public ActionResult ExternalLoginCallback(string returnUrl) { AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl })); if (!result.IsSuccessful) { return RedirectToAction("ExternalLoginFailure"); } if (OAuthWebSecurity.Login(result.Provider, result.ProviderUserId, createPersistentCookie: false)) { return RedirectToLocal(returnUrl); } if (User.Identity.IsAuthenticated) { // If the current user is logged in add the new account OAuthWebSecurity.CreateOrUpdateAccount(result.Provider, result.ProviderUserId, User.Identity.Name); return RedirectToLocal(returnUrl); } else { // User is new, ask for their desired membership name string loginData = OAuthWebSecurity.SerializeProviderUserId(result.Provider, result.ProviderUserId); ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(result.Provider).DisplayName; ViewBag.ReturnUrl = returnUrl; return View("ExternalLoginConfirmation", new RegisterExternalLoginModel { UserName = result.UserName, ExternalLoginData = loginData }); } } 

and

 public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid) { if (Membership.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(returnUrl)) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Home"); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed, redisplay form return View(model); } 
+3
source share
3 answers

Perhaps this is due to the same issue that I am MVC4 ExtendedMembershipProvider and entityframework .. I uninstalled the nuget universal provider package and this particular error disappeared.

Also this "very recent" article by John Galloway may help.

+3
source

If you use Visual Studio, you can save all this effort. The MVC 4 Internet Template comes with four external identity providers. I tested them, as well as Google accounts, Microsoft account, Facebook login and Twitter login. Everything works fine, with zero lines of code.

I think the same with the web form template too.

More information at http://blogs.msdn.com/b/webdev/archive/2012/08/15/oauth-openid-support-for-webforms-mvc-and-webpages.aspx .

+1
source

You can use the implementation of ExtendedMembershipProvider . For example: the built-in SimpleMembershipProvider .

Each ExtendedMembershipProvider IS A MembershipProvider .

Read more on John Galloway's Blog

0
source

Source: https://habr.com/ru/post/1444223/


All Articles