在MVC 5设置窗体身份验证的多个Web应用程序基于OWIN [英] Setting up Forms Authentication for multiple Web Apps in MVC 5 based on OWIN
问题描述
我在建立我的第一个MVC Web应用程序的过程。我知道我需要提供一个基于表单的身份验证模式以及我知道我会被重新使用多个其他内部Web应用程序也是如此。
I am in process of setting up my 1st MVC Web App. I know I need to provide a Forms Based Authentication model as well as I know I will be reusing it for multiple other internal web apps as well.
使用EF code所有的MVC 5认证,我相信这是所有基于OWIN的东西,该文件已经是烤到一个单一的Web应用程序首先毫不逊色。
All the documentation for MVC 5 Authentication, which I believe is all based on OWIN stuff, have it "baked" into a single web app using EF Code First no less.
我想做的是有一个又一个的Web应用程序,我剥夺了一切的除了帐户的东西,然后尝试点我的Web应用程序身份验证这一点,有它返回一个令牌,我猜测我的身份验证的用户,和他/她的角色。
What I am trying is to have an another Web App that I strip everything out of except for the Account stuff and then try to "point" my web apps Authentication to that and have it return a "token", I'm guessing, of my Authenticated User and his/her "Roles".
我是在正确的轨道?我方式在复杂吗?我是新来的Web开发,但是这似乎是一个相当合理的和直接的要求。傻眼了,我找不到它的任何地方。
Am I on the right track? Am I WAY over complicating this? I'm new to Web Development but this seems like a fairly reasonable and straightforward request. Dumbfounded that I can't find it anywhere.
推荐答案
工作有新的 OWIN 身份API 的包装,你需要使用的应用和外部标志工作在家居饼干像波纹管:
Work with new OWIN Identity API that wraps everything that you need to work with Application and External sign in cookies like bellow:
public class IdentityAuthenticationManager
{
public IdentityAuthenticationManager();
public IdentityAuthenticationManager(IdentityStoreManager storeManager);
public string ClaimsIssuer { get; set; }
public string RoleClaimType { get; set; }
public IdentityStoreManager StoreManager { get; set; }
public string UserIdClaimType { get; set; }
public string UserNameClaimType { get; set; }
public virtual void Challenge(HttpContextBase context, string authenticationType, string redirectUrl);
public virtual Task<bool> CheckPasswordAndSignIn(HttpContextBase context, string userName, string password, bool isPersistent);
public virtual Task<bool> CreateAndSignInExternalUser(HttpContextBase context, string loginProvider, IUser user);
public virtual IEnumerable<Microsoft.Owin.Security.AuthenticationDescription> GetExternalAuthenticationTypes(HttpContextBase context);
public virtual Task<ClaimsIdentity> GetExternalIdentity(HttpContextBase context);
public virtual Task<IList<Claim>> GetUserIdentityClaims(string userId, IEnumerable<Claim> claims);
public virtual Task<bool> LinkExternalIdentity(ClaimsIdentity id, string userId, string loginProvider);
public virtual Task SignIn(HttpContextBase context, string userId, bool isPersistent);
public virtual Task SignIn(HttpContextBase context, string userId, IEnumerable<Claim> claims, bool isPersistent);
public virtual Task<bool> SignInExternalIdentity(HttpContextBase context, ClaimsIdentity id, string loginProvider);
public virtual void SignOut(HttpContextBase context);
public virtual bool VerifyExternalIdentity(ClaimsIdentity id, string loginProvider);
}
和下面显示的登录 code的ASP.NET MVC模板:
And The following shows the login code for the ASP.NET MVC template:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
// Validate the user password
if (await AuthenticationManager.CheckPasswordAndSignIn(HttpContext, model.UserName, model.Password, model.RememberMe))
{
return RedirectToLocal(returnUrl);
}
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
有关更多信息,请访问<一href="http://blogs.msdn.com/b/webdev/archive/2013/07/03/understanding-owin-forms-authentication-in-mvc-5.aspx"相对=nofollow>这个。
For more information visit this.
这篇关于在MVC 5设置窗体身份验证的多个Web应用程序基于OWIN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!